You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by il...@apache.org on 2012/06/07 11:57:10 UTC
svn commit: r1347556 - in /cocoon/cocoon3/trunk:
cocoon-sample/src/main/resources/COB-INF/
cocoon-sax/src/main/java/org/apache/cocoon/sax/component/
cocoon-sax/src/main/java/org/apache/cocoon/sax/util/
Author: ilgrosso
Date: Thu Jun 7 09:57:10 2012
New Revision: 1347556
URL: http://svn.apache.org/viewvc?rev=1347556&view=rev
Log:
[COCOON3-62] Implementing CacheKey via timestamp + modifiyng sample sitemap allowing some IT tests to keep working
Added:
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/URLManipulationUtils.java (with props)
Modified:
cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/COB-INF/sitemap.xmap
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java
Modified: cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/COB-INF/sitemap.xmap
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/COB-INF/sitemap.xmap?rev=1347556&r1=1347555&r2=1347556&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/COB-INF/sitemap.xmap (original)
+++ cocoon/cocoon3/trunk/cocoon-sample/src/main/resources/COB-INF/sitemap.xmap Thu Jun 7 09:57:10 2012
@@ -48,7 +48,7 @@
</map:pipeline>
<!-- ~~~~~~~~~~~~~~~~ sax pipelines ~~~~~~~~~~~~~~~ -->
- <map:pipeline jmx-group-name="sax">
+ <map:pipeline jmx-group-name="sax" type="noncaching">
<map:match equals="sax-pipeline/simple">
<map:generate src="sax-pipeline/simple.xml" />
<map:transform src="sax-pipeline/simple.xslt">
@@ -233,7 +233,7 @@
</map:pipeline>
<!-- ~~~~~~~~~~~~~~~~ advanced matching (when/otherwise) ~~~~~~~~~~~~~~~ -->
- <map:pipeline>
+ <map:pipeline type="noncaching">
<map:match pattern="advanced-matching">
<map:select value="{jexl:cocoon.request.myparam}">
<map:when equals="11">
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=1347556&r1=1347555&r2=1347556&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 Thu Jun 7 09:57:10 2012
@@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;
-
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
@@ -33,18 +32,21 @@ import javax.xml.transform.sax.SAXResult
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamSource;
-
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.component.CachingPipelineComponent;
import org.apache.cocoon.pipeline.util.StringRepresentation;
import org.apache.cocoon.sax.AbstractSAXTransformer;
import org.apache.cocoon.sax.SAXConsumer;
import org.apache.cocoon.sax.util.InMemoryLRUResourceCache;
import org.apache.cocoon.sax.util.SAXConsumerAdapter;
+import org.apache.cocoon.sax.util.URLManipulationUtils;
import org.apache.cocoon.sax.util.ValidityValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class XSLTTransformer extends AbstractSAXTransformer {
+public class XSLTTransformer extends AbstractSAXTransformer implements CachingPipelineComponent {
/**
* The memory based LRU cache for already loaded XSLTs.
@@ -280,7 +282,21 @@ public class XSLTTransformer extends Abs
saxConsumerAdapter.setContentHandler(transformerHandler);
super.setSAXConsumer(saxConsumerAdapter);
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.apache.cocoon.pipeline.component.CachingPipelineComponent #constructCacheKey()
+ */
+ @Override
+ public CacheKey constructCacheKey() {
+ if (this.source == null) {
+ throw new SetupException(this.getClass().getSimpleName() + " has no source.");
+ }
+ return new TimestampCacheKey(this.source, URLManipulationUtils.getLastModified(this.source));
+ }
+
/**
* Utility method to create a new transformer factory.
*
Added: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/URLManipulationUtils.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/URLManipulationUtils.java?rev=1347556&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/URLManipulationUtils.java (added)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/URLManipulationUtils.java Thu Jun 7 09:57:10 2012
@@ -0,0 +1,71 @@
+/*
+ * 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.sax.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import org.apache.cocoon.pipeline.util.URLConnectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class URLManipulationUtils {
+
+ /**
+ * Logger.
+ */
+ private static final Logger LOG = LoggerFactory.getLogger(URLManipulationUtils.class);
+
+ /**
+ * Find the actual last modification timestamp for the given URL,
+ * reverting to java.io.File#lastModified() when applicable.
+ *
+ * @param url URL to be examined for last modified
+ * @return File.lastModified() when applicable or URLconnection.getLastModified()
+ */
+ public static long getLastModified(final URL url) {
+ if (url == null) {
+ throw new IllegalArgumentException("URL source cannot be null");
+ }
+
+ long lastModified = -1;
+
+ if ("file".equals(url.getProtocol())) {
+ try {
+ lastModified = new File(url.toURI()).lastModified();
+ } catch (URISyntaxException e) {
+ LOG.error("Error while opening {} as file", url, e);
+ }
+ } else {
+ URLConnection connection = null;
+ try {
+ connection = url.openConnection();
+ lastModified = connection.getLastModified();
+ } catch (IOException e) {
+ LOG.error("Error while connecting to {}", url, e);
+ } finally {
+ if (connection != null) {
+ URLConnectionUtils.closeQuietly(connection);
+ }
+ }
+ }
+
+ return lastModified;
+ }
+}
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/URLManipulationUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/URLManipulationUtils.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/URLManipulationUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain