svn commit: r1347419 - /cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLGenerator.java

[email protected]
Newsgroups gmane.text.xml.cocoon.cvs
Message-ID <[email protected]>
Author: ilgrosso
Date: Thu Jun  7 06:53:30 2012
New Revision: 1347419

URL: http://svn.apache.org/viewvc?rev=1347419&view=rev
Log:
Making XMLGenerator cacheable

Modified:
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLGenerator.java

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLGenerator.java?rev=1347419&r1=1347418&r2=1347419&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLGenerator.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLGenerator.java Thu Jun  7 06:53:30 2012
@@ -24,6 +24,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Arrays;
@@ -192,7 +193,7 @@ public class XMLGenerator extends Abstra
         }
     }
 
-    private class FileGenerator extends AbstractSAXGenerator {
+    private class FileGenerator extends AbstractSAXGenerator implements CachingPipelineComponent {
 
         private final transient File file;
 
@@ -204,6 +205,28 @@ public class XMLGenerator extends Abstra
 
             this.file = file;
         }
+        
+        /**
+         * {@inheritDoc}
+         *
+         * @see org.apache.cocoon.pipeline.component.CachingPipelineComponent #constructCacheKey()
+         */
+        @Override
+        public CacheKey constructCacheKey() {
+            if (this.file == null) {
+                throw new SetupException(this.getClass().getSimpleName() + " has no file.");
+            }
+
+            CacheKey cacheKey = null;
+            try {
+                cacheKey = new TimestampCacheKey(this.file.toURI().toURL(), this.file.lastModified());
+            } catch (MalformedURLException e) {
+                LOG.error("Can't construct cache key. "
+                        + "Error while converting to " + this.file + " to URL", e);
+            }
+
+            return cacheKey;
+        }
 
         @Override
         public void execute() {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.