This project has retired. For details please refer to its Attic page.
XPathDirectoryGenerator (Cocoon Pipeline Components 1.0.0 API)

org.apache.cocoon.generation
Class XPathDirectoryGenerator

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.xml.AbstractXMLProducer
          extended byorg.apache.cocoon.generation.AbstractGenerator
              extended byorg.apache.cocoon.generation.ServiceableGenerator
                  extended byorg.apache.cocoon.generation.DirectoryGenerator
                      extended byorg.apache.cocoon.generation.XPathDirectoryGenerator
All Implemented Interfaces:
org.apache.cocoon.caching.CacheableProcessingComponent, Disposable, org.apache.cocoon.generation.Generator, Poolable, Recyclable, Serviceable, org.apache.cocoon.sitemap.SitemapModelComponent, org.apache.cocoon.xml.XMLProducer

public class XPathDirectoryGenerator
extends DirectoryGenerator

Generates an XML directory listing performing XPath queries on XML files. It can be used both as a plain DirectoryGenerator or, by specifying a parameter xpath, it will perform an XPath query on every XML resource.

Generates an XML directory listing performing XPath queries on XML files. It can be used both as a plain DirectoryGenerator or, by specifying a parameter xpath, it will perform an XPath query on every XML resource. A nsmapping parameter can be specified to point to a file containing lines to map prefixes to namespaces like this:

prefix=namespace-uri
prefix2=namespace-uri-2

A parameter nsmapping-reload specifies if the prefix-2-namespace mapping file should be checked to be reloaded on each request to this generator if it was modified since the last time it was read.

An additional parameter xmlFiles can be set in the sitemap setting the regular expression pattern for determining if a file should be handled as XML file or not. The default value for this param is \.xml$, so that it matches all files ending .xml.


Sample usage:

Sitemap:
  <map:match pattern="documents/**"> 
   <map:generate type="xpathdirectory" src="docs/{1}"> 
    <map:parameter name="xpath" value="/article/title|/article/abstract"/> 
    <map:parameter name="nsmapping" value="mapping.properties"/> 
    <map:parameter name="nsmapping-reload" value="false"/> 
    <map:parameter name="xmlFiles" value="\.xml$"/> 
   </map:generate> 
   <map:serialize type="xml" /> 
  </map:match>
 

Request:
http://www.some.host/documents/test

Result:
  <dir:directory name="test" lastModified="1010400942000" date="1/7/02 11:55 AM" requested="true" xmlns:dir="http://apache.org/cocoon/directory/2.0"> 
   <dir:directory name="subdirectory" lastModified="1010400942000" date="1/7/02 11:55 AM"/> 
   <dir:file name="test.xml" lastModified="1011011579000" date="1/14/02 1:32 PM"> 
    <dir:xpath query="/article/title"> 
     <title>This is a test document</title> 
      <abstract> 
       <para>Abstract of my test article</para> 
      </abstract> 
     </dir:xpath> 
    </dir:file> 
   <dir:file name="test.gif" lastModified="1011011579000" date="1/14/02 1:32 PM"/> 
  </dir:directory>
 

Version:
$Id: XPathDirectoryGenerator.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Nested Class Summary
 
Nested classes inherited from class org.apache.cocoon.generation.DirectoryGenerator
DirectoryGenerator.DirValidity
 
Field Summary
protected  Document doc
          The document that should be parsed and (partly) included.
protected static Map mappingFiles
          All the mapping files lastmodified dates
protected  org.apache.cocoon.core.xml.DOMParser parser
          The parser for the XML snippets to be included.
protected  PrefixResolver prefixResolver
          The PrefixResolver responsable for processing current request (if any).
protected  XPathProcessor processor
          The XPath processor.
protected static String QUERY_ATTR_NAME
          Attribute for the XPath query.
protected  RE xmlRE
          The regular expression for the XML files pattern.
protected  String xpath
          The XPath.
protected static String XPATH_NODE_NAME
          Local name for the element that contains the included XML snippet.
 
Fields inherited from class org.apache.cocoon.generation.DirectoryGenerator
attributes, cacheKeyParList, DATE_ATTR_NAME, dateFormatter, depth, DIR_NODE_NAME, directorySource, excludeRE, FILE_NODE_NAME, FILENAME_ATTR_NAME, includeRE, isRequestedDirectory, LASTMOD_ATTR_NAME, PREFIX, refreshDelay, reverse, rootRE, SIZE_ATTR_NAME, sort, URI, validity
 
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
XPathDirectoryGenerator()
           
 
Method Summary
 void dispose()
          Disposable
protected  boolean isXML(File path)
          Determines if a given File shall be handled as XML.
protected  void performXPathQuery(File xmlFile)
          Performs an XPath query on the file.
 void recycle()
          Recycle resources
 void service(ServiceManager manager)
           
 void setParser(org.apache.cocoon.core.xml.DOMParser parser)
           
 void setup(org.apache.cocoon.environment.SourceResolver resolver, Map objectModel, String src, Parameters par)
          Setup this sitemap component
 void setXPathProcessor(XPathProcessor processor)
           
protected  void startNode(String nodeName, File path)
          Extends the startNode() method of the DirectoryGenerator by starting a possible XPath query on a file.
 
Methods inherited from class org.apache.cocoon.generation.DirectoryGenerator
addAncestorPath, addPath, endNode, generate, getAncestors, getKey, getValidity, isExcluded, isIncluded, isRoot, setNodeAttributes
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
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

XPATH_NODE_NAME

protected static final String XPATH_NODE_NAME
Local name for the element that contains the included XML snippet.

See Also:
Constant Field Values

QUERY_ATTR_NAME

protected static final String QUERY_ATTR_NAME
Attribute for the XPath query.

See Also:
Constant Field Values

mappingFiles

protected static final Map mappingFiles
All the mapping files lastmodified dates


parser

protected org.apache.cocoon.core.xml.DOMParser parser
The parser for the XML snippets to be included.


doc

protected Document doc
The document that should be parsed and (partly) included.


prefixResolver

protected PrefixResolver prefixResolver
The PrefixResolver responsable for processing current request (if any).


xmlRE

protected RE xmlRE
The regular expression for the XML files pattern.


xpath

protected String xpath
The XPath.


processor

protected XPathProcessor processor
The XPath processor.

Constructor Detail

XPathDirectoryGenerator

public XPathDirectoryGenerator()
Method Detail

setParser

public void setParser(org.apache.cocoon.core.xml.DOMParser parser)

setXPathProcessor

public void setXPathProcessor(XPathProcessor processor)

dispose

public void dispose()
Disposable


recycle

public void recycle()
Recycle resources

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

service

public void service(ServiceManager manager)
             throws ServiceException
Throws:
ServiceException

setup

public void setup(org.apache.cocoon.environment.SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters par)
           throws org.apache.cocoon.ProcessingException,
                  SAXException,
                  IOException
Setup this sitemap component

Specified by:
setup in interface org.apache.cocoon.sitemap.SitemapModelComponent
Overrides:
setup in class DirectoryGenerator
Parameters:
resolver - the SourceResolver
objectModel - The environmental object model
src - the source attribute
par - the parameters
Throws:
org.apache.cocoon.ProcessingException - if processing failes
SAXException - in case of XML related errors
IOException - in case of file related errors

isXML

protected boolean isXML(File path)
Determines if a given File shall be handled as XML.

Parameters:
path - the File to check
Returns:
true if the given File shall handled as XML, false otherwise.

performXPathQuery

protected void performXPathQuery(File xmlFile)
                          throws SAXException
Performs an XPath query on the file.

Parameters:
xmlFile - the File the XPath is performed on.
Throws:
SAXException - if something goes wrong while adding the XML snippet.

startNode

protected void startNode(String nodeName,
                         File path)
                  throws SAXException
Extends the startNode() method of the DirectoryGenerator by starting a possible XPath query on a file.

Overrides:
startNode in class DirectoryGenerator
Parameters:
nodeName - the node currently processing
path - the file path
Throws:
SAXException - in case of errors


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