| org.apache.cocoon.generation.AbstractGenerator org.apache.cocoon.generation.ServiceableGenerator org.apache.cocoon.generation.TraversableGenerator org.apache.cocoon.generation.XPathTraversableGenerator
XPathTraversableGenerator | public class XPathTraversableGenerator extends TraversableGenerator (Code) | | Generates an XML collection listing performing XPath queries on XML sources.
It can be used both as a plain TraversableGenerator or, if an XPath is
specified, it will perform an XPath query on every XML resource, where "xml
resource" is, by default, any resource ending with ".xml", which can be
overriden by setting the (regexp) pattern "xmlFiles as a sitemap parameter,
or where the name of the resource has a container-wide mime-type mapping to
'text/xml' such as specified by mime-mapping elements in a web.xml
descriptor file.
The XPath can be specified in two ways:
- By using an XPointerish syntax in the URL: everything following the
pound sign (possiby preceding query
string arguments) will be treated as the XPath;
- Specifying it as a sitemap parameter named "xpath"
Sample usage:
Sitemap:
<map:match pattern="documents/**">
<map:generate type="xpathdirectory"
src=" docs/{1}#/article/title|/article/abstract" >
< map:parameter name="xmlFiles" value="\.xml$"/>
</map:generate>
<map: serialize type="xml" /> </map:match>
Request:
http://www.some.host/documents/test
Result:
<collection:collection
name="test" lastModified="1010400942000"
date="1/7/02 11:55 AM" requested="true"
xmlns:collection="http://apache.org/cocoon/collection/1.0">
<collection:collection name="subdirectory" lastModified="1010400942000" date="1/7/02 11:55 AM" />
<collection:resource name="test.xml" lastModified="1011011579000" date="1/14/02 1:32 PM">
<collection:xpath docid="test.xml" query="/article/title">
<title>This is a test document</title>
<abstract>
<para>Abstract of my test article</para>
</abstract>
</collection:xpath>
</collection:resource>
<collection:resource name="test.gif" lastModified="1011011579000" date="1/14/02 1:32 PM">
</collection:collection>
If you need to use namespaces, you can set them as sitemap parameters in
the form:
lt;map:parameter name="xmlns:your prefix" value="nsURI"/**">
author: Gianugo Rabellino author: Daniele Madama version: CVS $Id: XPathTraversableGenerator.java 433543 2006-08-22 06:22:54Z crossley $ |
Inner Class :static class XPathPrefixResolver implements PrefixResolver | |
Method Summary | |
protected void | addContent(TraversableSource source) | public void | dispose() | protected boolean | isXML(TraversableSource path) Determines if a given TraversableSource shall be handled as XML. | protected void | performXPathQuery(TraversableSource in) Performs an XPath query on the source. | public void | recycle() | public void | service(ServiceManager manager) | public void | setup(SourceResolver resolver, Map objectModel, String src, Parameters par) |
QUERY_ATTR_NAME | final protected static String QUERY_ATTR_NAME(Code) | | Attribute for the XPath query.
|
RESULT_DOCID_ATTR | final protected static String RESULT_DOCID_ATTR(Code) | | The document containing a successful XPath query
|
XPATH_NODE_NAME | final protected static String XPATH_NODE_NAME(Code) | | Local name for the element that contains the included XML snippet.
|
context | protected Context context(Code) | | The cocoon context used for mime-type mappings
|
doc | protected Document doc(Code) | | The document that should be parsed and (partly) included.
|
prefixResolver | protected XPathPrefixResolver prefixResolver(Code) | | The prefix resolver for namespaced queries
|
processor | protected XPathProcessor processor(Code) | | The XPath processor.
|
xmlRE | protected RE xmlRE(Code) | | The regular expression for the XML files pattern.
|
dispose | public void dispose()(Code) | | |
isXML | protected boolean isXML(TraversableSource path)(Code) | | Determines if a given TraversableSource shall be handled as XML.
Parameters: path - the TraversableSource to check true if the given TraversableSource shall handled as XML, falseotherwise. |
performXPathQuery | protected void performXPathQuery(TraversableSource in) throws SAXException(Code) | | Performs an XPath query on the source.
Parameters: in - the Source the XPath is performed on. throws: SAXException - if something goes wrong while adding the XML snippet. |
recycle | public void recycle()(Code) | | Recycle resources
|
service | public void service(ServiceManager manager) throws ServiceException(Code) | | |
Methods inherited from org.apache.cocoon.generation.TraversableGenerator | protected void addAncestorPath(TraversableSource source, Stack ancestors) throws SAXException, ProcessingException(Code)(Java Doc) protected void addContent(TraversableSource source) throws SAXException, ProcessingException(Code)(Java Doc) protected void addPath(TraversableSource source, int depth) throws SAXException, ProcessingException(Code)(Java Doc) protected void endNode(String nodeName) throws SAXException(Code)(Java Doc) public void generate() throws SAXException, ProcessingException(Code)(Java Doc) protected Stack getAncestors(TraversableSource source) throws IOException(Code)(Java Doc) public Serializable getKey()(Code)(Java Doc) public SourceValidity getValidity()(Code)(Java Doc) protected boolean isExcluded(TraversableSource source)(Code)(Java Doc) protected boolean isIncluded(TraversableSource source)(Code)(Java Doc) protected boolean isRoot(TraversableSource source)(Code)(Java Doc) public void recycle()(Code)(Java Doc) protected void setNodeAttributes(TraversableSource source) throws SAXException, ProcessingException(Code)(Java Doc) public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException(Code)(Java Doc) protected void startNode(String nodeName, TraversableSource source) throws SAXException, ProcessingException(Code)(Java Doc)
|
Fields inherited from org.apache.cocoon.generation.ServiceableGenerator | protected ServiceManager manager(Code)(Java Doc)
|
Methods inherited from org.apache.cocoon.generation.ServiceableGenerator | public void dispose()(Code)(Java Doc) public void service(ServiceManager manager) throws ServiceException(Code)(Java Doc)
|
|
|