svn commit: r1449503 - in /cocoon/cocoon3/trunk: cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/ cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/generator/ cocoon-pipeline/src...

[email protected]
Newsgroups gmane.text.xml.cocoon.cvs
Message-ID <[email protected]>
Author: ilgrosso
Date: Sun Feb 24 16:42:40 2013
New Revision: 1449503

URL: http://svn.apache.org/r1449503
Log:
[COCOON3-71] #resolve

Added:
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampSourceCacheKey.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampURLCacheKey.java
      - copied, changed from r1449491, cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampCacheKey.java
Removed:
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampCacheKey.java
Modified:
    cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGenerator.java
    cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/generator/AddRootElementGenerator.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/URLListCacheKey.java
    cocoon/cocoon3/trunk/cocoon-rest-optional/pom.xml
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineBuilder.java
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SchemaProcessorTransformer.java
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLGenerator.java
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java
    cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/SchemaProcessorTransformerTest.java
    cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/component/FileReaderComponent.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/StringTemplateReader.java

Modified: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGenerator.java?rev=1449503&r1=1449502&r2=1449503&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGenerator.java (original)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGenerator.java Sun Feb 24 16:42:40 2013
@@ -34,7 +34,7 @@ import org.apache.cocoon.pipeline.Proces
 import org.apache.cocoon.pipeline.SetupException;
 import org.apache.cocoon.pipeline.caching.CacheKey;
 import org.apache.cocoon.pipeline.caching.CompoundCacheKey;
-import org.apache.cocoon.pipeline.caching.TimestampCacheKey;
+import org.apache.cocoon.pipeline.caching.TimestampURLCacheKey;
 import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
 import org.apache.cocoon.pipeline.components.parameters.Parameters;
 import org.apache.cocoon.sax.AbstractSAXGenerator;
@@ -465,13 +465,13 @@ public class DirectoryGenerator extends 
 
         try {
             final CompoundCacheKey key = new CompoundCacheKey();
-            TimestampCacheKey timestampCacheKey = new TimestampCacheKey(
+            TimestampURLCacheKey timestampCacheKey = new TimestampURLCacheKey(
                     this.directorySource.toURI().toURL(),
                     this.directorySource.lastModified());
             key.addCacheKey(timestampCacheKey);
 
             for (File file : this.validity) {
-                timestampCacheKey = new TimestampCacheKey(
+                timestampCacheKey = new TimestampURLCacheKey(
                         file.toURI().toURL(), file.lastModified());
                 key.addCacheKey(timestampCacheKey);
             }

Modified: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/generator/AddRootElementGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/generator/AddRootElementGenerator.java?rev=1449503&r1=1449502&r2=1449503&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/generator/AddRootElementGenerator.java (original)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/generator/AddRootElementGenerator.java Sun Feb 24 16:42:40 2013
@@ -23,7 +23,7 @@ import java.util.Map;
 
 import org.apache.cocoon.pipeline.ProcessingException;
 import org.apache.cocoon.pipeline.caching.CacheKey;
-import org.apache.cocoon.pipeline.caching.TimestampCacheKey;
+import org.apache.cocoon.pipeline.caching.TimestampURLCacheKey;
 import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
 import org.apache.cocoon.pipeline.util.URLConnectionUtils;
 import org.apache.cocoon.sax.AbstractSAXGenerator;
@@ -132,7 +132,7 @@ public class AddRootElementGenerator ext
      */
     @Override
     public CacheKey constructCacheKey() {
-        return new TimestampCacheKey(this.source, URLConnectionUtils
+        return new TimestampURLCacheKey(this.source, URLConnectionUtils
                 .getLastModified(this.source));
     }
 

Added: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampSourceCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampSourceCacheKey.java?rev=1449503&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampSourceCacheKey.java (added)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampSourceCacheKey.java Sun Feb 24 16:42:40 2013
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.caching;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import javax.xml.transform.Source;
+import org.apache.cocoon.pipeline.util.StringRepresentation;
+import org.apache.cocoon.util.murmurhash.MurmurHashCodeBuilder;
+
+public class TimestampSourceCacheKey extends AbstractCacheKey {
+
+    private static final long serialVersionUID = 79587530920810913L;
+
+    private long timestamp;
+
+    private final Source source;
+
+    public TimestampSourceCacheKey(final Source source, final long timestamp) {
+        super();
+
+        this.source = source;
+        this.timestamp = timestamp;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (!(obj instanceof TimestampSourceCacheKey)) {
+            return false;
+        }
+
+        final TimestampSourceCacheKey other = (TimestampSourceCacheKey) obj;
+        return this.source.equals(other.source);
+    }
+
+    public Source getSource() {
+        return source;
+    }
+
+    public long getTimestamp() {
+        return this.timestamp;
+    }
+
+    public void setTimestamp(final long timestamp) {
+        this.timestamp = timestamp;
+    }
+
+    @Override
+    public long getLastModified() {
+        return this.getTimestamp();
+    }
+
+    @Override
+    public int hashCode() {
+        return new MurmurHashCodeBuilder().
+                append(this.source.toString()).
+                append(this.timestamp).toHashCode();
+    }
+
+    @Override
+    public boolean isValid(final CacheKey cacheKey) {
+        if (!(cacheKey instanceof TimestampSourceCacheKey) || !this.equals(cacheKey)) {
+            return false;
+        }
+
+        final TimestampSourceCacheKey other = (TimestampSourceCacheKey) cacheKey;
+        return this.timestamp == other.timestamp;
+    }
+
+    @Override
+    public String toString() {
+        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
+        return StringRepresentation.buildString(this, "source=" + this.source.toString(),
+                "timestamp=" + this.timestamp + " (" + dateFormat.format(new Date(this.timestamp)) + ")");
+    }
+}

Copied: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampURLCacheKey.java (from r1449491, cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampCacheKey.java)
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampURLCacheKey.java?p2=cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampURLCacheKey.java&p1=cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampCacheKey.java&r1=1449491&r2=1449503&rev=1449503&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampCacheKey.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampURLCacheKey.java Sun Feb 24 16:42:40 2013
@@ -24,7 +24,7 @@ import java.util.Date;
 import org.apache.cocoon.pipeline.util.StringRepresentation;
 import org.apache.cocoon.util.murmurhash.MurmurHashCodeBuilder;
 
-public class TimestampCacheKey extends AbstractCacheKey {
+public class TimestampURLCacheKey extends AbstractCacheKey {
 
     private static final long serialVersionUID = -2790160879189162411L;
 
@@ -32,7 +32,7 @@ public class TimestampCacheKey extends A
 
     private final URL url;
 
-    public TimestampCacheKey(final URL url, final long timestamp) {
+    public TimestampURLCacheKey(final URL url, final long timestamp) {
         super();
 
         this.url = url;
@@ -41,11 +41,11 @@ public class TimestampCacheKey extends A
 
     @Override
     public boolean equals(final Object obj) {
-        if (!(obj instanceof TimestampCacheKey)) {
+        if (!(obj instanceof TimestampURLCacheKey)) {
             return false;
         }
 
-        final TimestampCacheKey other = (TimestampCacheKey) obj;
+        final TimestampURLCacheKey other = (TimestampURLCacheKey) obj;
         return this.url.toExternalForm().equals(other.url.toExternalForm());
     }
 
@@ -74,18 +74,18 @@ public class TimestampCacheKey extends A
 
     @Override
     public boolean isValid(final CacheKey cacheKey) {
-        if (!(cacheKey instanceof TimestampCacheKey) || !this.equals(cacheKey)) {
+        if (!(cacheKey instanceof TimestampURLCacheKey) || !this.equals(cacheKey)) {
             return false;
         }
 
-        final TimestampCacheKey other = (TimestampCacheKey) cacheKey;
+        final TimestampURLCacheKey other = (TimestampURLCacheKey) cacheKey;
         return this.timestamp == other.timestamp;
     }
 
     @Override
     public String toString() {
         final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
-        return StringRepresentation.buildString(this, "url=" + this.url,
+        return StringRepresentation.buildString(this, "url=" + this.url.toExternalForm(),
                 "timestamp=" + this.timestamp + " (" + dateFormat.format(new Date(this.timestamp)) + ")");
     }
 }

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/URLListCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/URLListCacheKey.java?rev=1449503&r1=1449502&r2=1449503&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/URLListCacheKey.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/URLListCacheKey.java Sun Feb 24 16:42:40 2013
@@ -44,10 +44,10 @@ public class URLListCacheKey extends Abs
 
     private static final long serialVersionUID = -5384157447531102615L;
 
-    private final List<TimestampCacheKey> cacheKeys = new LinkedList<TimestampCacheKey>();
+    private final List<TimestampURLCacheKey> cacheKeys = new LinkedList<TimestampURLCacheKey>();
 
     public void addURL(final URL url) {
-        this.cacheKeys.add(new TimestampCacheKey(url, URLConnectionUtils.getLastModified(url)));
+        this.cacheKeys.add(new TimestampURLCacheKey(url, URLConnectionUtils.getLastModified(url)));
     }
 
     @Override
@@ -67,12 +67,12 @@ public class URLListCacheKey extends Abs
             return false;
         }
 
-        final Iterator<TimestampCacheKey> myIterator = this.cacheKeys.iterator();
-        final Iterator<TimestampCacheKey> otherIterator = other.cacheKeys.iterator();
+        final Iterator<TimestampURLCacheKey> myIterator = this.cacheKeys.iterator();
+        final Iterator<TimestampURLCacheKey> otherIterator = other.cacheKeys.iterator();
 
         while (myIterator.hasNext()) {
-            final TimestampCacheKey myCacheKey = myIterator.next();
-            final TimestampCacheKey otherCacheKey = otherIterator.next();
+            final TimestampURLCacheKey myCacheKey = myIterator.next();
+            final TimestampURLCacheKey otherCacheKey = otherIterator.next();
 
             if (myCacheKey == null || !myCacheKey.equals(otherCacheKey)) {
                 if (LOG.isDebugEnabled()) {
@@ -110,12 +110,12 @@ public class URLListCacheKey extends Abs
         }
 
         final URLListCacheKey other = (URLListCacheKey) cacheKey;
-        final Iterator<TimestampCacheKey> myIterator = this.cacheKeys.iterator();
-        final Iterator<TimestampCacheKey> otherIterator = other.cacheKeys.iterator();
+        final Iterator<TimestampURLCacheKey> myIterator = this.cacheKeys.iterator();
+        final Iterator<TimestampURLCacheKey> otherIterator = other.cacheKeys.iterator();
 
         while (myIterator.hasNext()) {
-            final TimestampCacheKey myCacheKey = myIterator.next();
-            final TimestampCacheKey otherCacheKey = otherIterator.next();
+            final TimestampURLCacheKey myCacheKey = myIterator.next();
+            final TimestampURLCacheKey otherCacheKey = otherIterator.next();
 
             if (!myCacheKey.isValid(otherCacheKey)) {
                 LOG.debug("Cache key is not valid:\nmyCacheKey={}\notherCacheKey={}", myCacheKey, otherCacheKey);
@@ -130,7 +130,7 @@ public class URLListCacheKey extends Abs
     @Override
     public long getLastModified() {
         // update last-modificatied for each URL
-        for (TimestampCacheKey tCacheKey : this.cacheKeys) {
+        for (TimestampURLCacheKey tCacheKey : this.cacheKeys) {
             tCacheKey.setTimestamp(URLConnectionUtils.getLastModified(tCacheKey.getUrl()));
         }
 

Modified: cocoon/cocoon3/trunk/cocoon-rest-optional/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest-optional/pom.xml?rev=1449503&r1=1449502&r2=1449503&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-rest-optional/pom.xml (original)
+++ cocoon/cocoon3/trunk/cocoon-rest-optional/pom.xml Sun Feb 24 16:42:40 2013
@@ -30,7 +30,7 @@
   
   <artifactId>cocoon-rest-optional</artifactId>
   <groupId>org.apache.cocoon.rest.optional</groupId>
-  <name>Apache cocoon 3: Optional REST components</name>
+  <name>Apache Cocoon 3: Optional REST components</name>
   <description>org.cocoon.rest.optional:cocoon-rest-optional:3.0.0-beta-1-SNAPSHOT</description>
   
   <build>

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineBuilder.java?rev=1449503&r1=1449502&r2=1449503&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineBuilder.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/builder/LinkedSAXPipelineBuilder.java Sun Feb 24 16:42:40 2013
@@ -17,7 +17,7 @@
 package org.apache.cocoon.sax.builder;
 
 /**
- * 
+ *
  * @version: $Id$
  */
 public interface LinkedSAXPipelineBuilder {
@@ -27,5 +27,4 @@ public interface LinkedSAXPipelineBuilde
     LinkedSAXPipelineStarterBuilder newCachingPipeline();
 
     LinkedSAXPipelineStarterBuilder newNonCachingPipeline();
-
 }

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SchemaProcessorTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SchemaProcessorTransformer.java?rev=1449503&r1=1449502&r2=1449503&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SchemaProcessorTransformer.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SchemaProcessorTransformer.java Sun Feb 24 16:42:40 2013
@@ -21,12 +21,14 @@ package org.apache.cocoon.sax.component;
 import java.net.URL;
 import java.util.Map;
 import javax.xml.XMLConstants;
+import javax.xml.transform.Source;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
 import javax.xml.validation.ValidatorHandler;
 import org.apache.cocoon.pipeline.SetupException;
 import org.apache.cocoon.pipeline.caching.CacheKey;
-import org.apache.cocoon.pipeline.caching.TimestampCacheKey;
+import org.apache.cocoon.pipeline.caching.TimestampSourceCacheKey;
+import org.apache.cocoon.pipeline.caching.TimestampURLCacheKey;
 import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
 import org.apache.cocoon.pipeline.util.StringRepresentation;
 import org.apache.cocoon.pipeline.util.URLConnectionUtils;
@@ -54,31 +56,43 @@ public final class SchemaProcessorTransf
 
     private Schema schema;
 
-    private URL source;
+    private URL url;
+
+    private long lastModified;
+
+    private Source source;
 
     public SchemaProcessorTransformer() {
         super();
     }
 
-    public SchemaProcessorTransformer(URL source) {
+    public SchemaProcessorTransformer(final URL url) {
+        super();
+        this.init(url);
+    }
+
+    public SchemaProcessorTransformer(final Source source, final long lastModified) {
         super();
-        this.init(source);
+        this.init(source, lastModified);
     }
 
     @Override
-    public void setConfiguration(Map<String, ? extends Object> configuration) {
+    public void setConfiguration(final Map<String, ? extends Object> configuration) {
         this.init((URL) configuration.get(SOURCE));
     }
 
     @Override
     public String toString() {
-        return StringRepresentation.buildString(this, "src=" + this.source);
+        return StringRepresentation.buildString(this, "src=" + (this.url == null
+                ? "<" + this.source + "," + this.lastModified + ">"
+                : this.url.toExternalForm()));
     }
 
     @Override
-    protected void setSAXConsumer(SAXConsumer xmlConsumer) {
+    protected void setSAXConsumer(final SAXConsumer xmlConsumer) {
         ValidatorHandler validatorHandler = this.schema.newValidatorHandler();
-        validatorHandler.setErrorHandler(new SchemaErrorHandler(LOG, this.source.toExternalForm()));
+        validatorHandler.setErrorHandler(new SchemaErrorHandler(LOG,
+                this.url == null ? this.source.toString() : this.url.toExternalForm()));
         validatorHandler.setContentHandler(xmlConsumer);
 
         SAXConsumerAdapter saxConsumerAdapter = new SAXConsumerAdapter();
@@ -86,45 +100,76 @@ public final class SchemaProcessorTransf
         super.setSAXConsumer(saxConsumerAdapter);
     }
 
-    private void init(URL source) {
-        if (source == null) {
-            throw new IllegalArgumentException("The parameter 'source' mustn't be null.");
+    private void checkLocalCache(final String key) {
+        if (SCHEMA_CACHE.containsKey(key)) {
+            ValidityValue<Schema> cacheEntry = SCHEMA_CACHE.get(key);
+            if (cacheEntry.getLastModified() >= this.lastModified) {
+                LOG.debug("{} local cache hit: {}", getClass().getSimpleName(), key);
+
+                this.schema = cacheEntry.getValue();
+            }
         }
+    }
 
-        this.source = source;
+    private void putInLocalCache(final String key) {
+        LOG.debug("{} local cache miss: {}", getClass().getSimpleName(), key);
 
-        Long lastModified = URLConnectionUtils.getLastModified(this.source);
+        LOG.debug("{} local cache put: {}", getClass().getSimpleName(), key);
 
-        if (SCHEMA_CACHE.containsKey(source.toExternalForm())) {
-            ValidityValue<Schema> cacheEntry = SCHEMA_CACHE.get(source.toExternalForm());
-            if (lastModified == null || cacheEntry.getLastModified() >= lastModified) {
-                LOG.debug("{} local cache hit: {}", getClass().getSimpleName(), this.source.toExternalForm());
+        ValidityValue<Schema> cacheEntry = new ValidityValue<Schema>(this.schema, this.lastModified);
+        SCHEMA_CACHE.put(key, cacheEntry);
+    }
 
-                this.schema = cacheEntry.getValue();
-            }
+    private void init(final URL url) {
+        if (url == null) {
+            throw new IllegalArgumentException("The parameter 'source' mustn't be null.");
         }
-        if (this.schema == null) {
-            LOG.debug("{} local cache miss: {}", getClass().getSimpleName(), this.source.toExternalForm());
 
+        this.url = url;
+        this.lastModified = URLConnectionUtils.getLastModified(this.url);
+
+        checkLocalCache(this.url.toExternalForm());
+
+        if (this.schema == null) {
             try {
-                this.schema = SCHEMA_FACTORY.newSchema(source);
+                this.schema = SCHEMA_FACTORY.newSchema(this.url);
+            } catch (SAXException e) {
+                throw new SetupException("Could not initialize xschema source", e);
+            }
 
-                LOG.debug("{} local cache put: {}", getClass().getSimpleName(), this.source.toExternalForm());
+            putInLocalCache(this.url.toExternalForm());
+        }
+    }
 
-                ValidityValue<Schema> cacheEntry = new ValidityValue<Schema>(this.schema, lastModified);
-                SCHEMA_CACHE.put(this.source.toExternalForm(), cacheEntry);
+    private void init(final Source source, final long lastModified) {
+        if (source == null) {
+            throw new IllegalArgumentException("The parameter 'source' mustn't be null.");
+        }
+
+        this.source = source;
+        this.lastModified = lastModified;
+
+        checkLocalCache(this.source.toString());
+
+        if (this.schema == null) {
+            try {
+                this.schema = SCHEMA_FACTORY.newSchema(this.source);
             } catch (SAXException e) {
                 throw new SetupException("Could not initialize xschema source", e);
             }
+
+            putInLocalCache(this.source.toString());
         }
     }
 
     @Override
     public CacheKey constructCacheKey() {
-        if (this.source == null) {
+        if (this.url == null && this.source == null) {
             throw new SetupException(this.getClass().getSimpleName() + " has no source.");
         }
 
-        return new TimestampCacheKey(this.source, URLConnectionUtils.getLastModified(this.source));
+        return this.url == null
+                ? new TimestampSourceCacheKey(this.source, this.lastModified)
+                : new TimestampURLCacheKey(this.url, this.lastModified);
     }
 }

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java?rev=1449503&r1=1449502&r2=1449503&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XIncludeTransformer.java Sun Feb 24 16:42:40 2013
@@ -32,7 +32,7 @@ import org.apache.cocoon.pipeline.Proces
 import org.apache.cocoon.pipeline.caching.CacheKey;
 import org.apache.cocoon.pipeline.caching.CachedCacheKey;
 import org.apache.cocoon.pipeline.caching.CompoundCacheKey;
-import org.apache.cocoon.pipeline.caching.TimestampCacheKey;
+import org.apache.cocoon.pipeline.caching.TimestampURLCacheKey;
 import org.apache.cocoon.pipeline.caching.URLListCacheKey;
 import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
 import org.apache.cocoon.pipeline.util.StringRepresentation;

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=1449503&r1=1449502&r2=1449503&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 Sun Feb 24 16:42:40 2013
@@ -32,7 +32,7 @@ import org.apache.cocoon.pipeline.Pipeli
 import org.apache.cocoon.pipeline.ProcessingException;
 import org.apache.cocoon.pipeline.SetupException;
 import org.apache.cocoon.pipeline.caching.CacheKey;
-import org.apache.cocoon.pipeline.caching.TimestampCacheKey;
+import org.apache.cocoon.pipeline.caching.TimestampURLCacheKey;
 import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
 import org.apache.cocoon.pipeline.component.Starter;
 import org.apache.cocoon.pipeline.util.StringRepresentation;
@@ -203,7 +203,7 @@ public class XMLGenerator extends Abstra
 
             CacheKey cacheKey = null;
             try {
-                cacheKey = new TimestampCacheKey(this.file.toURI().toURL(), this.file.lastModified());
+                cacheKey = new TimestampURLCacheKey(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);
@@ -383,7 +383,7 @@ public class XMLGenerator extends Abstra
          */
         @Override
         public CacheKey constructCacheKey() {
-            return new TimestampCacheKey(this.source, URLConnectionUtils.getLastModified(this.source));
+            return new TimestampURLCacheKey(this.source, URLConnectionUtils.getLastModified(this.source));
         }
 
         /**

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=1449503&r1=1449502&r2=1449503&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 Sun Feb 24 16:42:40 2013
@@ -33,7 +33,7 @@ import org.apache.cocoon.pipeline.SetupE
 import org.apache.cocoon.pipeline.caching.CacheKey;
 import org.apache.cocoon.pipeline.caching.CompoundCacheKey;
 import org.apache.cocoon.pipeline.caching.ParameterCacheKey;
-import org.apache.cocoon.pipeline.caching.TimestampCacheKey;
+import org.apache.cocoon.pipeline.caching.TimestampURLCacheKey;
 import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
 import org.apache.cocoon.pipeline.util.StringRepresentation;
 import org.apache.cocoon.pipeline.util.URLConnectionUtils;
@@ -263,7 +263,7 @@ public class XSLTTransformer extends Abs
         }
 
         final CompoundCacheKey cacheKey = new CompoundCacheKey();
-        cacheKey.addCacheKey(new TimestampCacheKey(this.source, URLConnectionUtils.getLastModified(this.source)));
+        cacheKey.addCacheKey(new TimestampURLCacheKey(this.source, URLConnectionUtils.getLastModified(this.source)));
         cacheKey.addCacheKey(ParameterCacheKey.getSitemapSafeInstance(this.parameters));
 
         return cacheKey;

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/SchemaProcessorTransformerTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/SchemaProcessorTransformerTest.java?rev=1449503&r1=1449502&r2=1449503&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/SchemaProcessorTransformerTest.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/test/java/org/apache/cocoon/sax/SchemaProcessorTransformerTest.java Sun Feb 24 16:42:40 2013
@@ -18,12 +18,15 @@
  */
 package org.apache.cocoon.sax;
 
-import static junit.framework.Assert.*;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.ByteArrayOutputStream;
+import javax.xml.transform.stream.StreamSource;
 
 import org.apache.cocoon.pipeline.NonCachingPipeline;
 import org.apache.cocoon.pipeline.Pipeline;
+import org.apache.cocoon.pipeline.util.URLConnectionUtils;
 import org.apache.cocoon.sax.component.XMLGenerator;
 import org.apache.cocoon.sax.component.SchemaProcessorTransformer;
 import org.apache.cocoon.sax.component.SchemaValidationException;
@@ -34,13 +37,16 @@ import org.junit.Test;
 public class SchemaProcessorTransformerTest {
 
     /**
-     * A pipeline that performs an identity transformation, using the validation: generator -&gt;
-     * validator -&gt; serializer
+     * A pipeline that performs an identity transformation, using the validation: generator -&gt; validator -&gt;
+     * serializer
      */
     @Test
     public void testPipelineWithValidation() throws Exception {
-        Pipeline<SAXPipelineComponent> pipeline = this.createValidatingPipeline("<x></x>");
+        testPipelineWithValidationInternal(this.createValidatingURLPipeline("<x></x>"));
+        testPipelineWithValidationInternal(this.createValidatingSourcePipeline("<x></x>"));
+    }
 
+    private void testPipelineWithValidationInternal(final Pipeline<SAXPipelineComponent> pipeline) throws Exception {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         pipeline.setup(baos);
         pipeline.execute();
@@ -53,22 +59,44 @@ public class SchemaProcessorTransformerT
     }
 
     /**
-     * A pipeline that performs an identity transformation, using the validation: generator -&gt;
-     * validator -&gt; serializer. An error is expected performing <code>execute</code> method due
-     * to not valid xml input.
+     * A pipeline that performs an identity transformation, using the validation: generator -&gt; validator -&gt;
+     * serializer. An error is expected performing
+     * <code>execute</code> method due to not valid xml input.
      */
-    @Test(expected = SchemaValidationException.class)
-    public void testPipelineWithWrongValidation() throws Exception {
-        Pipeline<SAXPipelineComponent> pipeline = this.createValidatingPipeline("<y><z/></y>");
+    @Test
+    public void testPipelineWithWrongValidation() {
+        testPipelineWithWrongValidationInternal(this.createValidatingURLPipeline("<y><z/></y>"));
+        testPipelineWithWrongValidationInternal(this.createValidatingSourcePipeline("<y><z/></y>"));
+    }
+
+    private void testPipelineWithWrongValidationInternal(final Pipeline<SAXPipelineComponent> pipeline) {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         pipeline.setup(baos);
-        pipeline.execute();
+        try {
+            pipeline.execute();
+            fail("Not expected to reach this point");
+        } catch (Exception e) {
+            assertTrue(e instanceof SchemaValidationException);
+        }
     }
 
-    private Pipeline<SAXPipelineComponent> createValidatingPipeline(String xmlInput) {
+    private Pipeline<SAXPipelineComponent> createValidatingURLPipeline(final String xmlInput) {
+        return createValidatinPipeline(xmlInput,
+                new SchemaProcessorTransformer(this.getClass().getResource("/test.xsd")));
+    }
+
+    private Pipeline<SAXPipelineComponent> createValidatingSourcePipeline(final String xmlInput) {
+        return createValidatinPipeline(xmlInput, new SchemaProcessorTransformer(
+                new StreamSource(this.getClass().getResourceAsStream("/test.xsd")),
+                URLConnectionUtils.getLastModified(this.getClass().getResource("/test.xsd"))));
+    }
+
+    private Pipeline<SAXPipelineComponent> createValidatinPipeline(final String xmlInput,
+            final SchemaProcessorTransformer spt) {
+
         Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<SAXPipelineComponent>();
         pipeline.addComponent(new XMLGenerator(xmlInput));
-        pipeline.addComponent(new SchemaProcessorTransformer(this.getClass().getResource("/test.xsd")));
+        pipeline.addComponent(spt);
         pipeline.addComponent(new XMLSerializer());
 
         return pipeline;

Modified: cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/component/FileReaderComponent.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/component/FileReaderComponent.java?rev=1449503&r1=1449502&r2=1449503&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/component/FileReaderComponent.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/component/FileReaderComponent.java Sun Feb 24 16:42:40 2013
@@ -24,7 +24,7 @@ import java.net.URL;
 import java.net.URLConnection;
 import org.apache.cocoon.pipeline.ProcessingException;
 import org.apache.cocoon.pipeline.caching.CacheKey;
-import org.apache.cocoon.pipeline.caching.TimestampCacheKey;
+import org.apache.cocoon.pipeline.caching.TimestampURLCacheKey;
 import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
 import org.apache.cocoon.pipeline.util.URLConnectionUtils;
 
@@ -45,7 +45,7 @@ public class FileReaderComponent extends
      */
     @Override
     public CacheKey constructCacheKey() {
-        return new TimestampCacheKey(this.source, URLConnectionUtils.getLastModified(this.source));
+        return new TimestampURLCacheKey(this.source, URLConnectionUtils.getLastModified(this.source));
     }
 
     /**

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=1449503&r1=1449502&r2=1449503&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 Sun Feb 24 16:42:40 2013
@@ -28,7 +28,7 @@ import org.apache.cocoon.pipeline.Proces
 import org.apache.cocoon.pipeline.caching.CacheKey;
 import org.apache.cocoon.pipeline.caching.CompoundCacheKey;
 import org.apache.cocoon.pipeline.caching.ParameterCacheKey;
-import org.apache.cocoon.pipeline.caching.TimestampCacheKey;
+import org.apache.cocoon.pipeline.caching.TimestampURLCacheKey;
 import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
 import org.apache.cocoon.pipeline.component.Starter;
 import org.apache.cocoon.pipeline.util.URLConnectionUtils;
@@ -96,7 +96,7 @@ public class StringTemplateGenerator ext
         }
 
         final CompoundCacheKey cacheKey = new CompoundCacheKey();
-        cacheKey.addCacheKey(new TimestampCacheKey(this.url, URLConnectionUtils.getLastModified(this.url)));
+        cacheKey.addCacheKey(new TimestampURLCacheKey(this.url, URLConnectionUtils.getLastModified(this.url)));
         cacheKey.addCacheKey(ParameterCacheKey.getSitemapSafeInstance(this.parameters));
 
         return cacheKey;

Modified: cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateReader.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateReader.java?rev=1449503&r1=1449502&r2=1449503&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateReader.java (original)
+++ cocoon/cocoon3/trunk/cocoon-stringtemplate/src/main/java/org/apache/cocoon/stringtemplate/StringTemplateReader.java Sun Feb 24 16:42:40 2013
@@ -28,7 +28,7 @@ import org.apache.cocoon.pipeline.Proces
 import org.apache.cocoon.pipeline.caching.CacheKey;
 import org.apache.cocoon.pipeline.caching.CompoundCacheKey;
 import org.apache.cocoon.pipeline.caching.ParameterCacheKey;
-import org.apache.cocoon.pipeline.caching.TimestampCacheKey;
+import org.apache.cocoon.pipeline.caching.TimestampURLCacheKey;
 import org.apache.cocoon.pipeline.component.AbstractPipelineComponent;
 import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
 import org.apache.cocoon.pipeline.component.Finisher;
@@ -72,7 +72,7 @@ public class StringTemplateReader extend
         }
 
         final CompoundCacheKey cacheKey = new CompoundCacheKey();
-        cacheKey.addCacheKey(new TimestampCacheKey(this.source, URLConnectionUtils.getLastModified(this.source)));
+        cacheKey.addCacheKey(new TimestampURLCacheKey(this.source, URLConnectionUtils.getLastModified(this.source)));
         cacheKey.addCacheKey(new ParameterCacheKey("contextParameters", this.parameters));
 
         return cacheKey;
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.