cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject svn commit: r1355254 - in /cocoon/cocoon3/trunk: cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ cocoon-sax/src/main/java/org/apache/cocoon/sax/component/ cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/
Date Fri, 29 Jun 2012 07:47:47 GMT
Author: ilgrosso
Date: Fri Jun 29 07:47:46 2012
New Revision: 1355254

URL: http://svn.apache.org/viewvc?rev=1355254&view=rev
Log:
Refactoring ParameterCacheKey Sitemap-safe instantiation with a factory method

Modified:
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java
    cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java
    cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateTransformer.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=1355254&r1=1355253&r2=1355254&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
Fri Jun 29 07:47:46 2012
@@ -17,6 +17,7 @@
 package org.apache.cocoon.pipeline.caching;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -45,6 +46,27 @@ public class ParameterCacheKey extends A
 
     private final Map<String, String> parameters;
 
+    /**
+     * Build an instance only when parameter names are safe in Sitemap context.
+     * 
+     * @param parameters to be considered for caching
+     * @return a Sitemap-safe instance
+     */
+    public static ParameterCacheKey getSitemapSafeInstance(Map<String, Object> parameters)
{
+        if (parameters == null) {
+            parameters = Collections.EMPTY_MAP;
+        }
+
+        Map<String, String> safeParams = new HashMap<String, String>();
+        for (Entry<String, Object> entry : parameters.entrySet()) {
+            if (!SITEMAP_PARAM_NON_CACHABLE_NAMES.contains(entry.getKey())) {
+                safeParams.put(entry.getKey(), entry.getValue().toString());
+            }
+        }
+
+        return new ParameterCacheKey(Collections.unmodifiableMap(safeParams));
+    }
+
     public ParameterCacheKey() {
         this(new HashMap<String, String>());
     }
@@ -86,32 +108,6 @@ public class ParameterCacheKey extends A
     }
 
     /**
-     * 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)

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java?rev=1355254&r1=1355253&r2=1355254&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java
Fri Jun 29 07:47:46 2012
@@ -264,7 +264,7 @@ public class XSLTTransformer extends Abs
 
         final CompoundCacheKey cacheKey = new CompoundCacheKey();
         cacheKey.addCacheKey(new TimestampCacheKey(this.source, URLUtils.getLastModified(this.source)));
-        cacheKey.addCacheKey(new ParameterCacheKey().setSitemapParameters(this.parameters));
+        cacheKey.addCacheKey(ParameterCacheKey.getSitemapSafeInstance(this.parameters));
 
         return cacheKey;
     }

Modified: cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java?rev=1355254&r1=1355253&r2=1355254&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateGenerator.java
Fri Jun 29 07:47:46 2012
@@ -97,7 +97,7 @@ public class StringTemplateGenerator ext
 
         final CompoundCacheKey cacheKey = new CompoundCacheKey();
         cacheKey.addCacheKey(new TimestampCacheKey(this.url, URLUtils.getLastModified(this.url)));
-        cacheKey.addCacheKey(new ParameterCacheKey().setSitemapParameters(this.parameters));
+        cacheKey.addCacheKey(ParameterCacheKey.getSitemapSafeInstance(this.parameters));
 
         return cacheKey;
     }

Modified: cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateTransformer.java?rev=1355254&r1=1355253&r2=1355254&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateTransformer.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateTransformer.java
Fri Jun 29 07:47:46 2012
@@ -45,7 +45,7 @@ public class StringTemplateTransformer e
 
     @Override
     public CacheKey constructCacheKey() {
-        return new ParameterCacheKey().setSitemapParameters(this.parameters);
+        return ParameterCacheKey.getSitemapSafeInstance(this.parameters);
     }
 
     @Override



Mime
View raw message