org.apache.cocoon.generation
Class DirectoryGenerator

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.xml.AbstractXMLProducer
          extended by org.apache.cocoon.generation.AbstractGenerator
              extended by org.apache.cocoon.generation.ServiceableGenerator
                  extended by org.apache.cocoon.generation.DirectoryGenerator
All Implemented Interfaces:
Poolable, Recyclable, Disposable, Component, LogEnabled, Serviceable, CacheableProcessingComponent, Generator, SitemapModelComponent, XMLProducer
Direct Known Subclasses:
ImageDirectoryGenerator, MP3DirectoryGenerator, XPathDirectoryGenerator

public class DirectoryGenerator
extends ServiceableGenerator
implements CacheableProcessingComponent

Version:
$Id: DirectoryGenerator.html 1304258 2012-03-23 10:09:27Z ilgrosso $

Nested Class Summary
static class DirectoryGenerator.DirValidity
          Specific validity class, that holds all files that have been generated
 
Field Summary
protected  AttributesImpl attributes
          Convenience object, so we don't need to create an AttributesImpl for every element.
protected  List cacheKeyParList
          The cache key needs to be generated for the configuration of this generator, so storing the parameters for generateKey().
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  Source directorySource
          The source object for the directory.
protected  org.apache.regexp.RE excludeRE
          The regular expression for the exclude pattern.
protected static String FILE_NODE_NAME
           
protected static String FILENAME_ATTR_NAME
           
protected  org.apache.regexp.RE 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  org.apache.regexp.RE 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.
protected  DirectoryGenerator.DirValidity validity
          The validity that is being built
 
Fields inherited from class org.apache.cocoon.generation.ServiceableGenerator
manager
 
Fields inherited from class org.apache.cocoon.generation.AbstractGenerator
objectModel, parameters, resolver, source
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.generation.Generator
ROLE
 
Constructor Summary
DirectoryGenerator()
           
 
Method Summary
protected  void addAncestorPath(File path, Stack ancestors)
          Adds recursively the path from the directory matched by the root pattern down to the requested directory.
protected  void addPath(File path, int depth)
          Adds a single node to the generated document.
protected  void endNode(String nodeName)
          Ends the named node.
 void generate()
          Generate XML data.
protected  Stack getAncestors(File path)
          Creates a stack containing the ancestors of File up to specified directory.
 Serializable getKey()
          Generate the unique key.
 SourceValidity getValidity()
          Gets the source validity, using a deferred validity object.
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 recycle()
          Recycle resources
protected  void setNodeAttributes(File path)
          Sets the attributes for a given path.
 void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
          Set the request parameters.
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.generation.ServiceableGenerator
dispose, service
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
 

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

validity

protected DirectoryGenerator.DirValidity validity
The validity that is being built


attributes

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


cacheKeyParList

protected List cacheKeyParList
The cache key needs to be generated for the configuration of this generator, so storing the parameters for generateKey(). Using the member variables after setup() would not work I guess. I don't know a way from the regular expressions back to the pattern or at least a useful string.


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. FIXME: SimpleDateFormat is not supported by all locales!


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 org.apache.regexp.RE rootRE
The regular expression for the root pattern.


includeRE

protected org.apache.regexp.RE includeRE
The regular expression for the include pattern.


excludeRE

protected org.apache.regexp.RE 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.


directorySource

protected Source directorySource
The source object for the directory.

Constructor Detail

DirectoryGenerator

public DirectoryGenerator()
Method Detail

setup

public void setup(SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters par)
           throws ProcessingException,
                  SAXException,
                  IOException
Set the request parameters. Must be called before the generate method.

Specified by:
setup in interface SitemapModelComponent
Overrides:
setup in class AbstractGenerator
Parameters:
resolver - the SourceResolver object
objectModel - a Map containing model object
src - the directory to be XMLized specified as src attribute on <map:generate/>
par - configuration parameters
Throws:
ProcessingException
SAXException
IOException

getKey

public Serializable getKey()
Description copied from interface: CacheableProcessingComponent
Generate the unique key. This key must be unique inside the space of this component. This method must be invoked before the getValidity() method.

Specified by:
getKey in interface CacheableProcessingComponent
Returns:
The generated key or null if the component is currently not cacheable.

getValidity

public SourceValidity getValidity()
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.

Specified by:
getValidity in interface CacheableProcessingComponent
Returns:
The generated validity object or null if the component is currently not cacheable.
See Also:
DirectoryGenerator.DirValidity

generate

public void generate()
              throws SAXException,
                     ProcessingException
Generate XML data.

Specified by:
generate in interface Generator
Throws:
SAXException - if an error occurs while outputting the document
ProcessingException - if the requsted URI isn't a directory on the local filesystem

getAncestors

protected Stack 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 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 depth)
                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
depth - 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.

recycle

public void recycle()
Recycle resources

Specified by:
recycle in interface Recyclable
Overrides:
recycle in class AbstractGenerator


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.