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 2011/07/02 17:48:07 UTC
svn commit: r1142238 - in /cocoon/cocoon3/trunk:
cocoon-optional/src/main/java/org/apache/cocoon/generation/
cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/
cocoon-sax/src/main/java/org/apache/cocoon/sax/component/
cocoon-sax/src/main...
Author: ilgrosso
Date: Sat Jul 2 15:47:58 2011
New Revision: 1142238
URL: http://svn.apache.org/viewvc?rev=1142238&view=rev
Log:
Starting the mission (impossible) of improving Sonar report on PMD, Findbugs and Checkstyle
Modified:
cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/generation/DirectoryGenerator.java
cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CompleteCacheValue.java
cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/TimestampCacheKey.java
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SchemaErrorHandler.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/XMLGenerator.java
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XSLTTransformer.java
cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/InMemoryLRUResourceCache.java
Modified: cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/generation/DirectoryGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/generation/DirectoryGenerator.java?rev=1142238&r1=1142237&r2=1142238&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/generation/DirectoryGenerator.java (original)
+++ cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/generation/DirectoryGenerator.java Sat Jul 2 15:47:58 2011
@@ -41,9 +41,12 @@ import java.util.Stack;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
-public class DirectoryGenerator extends AbstractSAXGenerator implements
- CachingPipelineComponent {
- private final Log logger = LogFactory.getLog(this.getClass());
+public class DirectoryGenerator extends AbstractSAXGenerator
+ implements CachingPipelineComponent {
+
+ private static final Log LOG = LogFactory.getLog(DirectoryGenerator.class);
+
+ private static final String CDATA = "CDATA";
/** The URI of the namespace of this generator. */
protected static final String URI = "http://apache.org/cocoon/directory/2.0";
@@ -53,18 +56,22 @@ public class DirectoryGenerator extends
/* Node and attribute names */
protected static final String DIR_NODE_NAME = "directory";
+
protected static final String FILE_NODE_NAME = "file";
protected static final String FILENAME_ATTR_NAME = "name";
+
protected static final String LASTMOD_ATTR_NAME = "lastModified";
+
protected static final String DATE_ATTR_NAME = "date";
+
protected static final String SIZE_ATTR_NAME = "size";
/**
* Convenience object, so we don't need to create an AttributesImpl for
* every element.
*/
- protected AttributesImpl attributes = new AttributesImpl();
+ protected AttributesImpl attributes = new AttributesImpl();
/**
* The depth parameter determines how deep the DirectoryGenerator should
@@ -77,7 +84,9 @@ public class DirectoryGenerator extends
* should be converted. FIXME: SimpleDateFormat is not supported by all
* locales!
*/
- protected SimpleDateFormat dateFormatter = new SimpleDateFormat();;
+ protected SimpleDateFormat dateFormatter = new SimpleDateFormat();
+
+ ;
/** The delay between checks on updates to the filesystem. */
protected long refreshDelay;
@@ -88,7 +97,7 @@ public class DirectoryGenerator extends
* "lastmodified" and "directory", where "directory" is the same as "name",
* except that directory entries are listed first.
*/
- protected String sort ="name";
+ protected String sort = "name";
/**
* The reverse parameter reverses the sort order. <code>false</code> is
@@ -121,24 +130,27 @@ public class DirectoryGenerator extends
}
public DirectoryGenerator() {
+ super();
}
- public DirectoryGenerator(File file) {
+ public DirectoryGenerator(final File file) {
+ super();
if (file == null) {
throw new SetupException("A file has to be passed.");
}
this.directorySource = file;
-
}
@Override
- public void setConfiguration(Map<String, ? extends Object> configuration) {
- URL url = (URL) configuration.get("source");
+ public void setConfiguration(
+ final Map<String, ? extends Object> configuration) {
+
+ final URL url = (URL) configuration.get("source");
this.setDirectorySource(new File(url.getFile()));
- Parameters parameters = new Parameters(configuration);
+ final Parameters parameters = new Parameters(configuration);
this.depth = parameters.getAsInteger("depth", 1);
- String dateFormatString = parameters.get("dateFormat", null);
+ final String dateFormatString = parameters.get("dateFormat", null);
if (dateFormatString != null) {
this.dateFormatter = new SimpleDateFormat(dateFormatString);
}
@@ -148,32 +160,32 @@ public class DirectoryGenerator extends
this.reverse = parameters.getAsBoolean("reverse", false);
this.refreshDelay = parameters.getAsLong("refreshDelay", 1L) * 1000L;
- if (this.logger.isDebugEnabled()) {
- this.logger.debug("depth: " + this.depth);
- this.logger.debug("dateFormat: " + this.dateFormatter.toPattern());
- this.logger.debug("sort: " + this.sort);
- this.logger.debug("reverse: " + this.reverse);
- this.logger.debug("refreshDelay: " + this.refreshDelay);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("depth: " + this.depth);
+ LOG.debug("dateFormat: " + this.dateFormatter.toPattern());
+ LOG.debug("sort: " + this.sort);
+ LOG.debug("reverse: " + this.reverse);
+ LOG.debug("refreshDelay: " + this.refreshDelay);
}
String rePattern = null;
try {
rePattern = parameters.get("root", null);
this.rootRE = (rePattern == null) ? null : new RE(rePattern);
- if (this.logger.isDebugEnabled()) {
- this.logger.debug("root pattern: " + rePattern);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("root pattern: " + rePattern);
}
rePattern = parameters.get("include", null);
this.includeRE = (rePattern == null) ? null : new RE(rePattern);
- if (this.logger.isDebugEnabled()) {
- this.logger.debug("include pattern: " + rePattern);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("include pattern: " + rePattern);
}
rePattern = parameters.get("exclude", null);
this.excludeRE = (rePattern == null) ? null : new RE(rePattern);
- if (this.logger.isDebugEnabled()) {
- this.logger.debug("exclude pattern: " + rePattern);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("exclude pattern: " + rePattern);
}
} catch (RESyntaxException rese) {
throw new ProcessingException("Syntax error in regexp pattern '"
@@ -211,7 +223,7 @@ public class DirectoryGenerator extends
this.getSAXConsumer().startDocument();
this.getSAXConsumer().startPrefixMapping(PREFIX, URI);
- Stack<File> ancestors = getAncestors(directorySource);
+ final Stack<File> ancestors = getAncestors(directorySource);
addAncestorPath(directorySource, ancestors);
this.getSAXConsumer().endPrefixMapping(PREFIX);
@@ -230,7 +242,7 @@ public class DirectoryGenerator extends
* the File whose ancestors shall be retrieved
* @return a Stack containing the ancestors.
*/
- protected Stack<File> getAncestors(File path) {
+ protected Stack<File> getAncestors(final File path) {
File parent = path;
Stack<File> ancestors = new Stack<File>();
@@ -250,15 +262,16 @@ public class DirectoryGenerator extends
/**
* Adds recursively the path from the directory matched by the root pattern
* down to the requested directory.
- *
+ *
* @param path
* the requested directory.
* @param ancestors
* the stack of the ancestors.
* @throws SAXException
*/
- protected void addAncestorPath(File path, Stack<File> ancestors)
+ protected void addAncestorPath(final File path, final Stack<File> ancestors)
throws SAXException {
+
if (ancestors.empty()) {
this.isRequestedDirectory = true;
addPath(path, depth);
@@ -281,15 +294,19 @@ public class DirectoryGenerator extends
* @throws SAXException
* if an error occurs while constructing nodes
*/
- protected void addPath(File path, int depth) throws SAXException {
+ protected void addPath(final File path, final int depth)
+ throws SAXException {
+
if (path.isDirectory()) {
startNode(DIR_NODE_NAME, path);
if (depth > 0) {
- File contents[] = path.listFiles();
+ final File[] contents = path.listFiles();
- if (sort.equals("name")) {
+ if ("name".equals(sort)) {
Arrays.sort(contents, new Comparator<Object>() {
- public int compare(Object o1, Object o2) {
+
+ @Override
+ public int compare(final Object o1, final Object o2) {
if (reverse) {
return ((File) o2).getName().compareTo(
((File) o1).getName());
@@ -298,48 +315,59 @@ public class DirectoryGenerator extends
((File) o2).getName());
}
});
- } else if (sort.equals("size")) {
+ } else if ("size".equals(sort)) {
Arrays.sort(contents, new Comparator<Object>() {
- public int compare(Object o1, Object o2) {
+
+ @Override
+ public int compare(final Object o1, final Object o2) {
if (reverse) {
- return new Long(((File) o2).length())
- .compareTo(new Long(((File) o1)
- .length()));
+ return Long.valueOf(((File) o2).length()).
+ compareTo(
+ Long.valueOf(((File) o1).length()));
}
- return new Long(((File) o1).length())
- .compareTo(new Long(((File) o2).length()));
+ return Long.valueOf(((File) o1).length()).
+ compareTo(
+ Long.valueOf(((File) o2).length()));
}
});
- } else if (sort.equals("lastmodified")) {
+ } else if ("lastmodified".equals(sort)) {
Arrays.sort(contents, new Comparator<Object>() {
- public int compare(Object o1, Object o2) {
+
+ @Override
+ public int compare(final Object o1, final Object o2) {
if (reverse) {
- return new Long(((File) o2).lastModified())
- .compareTo(new Long(((File) o1)
- .lastModified()));
+ return Long.valueOf(((File) o2).lastModified()).
+ compareTo(Long.valueOf(
+ ((File) o1).lastModified()));
}
- return new Long(((File) o1).lastModified())
- .compareTo(new Long(((File) o2)
- .lastModified()));
+ return Long.valueOf(((File) o1).lastModified()).
+ compareTo(Long.valueOf(
+ ((File) o2).lastModified()));
}
});
- } else if (sort.equals("directory")) {
+ } else if ("directory".equals(sort)) {
Arrays.sort(contents, new Comparator<Object>() {
- public int compare(Object o1, Object o2) {
- File f1 = (File) o1;
- File f2 = (File) o2;
+
+ @Override
+ public int compare(final Object o1, final Object o2) {
+ final File f1 = (File) o1;
+ final File f2 = (File) o2;
if (reverse) {
- if (f2.isDirectory() && f1.isFile())
+ if (f2.isDirectory() && f1.isFile()) {
return -1;
- if (f2.isFile() && f1.isDirectory())
+ }
+ if (f2.isFile() && f1.isDirectory()) {
return 1;
+ }
return f2.getName().compareTo(f1.getName());
}
- if (f2.isDirectory() && f1.isFile())
+ if (f2.isDirectory() && f1.isFile()) {
return 1;
- if (f2.isFile() && f1.isDirectory())
+ }
+ if (f2.isFile() && f1.isDirectory()) {
return -1;
+ }
return f1.getName().compareTo(f2.getName());
}
});
@@ -362,7 +390,7 @@ public class DirectoryGenerator extends
/**
* Begins a named node and calls setNodeAttributes to set its attributes.
- *
+ *
* @param nodeName
* the name of the new node
* @param path
@@ -370,7 +398,9 @@ public class DirectoryGenerator extends
* @throws SAXException
* if an error occurs while creating the node
*/
- protected void startNode(String nodeName, File path) throws SAXException {
+ protected void startNode(final String nodeName, final File path)
+ throws SAXException {
+
this.validity.add(path);
setNodeAttributes(path);
this.getSAXConsumer().startElement(URI, nodeName,
@@ -381,28 +411,30 @@ public class DirectoryGenerator extends
* Sets the attributes for a given path. The default method sets attributes
* for the name of thefile/directory and for the last modification time of
* the path.
- *
+ *
* @param path
* the file/directory to use when setting attributes
* @throws SAXException
* if an error occurs while setting the attributes
*/
- protected void setNodeAttributes(File path) throws SAXException {
- long lastModified = path.lastModified();
+ protected void setNodeAttributes(final File path)
+ throws SAXException {
+
+ final long lastModified = path.lastModified();
attributes.clear();
attributes.addAttribute("", FILENAME_ATTR_NAME, FILENAME_ATTR_NAME,
- "CDATA", path.getName());
+ CDATA, path.getName());
attributes.addAttribute("", LASTMOD_ATTR_NAME, LASTMOD_ATTR_NAME,
- "CDATA", Long.toString(path.lastModified()));
- attributes.addAttribute("", DATE_ATTR_NAME, DATE_ATTR_NAME, "CDATA",
+ CDATA, Long.toString(path.lastModified()));
+ attributes.addAttribute("", DATE_ATTR_NAME, DATE_ATTR_NAME, CDATA,
dateFormatter.format(new Date(lastModified)));
- attributes.addAttribute("", SIZE_ATTR_NAME, SIZE_ATTR_NAME, "CDATA",
+ attributes.addAttribute("", SIZE_ATTR_NAME, SIZE_ATTR_NAME, CDATA,
Long.toString(path.length()));
if (this.isRequestedDirectory) {
- attributes.addAttribute("", "sort", "sort", "CDATA", this.sort);
- attributes.addAttribute("", "reverse", "reverse", "CDATA",
+ attributes.addAttribute("", "sort", "sort", CDATA, this.sort);
+ attributes.addAttribute("", "reverse", "reverse", CDATA,
String.valueOf(this.reverse));
- attributes.addAttribute("", "requested", "requested", "CDATA",
+ attributes.addAttribute("", "requested", "requested", CDATA,
"true");
this.isRequestedDirectory = false;
}
@@ -416,9 +448,9 @@ public class DirectoryGenerator extends
* @throws SAXException
* if an error occurs while closing the node
*/
- protected void endNode(String nodeName) throws SAXException {
- this.getSAXConsumer()
- .endElement(URI, nodeName, PREFIX + ':' + nodeName);
+ protected void endNode(final String nodeName) throws SAXException {
+ this.getSAXConsumer().endElement(
+ URI, nodeName, PREFIX + ':' + nodeName);
}
/**
@@ -429,7 +461,7 @@ public class DirectoryGenerator extends
* @return true if the File is the root or the root pattern is not set,
* false otherwise.
*/
- protected boolean isRoot(File path) {
+ protected boolean isRoot(final File path) {
return this.rootRE == null || this.rootRE.match(path.getName());
}
@@ -441,7 +473,7 @@ public class DirectoryGenerator extends
* @return true if the File shall be visible or the include Pattern is
* <code>null</code>, false otherwise.
*/
- protected boolean isIncluded(File path) {
+ protected boolean isIncluded(final File path) {
return this.includeRE == null || this.includeRE.match(path.getName());
}
@@ -453,35 +485,31 @@ public class DirectoryGenerator extends
* @return false if the given File shall not be excluded or the exclude
* Pattern is <code>null</code>, true otherwise.
*/
- protected boolean isExcluded(File path) {
+ protected boolean isExcluded(final File path) {
return this.excludeRE != null && this.excludeRE.match(path.getName());
}
- @SuppressWarnings("deprecation")
public CacheKey constructCacheKey() {
if (this.directorySource == null) {
throw new SetupException(this.getClass().getSimpleName()
+ " has no source.");
}
try {
- CompoundCacheKey key = new CompoundCacheKey();
+ final CompoundCacheKey key = new CompoundCacheKey();
TimestampCacheKey timestampCacheKey = new TimestampCacheKey(
- this.directorySource.toURL(),
+ this.directorySource.toURI().toURL(),
directorySource.lastModified());
key.addCacheKey(timestampCacheKey);
for (File file : validity) {
timestampCacheKey = new TimestampCacheKey(
- file.toURL(),
- file.lastModified());
+ file.toURI().toURL(), file.lastModified());
key.addCacheKey(timestampCacheKey);
}
return key;
} catch (Exception e) {
- this.logger.error(
- "Can't construct cache key. Error while connecting to "
- + this.directorySource, e);
+ LOG.error("Can't construct cache key. Error while connecting to "
+ + this.directorySource, e);
}
return null;
}
-
}
Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CompleteCacheValue.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CompleteCacheValue.java?rev=1142238&r1=1142237&r2=1142238&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CompleteCacheValue.java (original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/caching/CompleteCacheValue.java Sat Jul 2 15:47:58 2011
@@ -30,13 +30,15 @@ import org.apache.commons.logging.LogFac
public class CompleteCacheValue extends AbstractCacheValue {
private static final long serialVersionUID = 1L;
- private final Log logger = LogFactory.getLog(this.getClass());
+
+ private static final Log LOG = LogFactory.getLog(CompleteCacheValue.class);
+
private byte[] content;
- public CompleteCacheValue(byte[] content, CacheKey cacheKey) {
+ public CompleteCacheValue(final byte[] content, final CacheKey cacheKey) {
super(cacheKey);
- this.content = content;
+ this.content = content.clone();
}
/**
@@ -44,8 +46,9 @@ public class CompleteCacheValue extends
*
* @see org.apache.cocoon.pipeline.caching.CacheValue#getValue()
*/
+ @Override
public Object getValue() {
- return this.content;
+ return this.content.clone();
}
/**
@@ -53,18 +56,23 @@ public class CompleteCacheValue extends
*
* @see org.apache.cocoon.pipeline.caching.CacheValue#setValue()
*/
- public void setValue(Object value) {
+ @Override
+ public void setValue(final Object value) {
if (value instanceof String) {
this.content = ((String) value).getBytes();
- } else { // or maybe we should throw exception instead of serializing object ?
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ } else {
+ // or maybe we should throw exception instead of
+ // serializing object ?
+ final ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
try {
- ObjectOutputStream objectOut = new ObjectOutputStream(byteOut);
+ final ObjectOutputStream objectOut =
+ new ObjectOutputStream(byteOut);
objectOut.writeObject(value);
objectOut.flush();
objectOut.close();
} catch (IOException e) {
- this.logger.error("Some thing goes wrong during calculating setting value of: " + getCacheKey(), e);
+ LOG.error("Some thing goes wrong during calculating "
+ + "setting value of: " + getCacheKey(), e);
return;
}
this.content = byteOut.toByteArray();
@@ -73,7 +81,9 @@ public class CompleteCacheValue extends
@Override
public String toString() {
- return StringRepresentation.buildString(this, "content.length=" + this.content.length, "cacheKey=" + this.getCacheKey());
+ return StringRepresentation.buildString(this,
+ "content.length=" + this.content.length,
+ "cacheKey=" + this.getCacheKey());
}
/**
@@ -88,10 +98,11 @@ public class CompleteCacheValue extends
/**
* {@inheritDoc}
*
- * @see org.apache.cocoon.pipeline.caching.CacheValue#writeTo(java.io.OutputStream)
+ * @see org.apache.cocoon.pipeline.caching.CacheValue
+ * #writeTo(java.io.OutputStream)
*/
- public void writeTo(OutputStream outputStream) throws IOException {
+ @Override
+ public void writeTo(final OutputStream outputStream) throws IOException {
outputStream.write(this.content);
}
-
}
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=1142238&r1=1142237&r2=1142238&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 Sat Jul 2 15:47:58 2011
@@ -28,7 +28,9 @@ import org.apache.cocoon.pipeline.util.S
public class TimestampCacheKey extends AbstractCacheKey {
private static final long serialVersionUID = 1L;
+
private final long timestamp;
+
private final URL url;
public TimestampCacheKey(URL url, long timestamp) {
@@ -45,7 +47,7 @@ public class TimestampCacheKey extends A
}
TimestampCacheKey other = (TimestampCacheKey) obj;
- return this.url.equals(other.url);
+ return this.url.toExternalForm().equals(other.url.toExternalForm());
}
public long getTimestamp() {
@@ -58,7 +60,8 @@ public class TimestampCacheKey extends A
@Override
public int hashCode() {
- return new MurmurHashCodeBuilder().append(this.url.toExternalForm()).append(this.timestamp).toHashCode();
+ return new MurmurHashCodeBuilder().append(this.url.toExternalForm()).
+ append(this.timestamp).toHashCode();
}
public boolean isValid(CacheKey cacheKey) {
@@ -72,8 +75,10 @@ public class TimestampCacheKey extends A
@Override
public String toString() {
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
- return StringRepresentation.buildString(this, "url=" + this.url, "timestamp=" + this.timestamp + " ("
+ 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-sax/src/main/java/org/apache/cocoon/sax/component/SchemaErrorHandler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SchemaErrorHandler.java?rev=1142238&r1=1142237&r2=1142238&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SchemaErrorHandler.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/SchemaErrorHandler.java Sat Jul 2 15:47:58 2011
@@ -34,15 +34,20 @@ public final class SchemaErrorHandler im
this.schemaUri = schemaUri;
}
+ @Override
public void error(final SAXParseException ex) throws SAXException {
- throw new SchemaValidationException("Validation with schema " + this.schemaUri + " failed with error", ex);
+ throw new SchemaValidationException("Validation with schema "
+ + this.schemaUri + " failed with error", ex);
}
- public void fatalError(SAXParseException ex) throws SAXException {
- throw new SchemaValidationException("Validation with schema " + this.schemaUri + " failed with fatal error", ex);
+ @Override
+ public void fatalError(final SAXParseException ex) throws SAXException {
+ throw new SchemaValidationException("Validation with schema "
+ + this.schemaUri + " failed with fatal error", ex);
}
- public void warning(SAXParseException ex) throws SAXException {
+ @Override
+ public void warning(final SAXParseException ex) throws SAXException {
if (this.logger.isWarnEnabled()) {
this.logger.warn(ex.getMessage() + " at " + this.schemaUri);
}
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=1142238&r1=1142237&r2=1142238&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 Sat Jul 2 15:47:58 2011
@@ -78,7 +78,7 @@ public final class SchemaProcessorTransf
@Override
protected void setSAXConsumer(SAXConsumer xmlConsumer) {
ValidatorHandler validatorHandler = this.schema.newValidatorHandler();
- validatorHandler.setErrorHandler(new SchemaErrorHandler(this.LOG,
+ validatorHandler.setErrorHandler(new SchemaErrorHandler(LOG,
this.source.toExternalForm()));
validatorHandler.setContentHandler(xmlConsumer);
@@ -105,10 +105,11 @@ public final class SchemaProcessorTransf
}
this.schema = null;
- if (SCHEMA_LRU_CACHE.containsKey(source)) {
- ValidityValue<Schema> cacheEntry = SCHEMA_LRU_CACHE.get(source);
- if (schemaFile == null
- || cacheEntry.getLastModified() >= schemaFile.lastModified()) {
+ if (SCHEMA_LRU_CACHE.containsKey(source.toExternalForm())) {
+ ValidityValue<Schema> cacheEntry =
+ SCHEMA_LRU_CACHE.get(source.toExternalForm());
+ if (schemaFile == null || cacheEntry.getLastModified()
+ >= schemaFile.lastModified()) {
this.schema = cacheEntry.getValue();
}
@@ -123,7 +124,7 @@ public final class SchemaProcessorTransf
? new ValidityValue<Schema>(this.schema,
schemaFile.lastModified())
: new ValidityValue<Schema>(this.schema);
- SCHEMA_LRU_CACHE.put(source, cacheEntry);
+ SCHEMA_LRU_CACHE.put(source.toExternalForm(), cacheEntry);
} catch (SAXException e) {
throw new SetupException(
"Could not initialize xschema source", e);
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=1142238&r1=1142237&r2=1142238&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 Sat Jul 2 15:47:58 2011
@@ -26,9 +26,10 @@ import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
+import java.util.Arrays;
import java.util.Map;
-
import org.apache.cocoon.pipeline.PipelineException;
+
import org.apache.cocoon.pipeline.ProcessingException;
import org.apache.cocoon.pipeline.SetupException;
import org.apache.cocoon.pipeline.caching.CacheKey;
@@ -48,47 +49,57 @@ import org.w3c.dom.Node;
import org.xml.sax.SAXException;
/**
- * General purpose SAX generator that produces SAX events from different sources.
+ * General purpose SAX generator that produces SAX events from
+ * different sources.
*/
-public class XMLGenerator extends AbstractSAXGenerator implements CachingPipelineComponent {
+public class XMLGenerator extends AbstractSAXGenerator
+ implements CachingPipelineComponent {
- private Starter generator;
+ private final static Log LOG = LogFactory.getLog(XMLGenerator.class);
- private final Log logger = LogFactory.getLog(this.getClass());
+ private transient Starter generator;
public XMLGenerator() {
this((URL) null);
}
- public XMLGenerator(byte[] bytes) {
+ public XMLGenerator(final byte[] bytes) {
+ super();
this.generator = new ByteArrayGenerator(bytes);
}
- public XMLGenerator(byte[] bytes, String encoding) {
+ public XMLGenerator(final byte[] bytes, final String encoding) {
+ super();
this.generator = new ByteArrayGenerator(bytes, encoding);
}
- public XMLGenerator(File file) {
+ public XMLGenerator(final File file) {
+ super();
this.generator = new FileGenerator(file);
}
- public XMLGenerator(InputStream inputStream) {
+ public XMLGenerator(final InputStream inputStream) {
+ super();
this.generator = new InputStreamGenerator(inputStream);
}
- public XMLGenerator(Node node) {
+ public XMLGenerator(final Node node) {
+ super();
this.generator = new NodeGenerator(node);
}
- public XMLGenerator(SAXBuffer saxBuffer) {
+ public XMLGenerator(final SAXBuffer saxBuffer) {
+ super();
this.generator = new SAXBufferGenerator(saxBuffer);
}
- public XMLGenerator(String xmlString) {
+ public XMLGenerator(final String xmlString) {
+ super();
this.generator = new StringGenerator(xmlString);
}
- public XMLGenerator(URL url) {
+ public XMLGenerator(final URL url) {
+ super();
this.generator = new URLGenerator(url);
}
@@ -110,64 +121,78 @@ public class XMLGenerator extends Abstra
* @see org.apache.cocoon.sax.AbstractSAXProducer#setConfiguration(java.util.Map)
*/
@Override
- public void setConfiguration(Map<String, ? extends Object> configuration) {
- ((URLGenerator) this.generator).setSource((URL) configuration.get("source"));
+ public void setConfiguration(
+ final Map<String, ? extends Object> configuration) {
+ ((URLGenerator) this.generator).setSource(
+ (URL) configuration.get("source"));
}
@Override
public String toString() {
- return StringRepresentation.buildString(this, "internalGenerator=" + this.generator);
+ return StringRepresentation.buildString(this,
+ "internalGenerator=" + this.generator);
}
private class ByteArrayGenerator extends AbstractSAXGenerator {
- private final byte[] bytes;
- private final String encoding;
+ private final transient byte[] bytes;
+
+ private final transient String encoding;
- public ByteArrayGenerator(byte[] bytes) {
+ public ByteArrayGenerator(final byte[] bytes) {
this(bytes, null);
}
- public ByteArrayGenerator(byte[] bytes, String encoding) {
+ public ByteArrayGenerator(final byte[] bytes, final String encoding) {
+ super();
if (bytes == null) {
throw new SetupException("A byte array has to be passed.");
}
- this.bytes = bytes;
+ this.bytes = bytes.clone();
this.encoding = encoding;
}
public void execute() {
try {
- if (XMLGenerator.this.logger.isDebugEnabled()) {
- XMLGenerator.this.logger.debug("Using a byte array as source to produce SAX events.");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using a byte array as "
+ + "source to produce SAX events.");
}
if (this.encoding == null) {
- XMLUtils.toSax(new ByteArrayInputStream(this.bytes), XMLGenerator.this.getSAXConsumer());
+ XMLUtils.toSax(new ByteArrayInputStream(this.bytes),
+ XMLGenerator.this.getSAXConsumer());
} else {
- XMLUtils.toSax(new String(this.bytes, this.encoding), XMLGenerator.this.getSAXConsumer());
+ XMLUtils.toSax(new String(this.bytes, this.encoding),
+ XMLGenerator.this.getSAXConsumer());
}
} catch (PipelineException e) {
+ LOG.error("Pipeline expcetion thrown", e);
throw e;
} catch (UnsupportedEncodingException e) {
- throw new ProcessingException("The encoding " + this.encoding + " is not supported.", e);
+ throw new ProcessingException("The encoding " + this.encoding
+ + " is not supported.", e);
} catch (Exception e) {
- throw new ProcessingException("Can't parse byte array " + this.bytes, e);
+ throw new ProcessingException("Can't parse byte array "
+ + Arrays.toString(this.bytes), e);
}
}
@Override
public String toString() {
- return StringRepresentation.buildString(this, "bytes=" + this.bytes, "encoding=" + this.encoding);
+ return StringRepresentation.buildString(this,
+ "bytes=" + Arrays.toString(this.bytes),
+ "encoding=" + this.encoding);
}
}
private class FileGenerator extends AbstractSAXGenerator {
- private final File file;
+ private final transient File file;
- public FileGenerator(File file) {
+ public FileGenerator(final File file) {
+ super();
if (file == null) {
throw new SetupException("A file has to be passed.");
}
@@ -177,16 +202,19 @@ public class XMLGenerator extends Abstra
public void execute() {
try {
- if (XMLGenerator.this.logger.isDebugEnabled()) {
- XMLGenerator.this.logger.debug("Using file " + this.file.getAbsolutePath()
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using file " + this.file.getAbsolutePath()
+ " as source to produce SAX events.");
}
- XMLUtils.toSax(new FileInputStream(this.file), XMLGenerator.this.getSAXConsumer());
+ XMLUtils.toSax(new FileInputStream(this.file),
+ XMLGenerator.this.getSAXConsumer());
} catch (PipelineException e) {
+ LOG.error("Pipeline expcetion thrown", e);
throw e;
} catch (Exception e) {
- throw new ProcessingException("Can't read or parse file " + this.file.getAbsolutePath(), e);
+ throw new ProcessingException("Can't read or parse file "
+ + this.file.getAbsolutePath(), e);
}
}
@@ -198,11 +226,10 @@ public class XMLGenerator extends Abstra
private class InputStreamGenerator extends AbstractSAXGenerator {
- private final InputStream inputStream;
+ private final transient InputStream inputStream;
- public InputStreamGenerator(InputStream inputStream) {
+ public InputStreamGenerator(final InputStream inputStream) {
super();
-
if (inputStream == null) {
throw new SetupException("An input stream has to be passed.");
}
@@ -212,31 +239,35 @@ public class XMLGenerator extends Abstra
public void execute() {
try {
- if (XMLGenerator.this.logger.isDebugEnabled()) {
- XMLGenerator.this.logger.debug("Using input stream " + this.inputStream
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using input stream " + this.inputStream
+ " as source to produce SAX events.");
}
- XMLUtils.toSax(this.inputStream, XMLGenerator.this.getSAXConsumer());
+ XMLUtils.toSax(this.inputStream,
+ XMLGenerator.this.getSAXConsumer());
} catch (PipelineException e) {
+ LOG.error("Pipeline expcetion thrown", e);
throw e;
-
} catch (Exception e) {
- throw new ProcessingException("Can't read or parse file " + this.inputStream, e);
+ throw new ProcessingException("Can't read or parse file "
+ + this.inputStream, e);
}
}
@Override
public String toString() {
- return StringRepresentation.buildString(this, "inputStream=" + this.inputStream);
+ return StringRepresentation.buildString(this, "inputStream="
+ + this.inputStream);
}
}
private class NodeGenerator extends AbstractSAXGenerator {
- private final Node node;
+ private final transient Node node;
- public NodeGenerator(Node document) {
+ public NodeGenerator(final Node document) {
+ super();
if (document == null) {
throw new SetupException("A DOM document has to be passed.");
}
@@ -245,15 +276,18 @@ public class XMLGenerator extends Abstra
}
public void execute() {
- if (XMLGenerator.this.logger.isDebugEnabled()) {
- XMLGenerator.this.logger.debug("Using a DOM node to produce SAX events.");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using a DOM node to produce "
+ + "SAX events.");
}
- DOMStreamer streamer = new DOMStreamer(XMLGenerator.this.getSAXConsumer());
+ final DOMStreamer streamer = new DOMStreamer(
+ XMLGenerator.this.getSAXConsumer());
try {
streamer.stream(this.node);
} catch (SAXException e) {
- throw new SetupException("Can't stream DOM node + " + this.node);
+ throw new SetupException("Can't stream DOM node + "
+ + this.node, e);
}
}
@@ -265,11 +299,10 @@ public class XMLGenerator extends Abstra
private class SAXBufferGenerator extends AbstractSAXGenerator {
- private final SAXBuffer saxBuffer;
+ private final transient SAXBuffer saxBuffer;
- public SAXBufferGenerator(SAXBuffer saxBuffer) {
+ public SAXBufferGenerator(final SAXBuffer saxBuffer) {
super();
-
if (saxBuffer == null) {
throw new SetupException("A SAXBuffer has to be passed.");
}
@@ -278,28 +311,32 @@ public class XMLGenerator extends Abstra
}
public void execute() {
- if (XMLGenerator.this.logger.isDebugEnabled()) {
- XMLGenerator.this.logger.debug("Using a SAXBuffer to produce SAX events.");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using a SAXBuffer to produce "
+ + "SAX events.");
}
try {
this.saxBuffer.toSAX(XMLGenerator.this.getSAXConsumer());
} catch (SAXException e) {
- throw new ProcessingException("Can't stream " + this + " into the content handler.", e);
+ throw new ProcessingException("Can't stream " + this
+ + " into the content handler.", e);
}
}
@Override
public String toString() {
- return StringRepresentation.buildString(this, "saxBuffer=" + this.saxBuffer);
+ return StringRepresentation.buildString(this,
+ "saxBuffer=" + this.saxBuffer);
}
}
- private class StringGenerator extends AbstractSAXProducer implements Starter {
+ private class StringGenerator extends AbstractSAXProducer
+ implements Starter {
- private String xmlString;
+ private final transient String xmlString;
- public StringGenerator(String xmlString) {
+ public StringGenerator(final String xmlString) {
super();
if (xmlString == null) {
throw new SetupException("An XML string has to be passed.");
@@ -315,12 +352,15 @@ public class XMLGenerator extends Abstra
*/
public void execute() {
try {
- if (XMLGenerator.this.logger.isDebugEnabled()) {
- XMLGenerator.this.logger.debug("Using a string to produce SAX events.");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using a string to produce SAX events.");
}
- XMLUtils.toSax(new ByteArrayInputStream(this.xmlString.getBytes()), XMLGenerator.this.getSAXConsumer());
+ XMLUtils.toSax(new ByteArrayInputStream(
+ this.xmlString.getBytes()),
+ XMLGenerator.this.getSAXConsumer());
} catch (PipelineException e) {
+ LOG.error("Pipeline exception thrown", e);
throw e;
} catch (Exception e) {
throw new ProcessingException("Can't parse the XML string.", e);
@@ -329,15 +369,17 @@ public class XMLGenerator extends Abstra
@Override
public String toString() {
- return StringRepresentation.buildString(this, "xmlString=" + this.xmlString);
+ return StringRepresentation.buildString(this,
+ "xmlString=" + this.xmlString);
}
}
- private class URLGenerator extends AbstractSAXGenerator implements CachingPipelineComponent {
+ private class URLGenerator extends AbstractSAXGenerator
+ implements CachingPipelineComponent {
- private URL source;
+ private transient URL source;
- public URLGenerator(URL source) {
+ public URLGenerator(final URL source) {
super();
this.source = source;
}
@@ -345,23 +387,29 @@ public class XMLGenerator extends Abstra
/**
* {@inheritDoc}
*
- * @see org.apache.cocoon.pipeline.component.CachingPipelineComponent#constructCacheKey()
+ * @see org.apache.cocoon.pipeline.component.CachingPipelineComponent
+ * #constructCacheKey()
*/
public CacheKey constructCacheKey() {
if (this.source == null) {
- throw new SetupException(this.getClass().getSimpleName() + " has no source.");
+ throw new SetupException(this.getClass().getSimpleName()
+ + " has no source.");
}
URLConnection connection = null;
try {
connection = this.source.openConnection();
- TimestampCacheKey timestampCacheKey = new TimestampCacheKey(this.source, connection.getLastModified());
+ final TimestampCacheKey timestampCacheKey =
+ new TimestampCacheKey(this.source,
+ connection.getLastModified());
return timestampCacheKey;
} catch (IOException e) {
- XMLGenerator.this.logger
- .error("Can't construct cache key. Error while connecting to " + this.source, e);
+ LOG.error("Can't construct cache key. "
+ + "Error while connecting to " + this.source, e);
} finally {
- URLConnectionUtils.closeQuietly(connection);
+ if (connection != null) {
+ URLConnectionUtils.closeQuietly(connection);
+ }
}
return null;
@@ -374,27 +422,32 @@ public class XMLGenerator extends Abstra
*/
public void execute() {
if (this.source == null) {
- throw new ProcessingException(this.getClass().getSimpleName() + " has no source.");
+ throw new ProcessingException(this.getClass().getSimpleName()
+ + " has no source.");
}
- if (XMLGenerator.this.logger.isDebugEnabled()) {
- XMLGenerator.this.logger.debug("Using the URL " + this.source + " to produce SAX events.");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using the URL " + this.source
+ + " to produce SAX events.");
}
try {
- XMLUtils.toSax(this.source.openConnection(), XMLGenerator.this.getSAXConsumer());
+ XMLUtils.toSax(this.source.openConnection(),
+ XMLGenerator.this.getSAXConsumer());
} catch (IOException e) {
- throw new ProcessingException("Can't open connection to " + this.source, e);
+ throw new ProcessingException("Can't open connection to "
+ + this.source, e);
}
}
- public void setSource(URL source) {
+ public void setSource(final URL source) {
this.source = source;
}
@Override
public String toString() {
- return StringRepresentation.buildString(this, "source=" + this.source);
+ return StringRepresentation.buildString(this,
+ "source=" + 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=1142238&r1=1142237&r2=1142238&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 Sat Jul 2 15:47:58 2011
@@ -148,11 +148,12 @@ public class XSLTTransformer extends Abs
this.templates = null;
// check the XSLT is in the cache first
- if (XSLT_CACHE.containsKey(source)) {
+ if (XSLT_CACHE.containsKey(this.source.toExternalForm())) {
// get the XSLT directly from the cache
- ValidityValue<Templates> cacheEntry = XSLT_CACHE.get(this.source);
- if (xsltFile == null
- || cacheEntry.getLastModified() >= xsltFile.lastModified()) {
+ ValidityValue<Templates> cacheEntry =
+ XSLT_CACHE.get(this.source.toExternalForm());
+ if (xsltFile == null || cacheEntry.getLastModified()
+ >= xsltFile.lastModified()) {
this.templates = cacheEntry.getValue();
}
@@ -181,7 +182,7 @@ public class XSLTTransformer extends Abs
? new ValidityValue<Templates>(this.templates,
xsltFile.lastModified())
: new ValidityValue<Templates>(this.templates);
- XSLT_CACHE.put(this.source, cacheEntry);
+ XSLT_CACHE.put(this.source.toExternalForm(), cacheEntry);
} catch (TransformerConfigurationException e) {
throw new SetupException("Impossible to read XSLT from '"
+ this.source.toExternalForm()
Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/InMemoryLRUResourceCache.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/InMemoryLRUResourceCache.java?rev=1142238&r1=1142237&r2=1142238&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/InMemoryLRUResourceCache.java (original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/util/InMemoryLRUResourceCache.java Sat Jul 2 15:47:58 2011
@@ -17,7 +17,6 @@
package org.apache.cocoon.sax.util;
import java.io.Serializable;
-import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -42,8 +41,8 @@ public final class InMemoryLRUResourceCa
/**
* The map that implements the LRU cache.
*/
- private final Map<URL, ValidityValue<V>> data =
- new LinkedHashMap<URL, ValidityValue<V>>(
+ private final Map<String, ValidityValue<V>> data =
+ new LinkedHashMap<String, ValidityValue<V>>(
CACHE_CAPACITY, LOAD_FACTOR) {
/**
@@ -51,7 +50,7 @@ public final class InMemoryLRUResourceCa
*/
@Override
protected boolean removeEldestEntry(
- final Map.Entry<URL, ValidityValue<V>> eldest) {
+ final Map.Entry<String, ValidityValue<V>> eldest) {
return size() > CACHE_SIZE;
}
@@ -64,7 +63,7 @@ public final class InMemoryLRUResourceCa
* @return true if this map contains a mapping for the specified key, false
* otherwise.
*/
- public boolean containsKey(final URL key) {
+ public boolean containsKey(final String key) {
checkKey(key);
return this.data.containsKey(key);
}
@@ -79,7 +78,7 @@ public final class InMemoryLRUResourceCa
* @return the value to which the specified key is cached, null if this
* cache contains no mapping for the key.
*/
- public ValidityValue<V> get(final URL key) {
+ public ValidityValue<V> get(final String key) {
checkKey(key);
return this.data.get(key);
}
@@ -92,7 +91,7 @@ public final class InMemoryLRUResourceCa
* @param key key with which the specified value is to be associated.
* @param value value to be associated with the specified key.
*/
- public void put(final URL key, final ValidityValue<V> value) {
+ public void put(final String key, final ValidityValue<V> value) {
checkKey(key);
this.data.put(key, value);
}
@@ -102,7 +101,7 @@ public final class InMemoryLRUResourceCa
*
* @param key the key object.
*/
- private static void checkKey(final URL key) {
+ private static void checkKey(final String key) {
if (key == null) {
throw new IllegalArgumentException("null keys not supported");
}