Package com.hannonhill.cascade.velocity
Class CascadeXPathTool
- java.lang.Object
-
- com.hannonhill.cascade.velocity.CascadeXPathTool
-
public class CascadeXPathTool extends java.lang.Object
This class is used to perform various XPath calls on JDOM nodes.- Since:
- 7.12.3
-
-
Constructor Summary
Constructors Constructor Description CascadeXPathTool()
Constructs aCascadeXPathTool
and initializes anXPath
instance with an XPath expression that selects all nodes.CascadeXPathTool(java.lang.String path)
Constructs aCascadeXPathTool
and initializes anXPath
instance with the provided XPath expression.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNamespace(java.lang.String prefix, java.lang.String uri)
Adds a namespace definition to the list of namespaces known of this XPath expression.java.lang.String
getXPath()
Returns the wrapped XPath expression as a string.static CascadeXPathTool
newInstance(java.lang.String path)
Returns aCascadeXPathTool
that is initialized using the provided XPath expression.java.lang.Number
numberValueOf(java.lang.Object context)
Returns the number value of the first node selected by applying the wrapped XPath expression to the given context.java.util.List
selectNodes(java.lang.Object context)
Wrapper forXPath.selectNodes(Object)
that checks for a null context and throws a more meaningful error message.static java.util.List
selectNodes(java.lang.Object context, java.lang.String path)
Wrapper forXPath.selectNodes(Object, String)
that checks for a null context and throws a more meaningful error message.java.lang.Object
selectSingleNode(java.lang.Object context)
Wrapper forXPath.selectSingleNode(Object)
that checks for a null context and throws a more meaningful error message.static java.lang.Object
selectSingleNode(java.lang.Object context, java.lang.String path)
Wrapper forXPath.selectSingleNode(Object, String)
that checks for a null context and throws a more meaningful error message.void
setVariable(java.lang.String name, java.lang.Object value)
Defines an XPath variable and sets its value.java.lang.String
valueOf(java.lang.Object context)
Returns the string value of the first node selected by applying the wrapped XPath expression to the given context.
-
-
-
Constructor Detail
-
CascadeXPathTool
public CascadeXPathTool() throws java.lang.Exception
Constructs aCascadeXPathTool
and initializes anXPath
instance with an XPath expression that selects all nodes.- Throws:
java.lang.Exception
-
CascadeXPathTool
public CascadeXPathTool(java.lang.String path) throws java.lang.Exception
Constructs aCascadeXPathTool
and initializes anXPath
instance with the provided XPath expression.- Parameters:
path
-- Throws:
java.lang.Exception
-
-
Method Detail
-
newInstance
public static CascadeXPathTool newInstance(java.lang.String path) throws java.lang.Exception
Returns aCascadeXPathTool
that is initialized using the provided XPath expression.- Parameters:
path
-- Returns:
- Throws:
java.lang.Exception
-
addNamespace
public void addNamespace(java.lang.String prefix, java.lang.String uri)
Adds a namespace definition to the list of namespaces known of this XPath expression.- Parameters:
prefix
-uri
-
-
getXPath
public java.lang.String getXPath()
Returns the wrapped XPath expression as a string.- Returns:
-
numberValueOf
public java.lang.Number numberValueOf(java.lang.Object context) throws java.lang.Exception
Returns the number value of the first node selected by applying the wrapped XPath expression to the given context.- Parameters:
context
-- Returns:
- Throws:
java.lang.Exception
-
selectNodes
public java.util.List selectNodes(java.lang.Object context) throws java.lang.Exception
Wrapper forXPath.selectNodes(Object)
that checks for a null context and throws a more meaningful error message.- Parameters:
context
-- Returns:
- Throws:
java.lang.Exception
-
selectNodes
public static java.util.List selectNodes(java.lang.Object context, java.lang.String path) throws java.lang.Exception
Wrapper forXPath.selectNodes(Object, String)
that checks for a null context and throws a more meaningful error message.- Parameters:
context
-path
-- Returns:
- Throws:
java.lang.Exception
-
selectSingleNode
public java.lang.Object selectSingleNode(java.lang.Object context) throws java.lang.Exception
Wrapper forXPath.selectSingleNode(Object)
that checks for a null context and throws a more meaningful error message.- Parameters:
context
-- Returns:
- Throws:
java.lang.Exception
-
selectSingleNode
public static java.lang.Object selectSingleNode(java.lang.Object context, java.lang.String path) throws java.lang.Exception
Wrapper forXPath.selectSingleNode(Object, String)
that checks for a null context and throws a more meaningful error message.- Parameters:
context
-path
-- Returns:
- Throws:
java.lang.Exception
-
setVariable
public void setVariable(java.lang.String name, java.lang.Object value)
Defines an XPath variable and sets its value.- Parameters:
name
-value
-
-
valueOf
public java.lang.String valueOf(java.lang.Object context) throws java.lang.Exception
Returns the string value of the first node selected by applying the wrapped XPath expression to the given context.- Parameters:
context
-- Returns:
- Throws:
java.lang.Exception
-
-