org.apache.cocoon.optional.pipeline.components.sax.directory
Class DirectoryGenerator

java.lang.Object
  extended by org.apache.cocoon.pipeline.component.AbstractPipelineComponent
      extended by org.apache.cocoon.sax.AbstractSAXPipelineComponent
          extended by org.apache.cocoon.sax.AbstractSAXProducer
              extended by org.apache.cocoon.sax.AbstractSAXGenerator
                  extended by org.apache.cocoon.optional.pipeline.components.sax.directory.DirectoryGenerator
All Implemented Interfaces:
CachingPipelineComponent, PipelineComponent, Producer, Starter, SAXPipelineComponent, SAXProducer

public class DirectoryGenerator
extends AbstractSAXGenerator
implements CachingPipelineComponent


Field Summary
protected  org.xml.sax.helpers.AttributesImpl attributes
          Convenience object, so we don't need to create an AttributesImpl for every element.
protected static String DATE_ATTR_NAME
           
protected  SimpleDateFormat dateFormatter
          The dateFormatter determines into which date format the lastModified time should be converted.
protected  int depth
          The depth parameter determines how deep the DirectoryGenerator should delve.
protected static String DIR_NODE_NAME
           
protected  Pattern excludeRE
          The regular expression for the exclude pattern.
protected static String FILE_NODE_NAME
           
protected static String FILENAME_ATTR_NAME
           
protected  Pattern includeRE
          The regular expression for the include pattern.
protected  boolean isRequestedDirectory
          This is only set to true for the requested directory specified by the src attribute on the generator's configuration.
protected static String LASTMOD_ATTR_NAME
           
protected static String PREFIX
          The namespace prefix for this namespace.
protected  long refreshDelay
          The delay between checks on updates to the filesystem.
protected  boolean reverse
          The reverse parameter reverses the sort order.
protected  Pattern rootRE
          The regular expression for the root pattern.
protected static String SIZE_ATTR_NAME
           
protected  String sort
          The sort parameter determines by which attribute the content of one directory should be sorted.
protected static String URI
          The URI of the namespace of this generator.
 
Constructor Summary
DirectoryGenerator()
           
DirectoryGenerator(File file)
           
 
Method Summary
protected  void addAncestorPath(File path, Stack<File> ancestors)
          Adds recursively the path from the directory matched by the root pattern down to the requested directory.
protected  void addPath(File path, int scanDepth)
          Adds a single node to the generated document.
 CacheKey constructCacheKey()
           
protected  void endNode(String nodeName)
          Ends the named node.
 void execute()
          Gets the source validity, using a deferred validity object.
protected  Stack<File> getAncestors(File path)
          Creates a stack containing the ancestors of File up to specified directory.
protected  boolean isExcluded(File path)
          Determines if a given File shall be excluded from viewing.
protected  boolean isIncluded(File path)
          Determines if a given File shall be visible.
protected  boolean isRoot(File path)
          Determines if a given File is the defined root.
 void setConfiguration(Map<String,? extends Object> configuration)
          Pass component specific configuration parameters to the pipeline component in a generic way.
 void setDirectorySource(File directorySource)
           
protected  void setNodeAttributes(File path)
          Sets the attributes for a given path.
protected  void startNode(String nodeName, File path)
          Begins a named node and calls setNodeAttributes to set its attributes.
 
Methods inherited from class org.apache.cocoon.sax.AbstractSAXProducer
getSAXConsumer, setConsumer, setSAXConsumer, toString
 
Methods inherited from class org.apache.cocoon.pipeline.component.AbstractPipelineComponent
finish, setup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.pipeline.component.PipelineComponent
finish, setup
 

Field Detail

URI

protected static final String URI
The URI of the namespace of this generator.

See Also:
Constant Field Values

PREFIX

protected static final String PREFIX
The namespace prefix for this namespace.

See Also:
Constant Field Values

DIR_NODE_NAME

protected static final String DIR_NODE_NAME
See Also:
Constant Field Values

FILE_NODE_NAME

protected static final String FILE_NODE_NAME
See Also:
Constant Field Values

FILENAME_ATTR_NAME

protected static final String FILENAME_ATTR_NAME
See Also:
Constant Field Values

LASTMOD_ATTR_NAME

protected static final String LASTMOD_ATTR_NAME
See Also:
Constant Field Values

DATE_ATTR_NAME

protected static final String DATE_ATTR_NAME
See Also:
Constant Field Values

SIZE_ATTR_NAME

protected static final String SIZE_ATTR_NAME
See Also:
Constant Field Values

attributes

protected org.xml.sax.helpers.AttributesImpl attributes
Convenience object, so we don't need to create an AttributesImpl for every element.


depth

protected int depth
The depth parameter determines how deep the DirectoryGenerator should delve.


dateFormatter

protected SimpleDateFormat dateFormatter
The dateFormatter determines into which date format the lastModified time should be converted.


refreshDelay

protected long refreshDelay
The delay between checks on updates to the filesystem.


sort

protected String sort
The sort parameter determines by which attribute the content of one directory should be sorted. Possible values are "name", "size", "lastmodified" and "directory", where "directory" is the same as "name", except that directory entries are listed first.


reverse

protected boolean reverse
The reverse parameter reverses the sort order. false is default.


rootRE

protected Pattern rootRE
The regular expression for the root pattern.


includeRE

protected Pattern includeRE
The regular expression for the include pattern.


excludeRE

protected Pattern excludeRE
The regular expression for the exclude pattern.


isRequestedDirectory

protected boolean isRequestedDirectory
This is only set to true for the requested directory specified by the src attribute on the generator's configuration.

Constructor Detail

DirectoryGenerator

public DirectoryGenerator()

DirectoryGenerator

public DirectoryGenerator(File file)
Method Detail

setDirectorySource

public void setDirectorySource(File directorySource)

setConfiguration

public void setConfiguration(Map<String,? extends Object> configuration)
Description copied from interface: PipelineComponent
Pass component specific configuration parameters to the pipeline component in a generic way. This is useful in environments that automatically assemble pipelines with their components and can't use the components constructors or setters.

Specified by:
setConfiguration in interface PipelineComponent
Overrides:
setConfiguration in class AbstractPipelineComponent
Parameters:
configuration - The Map of configuration parameters.

execute

public void execute()
             throws ProcessingException
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 occurred. So the returned object is kept by the generator and filled with each of the files that is traversed.

Specified by:
execute in interface Starter
Throws:
SAXException - if an error occurs while outputting the document
ProcessingException - if the requested URI isn't a directory on the local filesystem
See Also:
public SourceValidity getValidity() { if (this.validity == null) { this.validity = new DirValidity(this.refreshDelay); } return this.validity; }/ /** Generate XML data.

getAncestors

protected Stack<File> getAncestors(File path)
Creates a stack containing the ancestors of File up to specified directory.

Parameters:
path - the File whose ancestors shall be retrieved
Returns:
a Stack containing the ancestors.

addAncestorPath

protected void addAncestorPath(File path,
                               Stack<File> ancestors)
                        throws SAXException
Adds recursively the path from the directory matched by the root pattern down to the requested directory.

Parameters:
path - the requested directory.
ancestors - the stack of the ancestors.
Throws:
SAXException

addPath

protected void addPath(File path,
                       int scanDepth)
                throws SAXException
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.

Parameters:
path - the file/directory to process
scanDepth - how deep to scan the directory
Throws:
SAXException - if an error occurs while constructing nodes

startNode

protected void startNode(String nodeName,
                         File path)
                  throws SAXException
Begins a named node and calls setNodeAttributes to set its attributes.

Parameters:
nodeName - the name of the new node
path - the file/directory to use when setting attributes
Throws:
SAXException - if an error occurs while creating the node

setNodeAttributes

protected void setNodeAttributes(File path)
                          throws SAXException
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.

Parameters:
path - the file/directory to use when setting attributes
Throws:
SAXException - if an error occurs while setting the attributes

endNode

protected void endNode(String nodeName)
                throws SAXException
Ends the named node.

Parameters:
nodeName - the name of the new node
Throws:
SAXException - if an error occurs while closing the node

isRoot

protected boolean isRoot(File path)
Determines if a given File is the defined root.

Parameters:
path - the File to check
Returns:
true if the File is the root or the root pattern is not set, false otherwise.

isIncluded

protected boolean isIncluded(File path)
Determines if a given File shall be visible.

Parameters:
path - the File to check
Returns:
true if the File shall be visible or the include Pattern is null, false otherwise.

isExcluded

protected boolean isExcluded(File path)
Determines if a given File shall be excluded from viewing.

Parameters:
path - the File to check
Returns:
false if the given File shall not be excluded or the exclude Pattern is null, true otherwise.

constructCacheKey

public CacheKey constructCacheKey()
Specified by:
constructCacheKey in interface CachingPipelineComponent


Copyright © 2008-2012 The Apache Software Foundation. All Rights Reserved.