Package com.consol.citrus.xml.xpath
Class XPathUtils
- java.lang.Object
-
- com.consol.citrus.xml.xpath.XPathUtils
-
public abstract class XPathUtils extends Object
XPath utility class providing static utility methods dealing with XPath expression evaluation. Class is abstract to prevent instantiation.- Author:
- Christoph Deppisch
-
-
Field Summary
Fields Modifier and Type Field Description static StringDYNAMIC_NS_ENDstatic StringDYNAMIC_NS_STARTDynamic namespace prefix suffix
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Objectevaluate(Node node, String xPathExpression, NamespaceContext nsContext, XPathExpressionResult resultType)Evaluate XPath expression as String result type regardless what actual result type the expression will evaluate to.static BooleanevaluateAsBoolean(Node node, String xPathExpression, NamespaceContext nsContext)Evaluate XPath expression with result type Boolean value.static NodeevaluateAsNode(Node node, String xPathExpression, NamespaceContext nsContext)Evaluate XPath expression with result type Node.static NodeListevaluateAsNodeList(Node node, String xPathExpression, NamespaceContext nsContext)Evaluate XPath expression with result type NodeList.static DoubleevaluateAsNumber(Node node, String xPathExpression, NamespaceContext nsContext)Evaluate XPath expression with result type Number.static ObjectevaluateAsObject(Node node, String xPathExpression, NamespaceContext nsContext, QName resultType)Evaluate XPath expression.static StringevaluateAsString(Node node, String xPathExpression, NamespaceContext nsContext)Evaluate XPath expression with result type String.static ObjectevaluateExpression(Node node, String xPathExpression, NamespaceContext nsContext, QName returnType)Evaluates the expression.static Map<String,String>getDynamicNamespaces(String expression)Extracts dynamic namespaces that are inline inside a XPath expression.static booleanhasDynamicNamespaces(String expression)Searches for dynamic namespaces in expression.static booleanisXPathExpression(String expression)Method to find out whether an expression is of XPath nature or custom dot notation syntax.static StringreplaceDynamicNamespaces(String expression, Map<String,String> namespaces)Replaces all dynamic namespaces in a XPath expression with respective prefixes in namespace map.
-
-
-
Field Detail
-
DYNAMIC_NS_START
public static final String DYNAMIC_NS_START
Dynamic namespace prefix suffix- See Also:
- Constant Field Values
-
DYNAMIC_NS_END
public static final String DYNAMIC_NS_END
- See Also:
- Constant Field Values
-
-
Method Detail
-
getDynamicNamespaces
public static Map<String,String> getDynamicNamespaces(String expression)
Extracts dynamic namespaces that are inline inside a XPath expression. Example:/{http://sample.org/foo}foo/{http://sample.org/bar}bar- Parameters:
expression-- Returns:
-
replaceDynamicNamespaces
public static String replaceDynamicNamespaces(String expression, Map<String,String> namespaces)
Replaces all dynamic namespaces in a XPath expression with respective prefixes in namespace map. XPath:/{http://sample.org/foo}foo/{http://sample.org/bar}barresults in/ns1:foo/ns2:barwhere the namespace map contains ns1 and ns2.- Parameters:
expression-namespaces-- Returns:
-
hasDynamicNamespaces
public static boolean hasDynamicNamespaces(String expression)
Searches for dynamic namespaces in expression.- Parameters:
expression-- Returns:
-
evaluate
public static Object evaluate(Node node, String xPathExpression, NamespaceContext nsContext, XPathExpressionResult resultType)
Evaluate XPath expression as String result type regardless what actual result type the expression will evaluate to.- Parameters:
node-xPathExpression-nsContext-resultType-- Returns:
-
evaluateAsNode
public static Node evaluateAsNode(Node node, String xPathExpression, NamespaceContext nsContext)
Evaluate XPath expression with result type Node.- Parameters:
node-xPathExpression-nsContext-- Returns:
-
evaluateAsNodeList
public static NodeList evaluateAsNodeList(Node node, String xPathExpression, NamespaceContext nsContext)
Evaluate XPath expression with result type NodeList.- Parameters:
node-xPathExpression-nsContext-- Returns:
-
evaluateAsString
public static String evaluateAsString(Node node, String xPathExpression, NamespaceContext nsContext)
Evaluate XPath expression with result type String.- Parameters:
node-xPathExpression-nsContext-- Returns:
-
evaluateAsBoolean
public static Boolean evaluateAsBoolean(Node node, String xPathExpression, NamespaceContext nsContext)
Evaluate XPath expression with result type Boolean value.- Parameters:
node-xPathExpression-nsContext-- Returns:
-
evaluateAsNumber
public static Double evaluateAsNumber(Node node, String xPathExpression, NamespaceContext nsContext)
Evaluate XPath expression with result type Number.- Parameters:
node-xPathExpression-nsContext-- Returns:
-
evaluateAsObject
public static Object evaluateAsObject(Node node, String xPathExpression, NamespaceContext nsContext, QName resultType)
Evaluate XPath expression.- Parameters:
node-xPathExpression-nsContext-- Returns:
-
isXPathExpression
public static boolean isXPathExpression(String expression)
Method to find out whether an expression is of XPath nature or custom dot notation syntax.- Parameters:
expression- the expression string to check.- Returns:
- boolean the result.
-
evaluateExpression
public static Object evaluateExpression(Node node, String xPathExpression, NamespaceContext nsContext, QName returnType)
Evaluates the expression.- Parameters:
node- the node.xPathExpression- the expression.nsContext- the context.returnType-- Returns:
- the result.
-
-