|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.avalon.framework.logger.AbstractLogEnabled
org.apache.cocoon.xml.AbstractXMLProducer
org.apache.cocoon.generation.AbstractGenerator
org.apache.cocoon.generation.ServiceableGenerator
org.apache.cocoon.generation.DirectoryGenerator
org.apache.cocoon.generation.XPathDirectoryGenerator
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
.
<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.proeprties"/> <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
<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>
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 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 org.apache.regexp.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)
Set the current ServiceManager instance used by this
Serviceable . |
void |
setup(SourceResolver resolver,
Map objectModel,
String src,
Parameters par)
Setup this sitemap component |
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.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 |
protected static final String XPATH_NODE_NAME
protected static final String QUERY_ATTR_NAME
protected static Map mappingFiles
protected DOMParser parser
protected Document doc
protected PrefixResolver prefixResolver
protected org.apache.regexp.RE xmlRE
protected String xpath
protected XPathProcessor processor
Constructor Detail |
public XPathDirectoryGenerator()
Method Detail |
public void dispose()
dispose
in interface Disposable
dispose
in class ServiceableGenerator
public void recycle()
recycle
in interface Recyclable
recycle
in class DirectoryGenerator
public void service(ServiceManager manager) throws ServiceException
ServiceableGenerator
ServiceManager
instance used by this
Serviceable
.
service
in interface Serviceable
service
in class ServiceableGenerator
ServiceException
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException
setup
in interface SitemapModelComponent
setup
in class DirectoryGenerator
resolver
- the SourceResolverobjectModel
- The environmental object modelsrc
- the source attributepar
- the parameters
ProcessingException
- if processing failes
SAXException
- in case of XML related errors
IOException
- in case of file related errorsprotected boolean isXML(File path)
path
- the File to check
protected void performXPathQuery(File xmlFile) throws SAXException
xmlFile
- the File the XPath is performed on.
SAXException
- if something goes wrong while adding the XML snippet.protected void startNode(String nodeName, File path) throws SAXException
startNode
in class DirectoryGenerator
nodeName
- the node currently processingpath
- the file path
SAXException
- in case of errors
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |