Author: reinhard
Date: Wed Jan 4 08:20:18 2012
New Revision: 1227070
URL: http://svn.apache.org/viewvc?rev=1227070&view=rev
Log:
commenting the variable "LOG" of type Logger as "Logger" is superfluous
fix all "Missing @Override" warnings
80 characters per line isn't necessary in 2012 anymore
adding some line breaks to increase the readability of some methods
Modified:
cocoon/cocoon3/trunk/cocoon-optional/src/main/java/org/apache/cocoon/optional/pipeline/components/sax/directory/DirectoryGenerator.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=1227070&r1=1227069&r2=1227070&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 Wed Jan 4 08:20:18 2012
@@ -44,11 +44,7 @@ import org.xml.sax.helpers.AttributesImp
public class DirectoryGenerator extends AbstractSAXGenerator implements CachingPipelineComponent {
- /**
- * Logger.
- */
- private static final Logger LOG =
- LoggerFactory.getLogger(DirectoryGenerator.class);
+ private static final Logger LOG = LoggerFactory.getLogger(DirectoryGenerator.class);
private static final String CDATA = "CDATA";
@@ -85,9 +81,9 @@ public class DirectoryGenerator extends
/**
* The dateFormatter determines into which date format the lastModified time
- * should be converted. FIXME: SimpleDateFormat is not supported by all
- * locales!
+ * should be converted.
*/
+ // FIXME: SimpleDateFormat is not supported by all locales!
protected SimpleDateFormat dateFormatter = new SimpleDateFormat();
/** The delay between checks on updates to the filesystem. */
@@ -137,18 +133,19 @@ public class DirectoryGenerator extends
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(
- final Map<String, ? extends Object> configuration) {
-
+ public void setConfiguration(final Map<String, ? extends Object> configuration) {
final URL url = (URL) configuration.get("source");
this.setDirectorySource(new File(url.getFile()));
+
final Parameters parameters = new Parameters(configuration);
this.depth = parameters.getAsInteger("depth", 1);
@@ -197,26 +194,27 @@ public class DirectoryGenerator extends
/**
* Gets the source validity, using a deferred validity object. The validity is initially empty since the files that
- * define it are not known before generation has occured. So the returned object is kept by the generator and filled
- * with each of the files that are traversed.
- *
+ * define it are not known before generation has occurred. So the returned object is kept by the generator and filled
+ * with each of the files that is traversed.
+ *
* @see DirectoryGenerator.DirValidity
- *
+ *
* public SourceValidity getValidity() { if (this.validity == null) { this.validity = new
* DirValidity(this.refreshDelay); } return this.validity; }/
- *
+ *
* /** Generate XML data.
- *
+ *
* @throws SAXException if an error occurs while outputting the document
- * @throws ProcessingException if the requsted URI isn't a directory on the local filesystem
+ * @throws ProcessingException if the requested URI isn't a directory on the local filesystem
*/
+ @Override
public void execute() throws ProcessingException {
+ // This relies on systemId being of the form "file://..."
+ if (!this.directorySource.isDirectory()) {
+ throw new ProcessingException(this.directorySource + " is not a directory.");
+ }
+
try {
- // This relies on systemId being of the form "file://..."
- if (!this.directorySource.isDirectory()) {
- throw new ProcessingException(this.directorySource
- + " is not a directory.");
- }
this.getSAXConsumer().startDocument();
this.getSAXConsumer().startPrefixMapping(PREFIX, URI);
@@ -227,14 +225,13 @@ public class DirectoryGenerator extends
this.getSAXConsumer().endPrefixMapping(PREFIX);
this.getSAXConsumer().endDocument();
} catch (Exception ioe) {
- throw new ProcessingException("Could not read directory "
- + this.directorySource, ioe);
+ throw new ProcessingException("Could not read directory " + this.directorySource, ioe);
}
}
/**
* Creates a stack containing the ancestors of File up to specified directory.
- *
+ *
* @param path the File whose ancestors shall be retrieved
* @return a Stack containing the ancestors.
*/
@@ -265,9 +262,7 @@ public class DirectoryGenerator extends
* the stack of the ancestors.
* @throws SAXException
*/
- protected void addAncestorPath(final File path, final Stack<File> ancestors)
- throws SAXException {
-
+ protected void addAncestorPath(final File path, final Stack<File> ancestors) throws SAXException {
if (ancestors.empty()) {
this.isRequestedDirectory = true;
this.addPath(path, this.depth);
@@ -281,62 +276,54 @@ public class DirectoryGenerator extends
/**
* Adds a single node to the generated document. If the path is a directory, and depth is greater than zero, then
* recursive calls are made to add nodes for the directory's children.
- *
+ *
* @param path the file/directory to process
- * @param depth how deep to scan the directory
+ * @param scanDepth how deep to scan the directory
* @throws SAXException if an error occurs while constructing nodes
*/
- protected void addPath(final File path, final int depth)
- throws SAXException {
-
+ protected void addPath(final File path, final int scanDepth) throws SAXException {
if (path.isDirectory()) {
this.startNode(DIR_NODE_NAME, path);
- if (depth > 0) {
+ if (scanDepth > 0) {
final File[] contents = path.listFiles();
if ("name".equals(this.sort)) {
Arrays.sort(contents, new Comparator<Object>() {
+ @Override
public int compare(final Object o1, final Object o2) {
if (DirectoryGenerator.this.reverse) {
- return ((File) o2).getName().compareTo(
- ((File) o1).getName());
+ return ((File) o2).getName().compareTo(((File) o1).getName());
}
- return ((File) o1).getName().compareTo(
- ((File) o2).getName());
+ return ((File) o1).getName().compareTo(((File) o2).getName());
}
});
} else if ("size".equals(this.sort)) {
Arrays.sort(contents, new Comparator<Object>() {
+ @Override
public int compare(final Object o1, final Object o2) {
if (DirectoryGenerator.this.reverse) {
- return Long.valueOf(((File) o2).length()).
- compareTo(
- Long.valueOf(((File) o1).length()));
+ return Long.valueOf(((File) o2).length()).compareTo(Long.valueOf(((File) o1).length()));
}
- return Long.valueOf(((File) o1).length()).
- compareTo(
- Long.valueOf(((File) o2).length()));
+ return Long.valueOf(((File) o1).length()).compareTo(Long.valueOf(((File) o2).length()));
}
});
} else if ("lastmodified".equals(this.sort)) {
Arrays.sort(contents, new Comparator<Object>() {
+ @Override
public int compare(final Object o1, final Object o2) {
if (DirectoryGenerator.this.reverse) {
- return Long.valueOf(((File) o2).lastModified()).
- compareTo(Long.valueOf(
- ((File) o1).lastModified()));
+ return Long.valueOf(((File) o2).lastModified()).compareTo(Long.valueOf(((File) o1).lastModified()));
}
- return Long.valueOf(((File) o1).lastModified()).
- compareTo(Long.valueOf(
- ((File) o2).lastModified()));
+ return Long.valueOf(((File) o1).lastModified()).compareTo(Long.valueOf(((File) o2).lastModified()));
}
});
} else if ("directory".equals(this.sort)) {
Arrays.sort(contents, new Comparator<Object>() {
+ @Override
public int compare(final Object o1, final Object o2) {
final File f1 = (File) o1;
final File f2 = (File) o2;
@@ -363,7 +350,7 @@ public class DirectoryGenerator extends
for (int i = 0; i < contents.length; i++) {
if (this.isIncluded(contents[i]) && !this.isExcluded(contents[i])) {
- this.addPath(contents[i], depth - 1);
+ this.addPath(contents[i], scanDepth - 1);
}
}
}
@@ -386,13 +373,10 @@ public class DirectoryGenerator extends
* @throws SAXException
* if an error occurs while creating the node
*/
- protected void startNode(final String nodeName, final File path)
- throws SAXException {
-
+ protected void startNode(final String nodeName, final File path) throws SAXException {
this.validity.add(path);
this.setNodeAttributes(path);
- this.getSAXConsumer().startElement(URI, nodeName,
- PREFIX + ':' + nodeName, this.attributes);
+ this.getSAXConsumer().startElement(URI, nodeName, PREFIX + ':' + nodeName, this.attributes);
}
/**
@@ -405,9 +389,7 @@ public class DirectoryGenerator extends
* @throws SAXException
* if an error occurs while setting the attributes
*/
- protected void setNodeAttributes(final File path)
- throws SAXException {
-
+ protected void setNodeAttributes(final File path) throws SAXException {
final long lastModified = path.lastModified();
this.attributes.clear();
this.attributes.addAttribute("", FILENAME_ATTR_NAME, FILENAME_ATTR_NAME,
@@ -430,7 +412,7 @@ public class DirectoryGenerator extends
/**
* Ends the named node.
- *
+ *
* @param nodeName the name of the new node
* @throws SAXException if an error occurs while closing the node
*/
@@ -441,7 +423,7 @@ public class DirectoryGenerator extends
/**
* Determines if a given File is the defined root.
- *
+ *
* @param path the File to check
* @return true if the File is the root or the root pattern is not set, false otherwise.
*/
@@ -451,7 +433,7 @@ public class DirectoryGenerator extends
/**
* Determines if a given File shall be visible.
- *
+ *
* @param path the File to check
* @return true if the File shall be visible or the include Pattern is <code>null</code>, false otherwise.
*/
@@ -461,7 +443,7 @@ public class DirectoryGenerator extends
/**
* Determines if a given File shall be excluded from viewing.
- *
+ *
* @param path the File to check
* @return false if the given File shall not be excluded or the exclude Pattern is <code>null</code>, true
* otherwise.
@@ -470,27 +452,31 @@ public class DirectoryGenerator extends
return this.excludeRE != null && this.excludeRE.match(path.getName());
}
+ @Override
public CacheKey constructCacheKey() {
if (this.directorySource == null) {
- throw new SetupException(this.getClass().getSimpleName()
- + " has no source.");
+ throw new SetupException(this.getClass().getSimpleName() + " has no source.");
}
+
try {
final CompoundCacheKey key = new CompoundCacheKey();
TimestampCacheKey timestampCacheKey = new TimestampCacheKey(
this.directorySource.toURI().toURL(),
this.directorySource.lastModified());
key.addCacheKey(timestampCacheKey);
+
for (File file : this.validity) {
timestampCacheKey = new TimestampCacheKey(
file.toURI().toURL(), file.lastModified());
key.addCacheKey(timestampCacheKey);
}
+
return key;
} catch (Exception e) {
LOG.error("Can't construct cache key. Error while connecting to "
+ this.directorySource, e);
}
+
return null;
}
}
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.