org.jdom.contrib.helpers
Class XPathHelper

java.lang.Object
  extended by org.jdom.contrib.helpers.XPathHelper

public class XPathHelper
extends java.lang.Object

Provides a set of utility methods to generate XPath expressions to select a given node in a (subtree of a) document.

Note: As this class has no knowledge of the document content, the generated XPath expression rely on the document structure. Hence any modification of the structure of the document may invalidate the generated XPaths.

Author:
Laurent Bihanic

Constructor Summary
XPathHelper()
           
 
Method Summary
static java.lang.String getPathString(org.jdom.Attribute to)
          Returns the path to the specified Attribute from the document root as an XPath expression.
static java.lang.String getPathString(org.jdom.Comment to)
          Returns the path to the specified Comment from the document root as an XPath expression.
static java.lang.String getPathString(org.jdom.Element to)
          Returns the path to the specified Element from the document root as an XPath expression.
static java.lang.String getPathString(java.lang.Object to)
          Returns the path to the specified JDOM node from the document root as an XPath expression.
static java.lang.String getPathString(java.lang.Object from, org.jdom.Attribute to)
          Returns the path from a given JDOM node to the specified Attribute as an XPath expression.
static java.lang.String getPathString(java.lang.Object from, org.jdom.Comment to)
          Returns the path from a given JDOM node to the specified Comment as an XPath expression.
static java.lang.String getPathString(java.lang.Object from, org.jdom.Element to)
          Returns the path from a given JDOM node to the specified Element as an XPath expression.
static java.lang.String getPathString(java.lang.Object from, java.lang.Object to)
          Returns the path from a JDOM node to another JDOM node as an XPath expression.
static java.lang.String getPathString(java.lang.Object from, org.jdom.ProcessingInstruction to)
          Returns the path from a given JDOM node to the specified ProcessingInstruction node as an XPath expression.
static java.lang.String getPathString(java.lang.Object from, org.jdom.Text to)
          Returns the path from a given JDOM node to the specified Text node as an XPath expression.
static java.lang.String getPathString(org.jdom.ProcessingInstruction to)
          Returns the path to the specified ProcessingInstruction node from the document root as an XPath expression.
static java.lang.String getPathString(org.jdom.Text to)
          Returns the path to the specified Text node from the document root as an XPath expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPathHelper

public XPathHelper()
Method Detail

getPathString

public static java.lang.String getPathString(org.jdom.Element to)
                                      throws org.jdom.JDOMException
Returns the path to the specified Element from the document root as an XPath expression.

Parameters:
to - the Element the generated path shall select.
Returns:
an XPath expression to select the specified node.
Throws:
org.jdom.JDOMException - if the XPath generation failed.
java.lang.IllegalArgumentException - if to is null.

getPathString

public static java.lang.String getPathString(java.lang.Object from,
                                             org.jdom.Element to)
                                      throws org.jdom.JDOMException
Returns the path from a given JDOM node to the specified Element as an XPath expression.

Parameters:
from - the Document or Element node at which the the generated path shall be applied. Use null to specify the topmost ancestor of the to node.
to - the Element the generated path shall select.
Returns:
an XPath expression to select the specified node.
Throws:
org.jdom.JDOMException - if the XPath generation failed.
java.lang.IllegalArgumentException - if to is null or from is not a Document or a Element node.

getPathString

public static java.lang.String getPathString(org.jdom.Attribute to)
                                      throws org.jdom.JDOMException
Returns the path to the specified Attribute from the document root as an XPath expression.

Parameters:
to - the Attribute the generated path shall select.
Returns:
an XPath expression to select the specified node.
Throws:
org.jdom.JDOMException - if the XPath generation failed.
java.lang.IllegalArgumentException - if to is null.

getPathString

public static java.lang.String getPathString(java.lang.Object from,
                                             org.jdom.Attribute to)
                                      throws org.jdom.JDOMException
Returns the path from a given JDOM node to the specified Attribute as an XPath expression.

Parameters:
from - the Document or Element node at which the the generated path shall be applied. Use null to specify the topmost ancestor of the to node.
to - the Attribute the generated path shall select.
Returns:
an XPath expression to select the specified node.
Throws:
org.jdom.JDOMException - if the XPath generation failed.
java.lang.IllegalArgumentException - if to is null or from is not a Document or a Element node.

getPathString

public static java.lang.String getPathString(org.jdom.Text to)
                                      throws org.jdom.JDOMException
Returns the path to the specified Text node from the document root as an XPath expression.

Parameters:
to - the Text node the generated path shall select.
Returns:
an XPath expression to select the specified node.
Throws:
org.jdom.JDOMException - if the XPath generation failed.
java.lang.IllegalArgumentException - if to is null.

getPathString

public static java.lang.String getPathString(java.lang.Object from,
                                             org.jdom.Text to)
                                      throws org.jdom.JDOMException
Returns the path from a given JDOM node to the specified Text node as an XPath expression.

Parameters:
from - the Document or Element node at which the the generated path shall be applied. Use null to specify the topmost ancestor of the to node.
to - the Text node the generated path shall select.
Returns:
an XPath expression to select the specified node.
Throws:
org.jdom.JDOMException - if the XPath generation failed.
java.lang.IllegalArgumentException - if to is null or from is not a Document or a Element node.

getPathString

public static java.lang.String getPathString(org.jdom.Comment to)
                                      throws org.jdom.JDOMException
Returns the path to the specified Comment from the document root as an XPath expression.

Parameters:
to - the Comment the generated path shall select.
Returns:
an XPath expression to select the specified node.
Throws:
org.jdom.JDOMException - if the XPath generation failed.
java.lang.IllegalArgumentException - if to is null.

getPathString

public static java.lang.String getPathString(java.lang.Object from,
                                             org.jdom.Comment to)
                                      throws org.jdom.JDOMException
Returns the path from a given JDOM node to the specified Comment as an XPath expression.

Parameters:
from - the Document or Element node at which the the generated path shall be applied. Use null to specify the topmost ancestor of the to node.
to - the Comment the generated path shall select.
Returns:
an XPath expression to select the specified node.
Throws:
org.jdom.JDOMException - if the XPath generation failed.
java.lang.IllegalArgumentException - if to is null or from is not a Document or a Element node.

getPathString

public static java.lang.String getPathString(org.jdom.ProcessingInstruction to)
                                      throws org.jdom.JDOMException
Returns the path to the specified ProcessingInstruction node from the document root as an XPath expression.

Parameters:
to - the ProcessingInstruction node the generated path shall select.
Returns:
an XPath expression to select the specified node.
Throws:
org.jdom.JDOMException - if the XPath generation failed.
java.lang.IllegalArgumentException - if to is null.

getPathString

public static java.lang.String getPathString(java.lang.Object from,
                                             org.jdom.ProcessingInstruction to)
                                      throws org.jdom.JDOMException
Returns the path from a given JDOM node to the specified ProcessingInstruction node as an XPath expression.

Parameters:
from - the Document or Element node at which the the generated path shall be applied. Use null to specify the topmost ancestor of the to node.
to - the ProcessingInstruction node the generated path shall select.
Returns:
an XPath expression to select the specified node.
Throws:
org.jdom.JDOMException - if the XPath generation failed.
java.lang.IllegalArgumentException - if to is null or from is not a Document or a Element node.

getPathString

public static java.lang.String getPathString(java.lang.Object to)
                                      throws org.jdom.JDOMException
Returns the path to the specified JDOM node from the document root as an XPath expression.

Parameters:
to - the JDOM node the generated path shall select.
Returns:
an XPath expression to select the specified node.
Throws:
org.jdom.JDOMException - if the XPath generation failed.
java.lang.IllegalArgumentException - if to is null or is not a JDOM node selectable by XPath expressions (Element, Attribute, Text, Comment, ProcessingInstruction).

getPathString

public static java.lang.String getPathString(java.lang.Object from,
                                             java.lang.Object to)
                                      throws org.jdom.JDOMException
Returns the path from a JDOM node to another JDOM node as an XPath expression.

Parameters:
from - the Document or Element node at which the the generated path shall be applied. Use null to specify the topmost ancestor of the to node.
to - the JDOM node the generated path shall select.
Returns:
an XPath expression to select the specified node.
Throws:
org.jdom.JDOMException - if the XPath generation failed.
java.lang.IllegalArgumentException - if from is not a Document or a Element node or to is null or is not a JDOM node selectable by XPath expressions (Element, Attribute, Text, Comment, ProcessingInstruction).


Copyright © 2007 Jason Hunter, Brett McLaughlin. All Rights Reserved.