cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From un...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/generation JXTemplateGenerator.java
Date Tue, 06 Jul 2004 10:34:36 GMT
unico       2004/07/06 03:34:36

  Modified:    src/java/org/apache/cocoon/generation
                        JXTemplateGenerator.java
  Log:
  qualify template cache-key with the template source uri
  
  Revision  Changes    Path
  1.52      +32 -5     cocoon-2.1/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java
  
  Index: JXTemplateGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- JXTemplateGenerator.java	2 Jul 2004 08:33:42 -0000	1.51
  +++ JXTemplateGenerator.java	6 Jul 2004 10:34:36 -0000	1.52
  @@ -42,8 +42,8 @@
   import java.util.TimeZone;
   
   import org.apache.avalon.framework.parameters.Parameters;
  -import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.caching.CacheableProcessingComponent;
   import org.apache.cocoon.components.flow.FlowHelper;
  @@ -54,8 +54,8 @@
   import org.apache.cocoon.environment.Request;
   import org.apache.cocoon.environment.SourceResolver;
   import org.apache.cocoon.transformation.ServiceableTransformer;
  -import org.apache.cocoon.xml.XMLConsumer;
   import org.apache.cocoon.xml.IncludeXMLConsumer;
  +import org.apache.cocoon.xml.XMLConsumer;
   import org.apache.cocoon.xml.XMLUtils;
   import org.apache.cocoon.xml.dom.DOMBuilder;
   import org.apache.cocoon.xml.dom.DOMStreamer;
  @@ -3191,17 +3191,21 @@
               ev = ev.next;
           }
       }
  +
   	/* (non-Javadoc)
   	 * @see org.apache.cocoon.caching.CacheableProcessingComponent#getKey()
   	 */
   	public Serializable getKey() {
       	JXTExpression cacheKeyExpr = (JXTExpression)getCurrentTemplateProperty(CACHE_KEY);
           try {
  -			return (Serializable) getValue(cacheKeyExpr, globalJexlContext, jxpathContext);
  +            final Serializable templateKey = (Serializable) getValue(cacheKeyExpr, globalJexlContext,
jxpathContext);
  +            if (templateKey != null) {
  +    			return new JXCacheKey(this.inputSource.getURI(), templateKey);
  +            }
   		} catch (Exception e) {
   			getLogger().error("error evaluating cache key", e);
  -			return null;
   		}
  +		return null;
   	}
   
   	/* (non-Javadoc)
  @@ -3236,5 +3240,28 @@
           builder.endDocument();
           Node node = builder.getDocument().getDocumentElement();
           return node.getChildNodes();
  +	}
  +	
  +	static final class JXCacheKey implements Serializable {
  +	    private final String templateUri;
  +	    private final Serializable templateKey;
  +	    private JXCacheKey(String templateUri, Serializable templateKey) {
  +	        this.templateUri = templateUri;
  +	        this.templateKey = templateKey;
  +	    }
  +	    public int hashCode() {
  +	        return templateUri.hashCode() + templateKey.hashCode();
  +	    }
  +	    public String toString() {
  +	        return "TK:" + templateUri + "_" + templateKey;
  +	    }
  +	    public boolean equals(Object o) {
  +	        if (o instanceof JXCacheKey) {
  +	            JXCacheKey jxck = (JXCacheKey)o;
  +	            return this.templateUri.equals(jxck.templateUri)
  +                       && this.templateKey.equals(jxck.templateKey);
  +	        }
  +	        return false;
  +	    }
   	}
   }
  
  
  

Mime
View raw message