com.taleo.integration.client.customstep.util.xml
Class XPathHelper

java.lang.Object
  extended by com.taleo.integration.client.customstep.util.xml.XPathHelper

public class XPathHelper
extends java.lang.Object

XPath Helper.

Author:
Romain Guay - Taleo Corporation

Constructor Summary
XPathHelper()
          Constructor without argument.
XPathHelper(javax.xml.namespace.NamespaceContext nsContext)
          Constructor with the namespace context.
 
Method Summary
 java.lang.Object evaluate(java.io.InputStream xml, java.lang.String xPath, javax.xml.namespace.QName returnType)
          Evaluate an XPath expression on an XML fragment.
 java.lang.Object getVariable(java.lang.Object name)
          Get a variable value.
 void setVariable(java.lang.String name, java.lang.Object value)
          Set a variable to be resolved while evaluating XPath.
static java.lang.String stripNamespacePrefixes(java.lang.String xPath)
          Strip the namespace prefixes from 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()
Constructor without argument.

Note that this instance cannot evaluate XPath expressions that use any namespace.


XPathHelper

public XPathHelper(javax.xml.namespace.NamespaceContext nsContext)
Constructor with the namespace context.

Note that this instance cannot evaluate XPath expressions that use the default namespace.

Parameters:
nsContext - The namespace context to evaluate the XPath expression.
Method Detail

setVariable

public void setVariable(java.lang.String name,
                        java.lang.Object value)
Set a variable to be resolved while evaluating XPath.

Parameters:
name - The variable name.
value - The variable value.

getVariable

public java.lang.Object getVariable(java.lang.Object name)
Get a variable value.

Parameters:
name - The variable name.
Returns:

evaluate

public java.lang.Object evaluate(java.io.InputStream xml,
                                 java.lang.String xPath,
                                 javax.xml.namespace.QName returnType)
                          throws javax.xml.parsers.ParserConfigurationException,
                                 org.xml.sax.SAXException,
                                 java.io.IOException,
                                 javax.xml.xpath.XPathExpressionException
Evaluate an XPath expression on an XML fragment.

Parameters:
xml - The XML fragment as an InputStream.
xPath - The XPathExpression as a String.
returnType - The return type as defined in XPathConstants.
Returns:
The result of evaluating the XPath expression.
Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
javax.xml.xpath.XPathExpressionException

stripNamespacePrefixes

public static java.lang.String stripNamespacePrefixes(java.lang.String xPath)
Strip the namespace prefixes from an XPath expression.

This is useful because SAXReader does not work with namespaces.

For example, the XPath "/x:A/y:B/C" would result in "/A/B/C".

Parameters:
xPath - The XPath expression.
Returns: