cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1355053 - /cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java
Date Thu, 28 Jun 2012 15:50:54 GMT
Author: ilgrosso
Date: Thu Jun 28 15:50:53 2012
New Revision: 1355053

URL: http://svn.apache.org/viewvc?rev=1355053&view=rev
Log:
Adding toString() and a way to escape sitemap-only parameters for caching

Modified:
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java?rev=1355053&r1=1355052&r2=1355053&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java
Thu Jun 28 15:50:53 2012
@@ -16,10 +16,13 @@
  */
 package org.apache.cocoon.pipeline.caching;
 
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Map.Entry;
-
+import java.util.Set;
+import org.apache.cocoon.pipeline.util.StringRepresentation;
 import org.apache.cocoon.util.murmurhash.MurmurHashCodeBuilder;
 
 /**
@@ -28,6 +31,18 @@ import org.apache.cocoon.util.murmurhash
 public class ParameterCacheKey extends AbstractCacheKey {
 
     private static final long serialVersionUID = 1L;
+
+    /**
+     * Set of parameter names that must not be considered for caching when in Sitemap context.
+     */
+    private static final Set<String> SITEMAP_PARAM_NON_CACHABLE_NAMES = new HashSet<String>(Arrays.asList(new
String[]{
+                "cocoon",
+                "org.apache.cocoon.configuration.Settings",
+                "javax.servlet.ServletContext",
+                "javax.servlet.http.HttpServletRequest",
+                "javax.servlet.http.HttpServletResponse"
+            }));
+
     private final Map<String, String> parameters;
 
     public ParameterCacheKey() {
@@ -60,17 +75,43 @@ public class ParameterCacheKey extends A
         this.parameters.put(name, Integer.toString(value));
     }
 
-    public void addParameter(String name, Map<?, ?> value) {
+    public final void addParameter(String name, Map<?, ?> value) {
         for (Entry<?, ?> object : value.entrySet()) {
             this.parameters.put(name + "_" + object.getKey().toString(), object.getValue().toString());
         }
     }
 
-    public void addParameter(String name, String value) {
+    public final void addParameter(String name, String value) {
         this.parameters.put(name, value);
     }
 
     /**
+     * Add a parameter to this cache key, only when name is safe in Sitemap context.
+     *
+     * @param name parameter name
+     * @param value parameter value
+     */
+    public void addSitemapParameter(String name, Object value) {
+        if (!SITEMAP_PARAM_NON_CACHABLE_NAMES.contains(name)) {
+            this.addParameter(name, value.toString());
+        }
+    }
+
+    /**
+     * Set this cache key parameters, only when names that are safe in Sitemap context.
+     *
+     * @param sitemapParameters
+     * @return this instance, for chained invokation
+     */
+    public ParameterCacheKey setSitemapParameters(Map<String, Object> sitemapParameters)
{
+        this.parameters.clear();
+        for (Entry<String, Object> entry : sitemapParameters.entrySet()) {
+            this.addSitemapParameter(entry.getKey(), entry.getValue());
+        }
+        return this;
+    }
+
+    /**
      * {@inheritDoc}
      *
      * @see java.lang.Object#equals(java.lang.Object)
@@ -90,6 +131,7 @@ public class ParameterCacheKey extends A
      *
      * @see org.apache.cocoon.pipeline.caching.CacheKey#getLastModified()
      */
+    @Override
     public long getLastModified() {
         return -1;
     }
@@ -113,7 +155,13 @@ public class ParameterCacheKey extends A
      *
      * @see org.apache.cocoon.pipeline.caching.CacheKey#isValid(org.apache.cocoon.pipeline.caching.CacheKey)
      */
+    @Override
     public boolean isValid(CacheKey cacheKey) {
         return this.equals(cacheKey);
     }
+
+    @Override
+    public String toString() {
+        return StringRepresentation.buildString(this, "parameters=" + this.parameters);
+    }
 }



Mime
View raw message