org.apache.velocity.anakia
Class XPathTool

java.lang.Object
  |
  +--org.apache.velocity.anakia.XPathTool

public class XPathTool
extends java.lang.Object

This class adds an entrypoint into XPath functionality, for Anakia.

All methods take a string XPath specification, along with a context, and produces a resulting java.util.List.

The W3C XPath Specification (http://www.w3.org/TR/xpath) refers to NodeSets repeatedly, but this implementation simply uses java.util.List to hold all Nodes. A 'Node' is any object in a JDOM object tree, such as an org.jdom.Element, org.jdom.Document, or org.jdom.Attribute.

To use it in Velocity, do this:

 #set $authors = $xpath.applyTo("document/author", $root)
 #foreach ($author in $authors)
   $author.getValue() 
 #end
 #set $chapterTitles = $xpath.applyTo("document/chapter/@title", $root)
 #foreach ($title in $chapterTitles)
   $title.getValue()
 #end
 

Version:
$Id: XPathTool.java,v 1.10 2001/03/20 01:52:52 jon Exp $
Author:
bob mcwhirter, Jon S. Stevens

Constructor Summary
XPathTool()
          Constructor does nothing, as this is mostly just objectified static methods
 
Method Summary
 java.util.List applyTo(java.lang.String xpathSpec, org.jdom.Document doc)
          Apply an XPath to a JDOM Document
 java.util.List applyTo(java.lang.String xpathSpec, org.jdom.Element elem)
          Apply an XPath to a JDOM Element
 java.util.List applyTo(java.lang.String xpathSpec, java.util.List nodeSet)
          Apply an XPath to a nodeset
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

XPathTool

public XPathTool()
Constructor does nothing, as this is mostly just objectified static methods
Method Detail

applyTo

public java.util.List applyTo(java.lang.String xpathSpec,
                              org.jdom.Document doc)
Apply an XPath to a JDOM Document
Parameters:
xpathSpec - The XPath to apply
doc - The Document context
Returns:
A list of selected nodes

applyTo

public java.util.List applyTo(java.lang.String xpathSpec,
                              org.jdom.Element elem)
Apply an XPath to a JDOM Element
Parameters:
xpathSpec - The XPath to apply
doc - The Element context
Returns:
A list of selected nodes

applyTo

public java.util.List applyTo(java.lang.String xpathSpec,
                              java.util.List nodeSet)
Apply an XPath to a nodeset
Parameters:
xpathSpec - The XPath to apply
doc - The nodeset context
Returns:
A list of selected nodes


Copyright © 2001 Apache Software Foundation. All Rights Reserved.