cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject svn commit: r289891 - in /cocoon/trunk: src/java/org/apache/cocoon/transformation/XIncludeTransformer.java status.xml
Date Sun, 18 Sep 2005 05:37:17 GMT
Author: antonio
Date: Sat Sep 17 22:37:11 2005
New Revision: 289891

URL: http://svn.apache.org/viewcvs?rev=289891&view=rev
Log:

<action dev="AG" type="add" fixes-bug="31600" due-to="Frans Englich" due-to-email="frans.englich@telia.com">
      Caching support for XInclude Transformer
</action>

Modified:
    cocoon/trunk/src/java/org/apache/cocoon/transformation/XIncludeTransformer.java
    cocoon/trunk/status.xml

Modified: cocoon/trunk/src/java/org/apache/cocoon/transformation/XIncludeTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/transformation/XIncludeTransformer.java?rev=289891&r1=289890&r2=289891&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/transformation/XIncludeTransformer.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/transformation/XIncludeTransformer.java Sat Sep
17 22:37:11 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.io.Serializable; 
 import java.net.MalformedURLException;
 import java.util.Map;
 
@@ -30,7 +31,9 @@
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.cocoon.ProcessingException;
 import org.apache.cocoon.ResourceNotFoundException;
+import org.apache.cocoon.caching.CacheableProcessingComponent; 
 import org.apache.cocoon.components.source.SourceUtil;
+import org.apache.cocoon.components.source.impl.MultiSourceValidity; 
 import org.apache.cocoon.components.xpointer.XPointer;
 import org.apache.cocoon.components.xpointer.XPointerContext;
 import org.apache.cocoon.components.xpointer.parser.ParseException;
@@ -43,6 +46,7 @@
 import org.apache.cocoon.xml.XMLConsumer;
 import org.apache.excalibur.source.Source;
 import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.SourceValidity; 
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.Locator;
@@ -64,9 +68,9 @@
  * and on the content of fallback elements (with loop inclusion detection).
  *
  * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a> (wrote the
original version)
- * @version CVS $Id$
+ * @version SVN $Id$
  */
-public class XIncludeTransformer extends AbstractTransformer implements Serviceable {
+public class XIncludeTransformer extends AbstractTransformer implements Serviceable, CacheableProcessingComponent
{ 
     protected SourceResolver resolver;
     protected ServiceManager manager;
     private XIncludePipe xIncludePipe;
@@ -79,11 +83,16 @@
     public static final String XINCLUDE_INCLUDE_ELEMENT_HREF_ATTRIBUTE = "href";
     public static final String XINCLUDE_INCLUDE_ELEMENT_PARSE_ATTRIBUTE = "parse";
 
+    private static final String XINCLUDE_CACHE_KEY = "XInclude"; 
+
+    /** The {@link SourceValidity} instance associated with this request. */ 
+    private MultiSourceValidity validity; 
 
     public void setup(SourceResolver resolver, Map objectModel, String source, Parameters
parameters)
             throws ProcessingException, SAXException, IOException {
         this.resolver = resolver;
-        this.xIncludePipe = new XIncludePipe();
+        this.validity = new MultiSourceValidity(resolver, MultiSourceValidity.CHECK_ALWAYS);

+        this.xIncludePipe = new XIncludePipe(); 
         this.xIncludePipe.enableLogging(getLogger());
         this.xIncludePipe.init(null);
         super.setContentHandler(xIncludePipe);
@@ -106,10 +115,21 @@
         this.manager = manager;
     }
 
+    /** Key to be used for caching */ 
+    public Serializable getKey() { 
+        return XINCLUDE_CACHE_KEY; 
+    } 
+
+    /** Get the validity for this transform */ 
+    public SourceValidity getValidity() { 
+        return this.validity; 
+    } 
+
     public void recycle()
     {
         // Reset all variables to initial state.
         this.resolver = null;
+        this.validity = null; 
         this.xIncludePipe = null;
         super.recycle();
     }
@@ -158,6 +178,12 @@
             return href;
         }
 
+        public void endDocument() throws SAXException { 
+            // We won't be getting any more sources so mark the MultiSourceValidity as finished.

+            validity.close(); 
+            super.endDocument(); 
+        } 
+
         public void startElement(String uri, String name, String raw, Attributes attr) throws
SAXException {
             if (xIncludeLevel == 1 && useFallback && XINCLUDE_NAMESPACE_URI.equals(uri)
&& XINCLUDE_FALLBACK_ELEMENT.equals(name)) {
                 fallbackLevel++;
@@ -172,7 +198,7 @@
                 return;
             } else if (xIncludeLevel > 0 && fallbackLevel > 0) {
                 fallbackLevel++;
-            } 
+            }
 
             xmlBaseSupport.startElement(uri, name, raw, attr);
             if (XINCLUDE_NAMESPACE_URI.equals(uri)) {
@@ -367,6 +393,9 @@
                     getLogger().debug("URL: " + url.getURI() + "\nSuffix: " + suffix);
                 }
 
+                // add the source to the SourceValidity 
+                validity.addSource(url); 
+ 
                 // check loop inclusion
                 String canonicURI = url.getURI() + (suffix.length() > 0 ? "#" + suffix:
"");
                 if (isLoopInclusion(canonicURI))
@@ -453,7 +482,7 @@
             }
             return false;
         }
-        
+
         private String getLocation() {
             if (this.locator == null) {
                 return "unknown location";

Modified: cocoon/trunk/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/status.xml?rev=289891&r1=289890&r2=289891&view=diff
==============================================================================
--- cocoon/trunk/status.xml (original)
+++ cocoon/trunk/status.xml Sat Sep 17 22:37:11 2005
@@ -561,6 +561,9 @@
    </action>
   </release>
   <release version="2.1.8" date="TBD">
+    <action dev="AG" type="add" fixes-bug="31600" due-to="Frans Englich" due-to-email="frans.englich@telia.com">
+      Caching support for XInclude Transformer
+    </action>
     <action dev="SW" type="add" due-to="Max Pfingsthorn" due-to-email="max.pfingsthorn@gmail.com">
       CForms block: new form libraries features. You can now define form definition and binding
       library files and import them for reuse and/or extension in regular definition and
binding files.



Mime
View raw message