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/11/27 13:42:06 UTC
svn commit: r1414157 [2/2] - in
/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline:
./ builder/ caching/ component/ util/
Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java?rev=1414157&r1=1414156&r2=1414157&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/ParameterCacheKey.java Tue Nov 27 12:41:54 2012
@@ -31,8 +31,6 @@ import org.apache.cocoon.util.murmurhash
*/
public class ParameterCacheKey extends AbstractCacheKey {
- private static final long serialVersionUID = 1L;
-
/**
* Set of parameter names that must not be considered for caching when in Sitemap context.
*/
@@ -44,6 +42,8 @@ public class ParameterCacheKey extends A
"javax.servlet.http.HttpServletResponse"
}));
+ private static final long serialVersionUID = -6069623439023188073L;
+
private final Map<String, String> parameters;
/**
@@ -52,15 +52,13 @@ public class ParameterCacheKey extends A
* @param parameters to be considered for caching
* @return a Sitemap-safe instance
*/
- public static ParameterCacheKey getSitemapSafeInstance(Map<String, Object> parameters) {
- if (parameters == null) {
- parameters = Collections.EMPTY_MAP;
- }
-
- Map<String, String> safeParams = new HashMap<String, String>();
- for (Entry<String, Object> entry : parameters.entrySet()) {
- if (!SITEMAP_PARAM_NON_CACHABLE_NAMES.contains(entry.getKey())) {
- safeParams.put(entry.getKey(), entry.getValue().toString());
+ public static ParameterCacheKey getSitemapSafeInstance(final Map<String, Object> parameters) {
+ final Map<String, String> safeParams = new HashMap<String, String>();
+ if (parameters != null) {
+ for (Entry<String, Object> entry : parameters.entrySet()) {
+ if (!SITEMAP_PARAM_NON_CACHABLE_NAMES.contains(entry.getKey())) {
+ safeParams.put(entry.getKey(), entry.getValue().toString());
+ }
}
}
@@ -71,7 +69,7 @@ public class ParameterCacheKey extends A
this(new HashMap<String, String>());
}
- public ParameterCacheKey(Map<String, String> parameters) {
+ public ParameterCacheKey(final Map<String, String> parameters) {
if (parameters == null) {
throw new IllegalArgumentException("A map of parameters has to be passed.");
}
@@ -79,31 +77,31 @@ public class ParameterCacheKey extends A
this.parameters = parameters;
}
- public ParameterCacheKey(String name, Map<?, ?> value) {
+ public ParameterCacheKey(final String name, Map<?, ?> value) {
this();
this.addParameter(name, value);
}
- public ParameterCacheKey(String name, String value) {
+ public ParameterCacheKey(final String name, String value) {
this();
this.addParameter(name, value);
}
- public void addParameter(String name, boolean value) {
+ public void addParameter(final String name, final boolean value) {
this.parameters.put(name, Boolean.toString(value));
}
- public void addParameter(String name, int value) {
+ public void addParameter(final String name, final int value) {
this.parameters.put(name, Integer.toString(value));
}
- public final void addParameter(String name, Map<?, ?> value) {
+ public final void addParameter(final String name, final Map<?, ?> value) {
for (Entry<?, ?> object : value.entrySet()) {
this.parameters.put(name + "_" + object.getKey().toString(), object.getValue().toString());
}
}
- public final void addParameter(String name, String value) {
+ public final void addParameter(final String name, final String value) {
this.parameters.put(name, value);
}
@@ -117,12 +115,12 @@ public class ParameterCacheKey extends A
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (!(obj instanceof ParameterCacheKey)) {
return false;
}
- ParameterCacheKey other = (ParameterCacheKey) obj;
+ final ParameterCacheKey other = (ParameterCacheKey) obj;
return this.parameters != null && this.parameters.equals(other.parameters);
}
@@ -143,7 +141,7 @@ public class ParameterCacheKey extends A
*/
@Override
public int hashCode() {
- MurmurHashCodeBuilder hashCodeBuilder = new MurmurHashCodeBuilder();
+ final MurmurHashCodeBuilder hashCodeBuilder = new MurmurHashCodeBuilder();
for (Entry<String, String> parameterEntry : this.parameters.entrySet()) {
hashCodeBuilder.append(parameterEntry.getKey()).append(parameterEntry.getValue());
}
@@ -156,7 +154,7 @@ public class ParameterCacheKey extends A
* @see org.apache.cocoon.pipeline.caching.CacheKey#isValid(org.apache.cocoon.pipeline.caching.CacheKey)
*/
@Override
- public boolean isValid(CacheKey cacheKey) {
+ public boolean isValid(final CacheKey cacheKey) {
return this.equals(cacheKey);
}
Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCache.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCache.java?rev=1414157&r1=1414156&r2=1414157&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCache.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCache.java Tue Nov 27 12:41:54 2012
@@ -21,18 +21,15 @@ package org.apache.cocoon.pipeline.cachi
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
-
import org.apache.cocoon.pipeline.util.StringRepresentation;
/**
- * A very simple implementation of the {@link Cache} interface.<br>
- * <br>
- * It uses a {@link WeakHashMap} as internal data store.
+ * A very simple implementation of the {@link Cache} interface.<br/><br/> It uses a {@link WeakHashMap} as internal data
+ * store.
*/
public class SimpleCache extends AbstractCache {
- private final Map<CacheKey, CacheValue> map =
- new WeakHashMap<CacheKey, CacheValue>();
+ private final Map<CacheKey, CacheValue> map = new WeakHashMap<CacheKey, CacheValue>();
/**
* {@inheritDoc}
@@ -62,7 +59,7 @@ public class SimpleCache extends Abstrac
* {@inheritDoc}
*
* @see org.apache.cocoon.pipeline.caching.AbstractCache#store(org.apache.cocoon.pipeline.caching.CacheKey,
- * org.apache.cocoon.pipeline.caching.CacheValue)
+ * org.apache.cocoon.pipeline.caching.CacheValue)
*/
@Override
protected void store(final CacheKey cacheKey, final CacheValue cacheValue) {
Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCacheKey.java?rev=1414157&r1=1414156&r2=1414157&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCacheKey.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/SimpleCacheKey.java Tue Nov 27 12:41:54 2012
@@ -23,10 +23,10 @@ import org.apache.cocoon.util.murmurhash
public class SimpleCacheKey extends AbstractCacheKey {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 6668460290536876103L;
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
return obj instanceof SimpleCacheKey;
}
@@ -35,10 +35,12 @@ public class SimpleCacheKey extends Abst
return new MurmurHashCodeBuilder().append(this.getClass().getName()).toHashCode();
}
- public boolean isValid(CacheKey cacheKey) {
+ @Override
+ public boolean isValid(final CacheKey cacheKey) {
return true;
}
+ @Override
public long getLastModified() {
return 0;
}
Modified: 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/TimestampCacheKey.java?rev=1414157&r1=1414156&r2=1414157&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/TimestampCacheKey.java Tue Nov 27 12:41:54 2012
@@ -26,7 +26,7 @@ import org.apache.cocoon.util.murmurhash
public class TimestampCacheKey extends AbstractCacheKey {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = -2790160879189162411L;
private long timestamp;
@@ -57,7 +57,7 @@ public class TimestampCacheKey extends A
return this.timestamp;
}
- public void setTimestamp(long timestamp) {
+ public void setTimestamp(final long timestamp) {
this.timestamp = timestamp;
}
@@ -84,10 +84,8 @@ public class TimestampCacheKey extends A
@Override
public String toString() {
- final SimpleDateFormat dateFormat =
- new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
- return StringRepresentation.buildString(this,
- "url=" + this.url, "timestamp=" + this.timestamp + " ("
- + dateFormat.format(new Date(this.timestamp)) + ")");
+ final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
+ return StringRepresentation.buildString(this, "url=" + this.url,
+ "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=1414157&r1=1414156&r2=1414157&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 Tue Nov 27 12:41:54 2012
@@ -30,8 +30,8 @@ import org.slf4j.LoggerFactory;
/**
* A
- * <code>CacheKey</code> holding a list of URLs.
- * Similar to CompoundCacheKey, this class will update URL timestamps before going into getLastModified().
+ * <code>CacheKey</code> holding a list of URLs. Similar to CompoundCacheKey, this class will update URL timestamps
+ * before going into getLastModified().
*
* @see CompoundCacheKey
*/
@@ -42,6 +42,8 @@ public class URLListCacheKey extends Abs
*/
private static final Logger LOG = LoggerFactory.getLogger(URLListCacheKey.class);
+ private static final long serialVersionUID = -5384157447531102615L;
+
private final List<TimestampCacheKey> cacheKeys = new LinkedList<TimestampCacheKey>();
public void addURL(final URL url) {
@@ -112,15 +114,11 @@ public class URLListCacheKey extends Abs
final Iterator<TimestampCacheKey> otherIterator = other.cacheKeys.iterator();
while (myIterator.hasNext()) {
- TimestampCacheKey myCacheKey = myIterator.next();
- TimestampCacheKey otherCacheKey = otherIterator.next();
+ final TimestampCacheKey myCacheKey = myIterator.next();
+ final TimestampCacheKey otherCacheKey = otherIterator.next();
if (!myCacheKey.isValid(otherCacheKey)) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Cache key is not valid: ");
- LOG.debug(" myCacheKey=" + myCacheKey);
- LOG.debug(" otherCacheKey=" + otherCacheKey);
- }
+ LOG.debug("Cache key is not valid:\nmyCacheKey={}\notherCacheKey={}", myCacheKey, otherCacheKey);
return false;
}
Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/AbstractPipelineComponent.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/AbstractPipelineComponent.java?rev=1414157&r1=1414156&r2=1414157&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/AbstractPipelineComponent.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/AbstractPipelineComponent.java Tue Nov 27 12:41:54 2012
@@ -1,38 +1,42 @@
/*
- * 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
+ * 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.
+ * 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.component;
import java.util.Map;
/**
- * A basic implementation of a {@link PipelineComponent} that provides empty
- * implementations of all its methods.
+ * A basic implementation of a {@link PipelineComponent} that provides empty implementations of all its methods.
*/
public abstract class AbstractPipelineComponent implements PipelineComponent {
+ @Override
public void finish() {
// do nothing
}
- public void setConfiguration(Map<String, ? extends Object> configuration) {
+ @Override
+ public void setConfiguration(final Map<String, ? extends Object> configuration) {
// do nothing
}
- public void setup(Map<String, Object> parameters) {
+ @Override
+ public void setup(final Map<String, Object> parameters) {
// do nothing
}
}
Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/StringRepresentation.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/StringRepresentation.java?rev=1414157&r1=1414156&r2=1414157&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/StringRepresentation.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/StringRepresentation.java Tue Nov 27 12:41:54 2012
@@ -1,39 +1,46 @@
/*
- * 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
+ * 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.
+ * 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.util;
/**
* Helper class to create the {@link String} for {@link Object#toString()}.
*/
-public abstract class StringRepresentation {
+public final class StringRepresentation {
- public static String buildString(Object instance, String... additionalOutputStrings) {
- StringBuilder sb = new StringBuilder();
- sb.append(instance.getClass().getSimpleName());
- sb.append("(hashCode=").append(System.identityHashCode(instance));
+ public static String buildString(final Object instance, final String... moreOutputStrs) {
+ final StringBuilder builder = new StringBuilder();
+ builder.append(instance.getClass().getSimpleName());
+ builder.append("(hashCode=").append(System.identityHashCode(instance));
- if (additionalOutputStrings != null) {
- for (String outputString : additionalOutputStrings) {
- sb.append(" ").append(outputString);
+ if (moreOutputStrs != null) {
+ for (String outputString : moreOutputStrs) {
+ builder.append(" ").append(outputString);
}
}
- sb.append(")");
+ builder.append(")");
- return sb.toString();
+ return builder.toString();
}
+ /**
+ * Private constructor, suggested for classes with static methods only.
+ */
+ private StringRepresentation() {
+ }
}
Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/URLConnectionUtils.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/URLConnectionUtils.java?rev=1414157&r1=1414156&r2=1414157&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/URLConnectionUtils.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/util/URLConnectionUtils.java Tue Nov 27 12:41:54 2012
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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.
+ * 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.util;
@@ -27,20 +29,19 @@ import java.net.URLConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class URLConnectionUtils {
+public final class URLConnectionUtils {
/**
* Logger.
*/
- private static final Logger LOG =
- LoggerFactory.getLogger(URLConnectionUtils.class);
+ private static final Logger LOG = LoggerFactory.getLogger(URLConnectionUtils.class);
/**
* Close a {@link URLConnection} quietly and take care of all the exception handling.
*
* @param urlConnection {@link URLConnection} to be closed.
*/
- public static void closeQuietly(URLConnection urlConnection) {
+ public static void closeQuietly(final URLConnection urlConnection) {
if (urlConnection == null) {
return;
}
@@ -68,12 +69,12 @@ public abstract class URLConnectionUtils
}
}
- private static void close(URLConnection urlConnection, Closeable closeable) {
+ private static void close(final URLConnection urlConnection, final Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException e) {
- LOG.warn("Can't close stream (" + closeable.getClass().getSimpleName() + "): "
+ LOG.warn("Can't close stream (" + closeable.getClass().getSimpleName() + "): "
+ urlConnection.getURL(), e);
}
}
@@ -115,4 +116,10 @@ public abstract class URLConnectionUtils
return lastModified;
}
+
+ /**
+ * Private constructor, suggested for classes with static methods only.
+ */
+ private URLConnectionUtils() {
+ }
}