Package com.helger.xml.xpath
Class XPathHelper
- java.lang.Object
-
- com.helger.xml.xpath.XPathHelper
-
@NotThreadSafe public final class XPathHelper extends Object
Utility class to createXPathandXPathExpressionobjects more easily.- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static XPathcreateNewXPath()Create a newXPathwithout any special settings using the defaultXPathFactory.static XPathcreateNewXPath(NamespaceContext aNamespaceContext)Create a newXPathwith the passed namespace context using the defaultXPathFactory.static XPathcreateNewXPath(XPathFactory aXPathFactory)Create a newXPathwithout any special settings.static XPathcreateNewXPath(XPathFactory aXPathFactory, NamespaceContext aNamespaceContext)Create a newXPathwith the passed namespace context.static XPathcreateNewXPath(XPathFactory aXPathFactory, XPathFunctionResolver aFunctionResolver)Create a newXPathwith the passed function resolver.static XPathcreateNewXPath(XPathFactory aXPathFactory, XPathVariableResolver aVariableResolver)Create a newXPathwith the passed variable resolver.static XPathcreateNewXPath(XPathFactory aXPathFactory, XPathVariableResolver aVariableResolver, XPathFunctionResolver aFunctionResolver, NamespaceContext aNamespaceContext)Create a newXPathwith the passed variable resolver, function resolver and namespace context.static XPathcreateNewXPath(XPathFunctionResolver aFunctionResolver)Create a newXPathwith the passed function resolver using the defaultXPathFactory.static XPathcreateNewXPath(XPathVariableResolver aVariableResolver)Create a newXPathwith the passed variable resolver using the defaultXPathFactory.static XPathcreateNewXPath(XPathVariableResolver aVariableResolver, NamespaceContext aNamespaceContext)Create a newXPathwith the passed variable resolver and namespace context using the defaultXPathFactory.static XPathcreateNewXPath(XPathVariableResolver aVariableResolver, XPathFunctionResolver aFunctionResolver, NamespaceContext aNamespaceContext)Create a newXPathwith the passed variable resolver, function resolver and namespace context using the defaultXPathFactory.static XPathExpressioncreateNewXPathExpression(String sXPath)Create a new XPath expression for evaluation using the defaultXPathFactory.static XPathExpressioncreateNewXPathExpression(NamespaceContext aNamespaceContext, String sXPath)Create a new XPath expression for evaluation using the defaultXPathFactory.static XPathExpressioncreateNewXPathExpression(XPathFunctionResolver aFunctionResolver, String sXPath)Create a new XPath expression for evaluation using the defaultXPathFactory.static XPathExpressioncreateNewXPathExpression(XPath aXPath, String sXPath)Create a new XPath expression for evaluation.static XPathExpressioncreateNewXPathExpression(XPathVariableResolver aVariableResolver, String sXPath)Create a new XPath expression for evaluation using the defaultXPathFactory.static XPathExpressioncreateNewXPathExpression(XPathVariableResolver aVariableResolver, XPathFunctionResolver aFunctionResolver, NamespaceContext aNamespaceContext, String sXPath)Create a new XPath expression for evaluation using the defaultXPathFactory.static XPathFactorycreateXPathFactorySaxonFirst()Create a newXPathFactorytrying to instantiate Saxon classnet.sf.saxon.xpath.XPathFactoryImplfirst.static XPathFactorygetDefaultXPathFactory()
-
-
-
Method Detail
-
getDefaultXPathFactory
@Nonnull public static XPathFactory getDefaultXPathFactory()
- Returns:
- The default XPath factory. Be careful when manipulating this
object! Never
null.
-
createXPathFactorySaxonFirst
@Nonnull public static XPathFactory createXPathFactorySaxonFirst()
Create a newXPathFactorytrying to instantiate Saxon classnet.sf.saxon.xpath.XPathFactoryImplfirst. If that fails, the default XPathFactory is created.- Returns:
- A new
XPathFactoryand nevernull. - Throws:
IllegalStateException- In case neither Saxon nor default factory could be instantiated!
-
createNewXPath
@Nonnull public static XPath createNewXPath()
Create a newXPathwithout any special settings using the defaultXPathFactory.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nonnull XPathFactory aXPathFactory)
Create a newXPathwithout any special settings.- Parameters:
aXPathFactory- The XPath factory object to use. May not benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nullable XPathVariableResolver aVariableResolver)
Create a newXPathwith the passed variable resolver using the defaultXPathFactory.- Parameters:
aVariableResolver- Variable resolver to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nonnull XPathFactory aXPathFactory, @Nullable XPathVariableResolver aVariableResolver)
Create a newXPathwith the passed variable resolver.- Parameters:
aXPathFactory- The XPath factory object to use. May not benull.aVariableResolver- Variable resolver to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nullable XPathFunctionResolver aFunctionResolver)
Create a newXPathwith the passed function resolver using the defaultXPathFactory.- Parameters:
aFunctionResolver- Function resolver to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nonnull XPathFactory aXPathFactory, @Nullable XPathFunctionResolver aFunctionResolver)
Create a newXPathwith the passed function resolver.- Parameters:
aXPathFactory- The XPath factory object to use. May not benull.aFunctionResolver- Function resolver to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nullable NamespaceContext aNamespaceContext)
Create a newXPathwith the passed namespace context using the defaultXPathFactory.- Parameters:
aNamespaceContext- Namespace context to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nonnull XPathFactory aXPathFactory, @Nullable NamespaceContext aNamespaceContext)
Create a newXPathwith the passed namespace context.- Parameters:
aXPathFactory- The XPath factory object to use. May not benull.aNamespaceContext- Namespace context to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nullable XPathVariableResolver aVariableResolver, @Nullable NamespaceContext aNamespaceContext)
Create a newXPathwith the passed variable resolver and namespace context using the defaultXPathFactory.- Parameters:
aVariableResolver- Variable resolver to be used. May benull.aNamespaceContext- Namespace context to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nullable XPathVariableResolver aVariableResolver, @Nullable XPathFunctionResolver aFunctionResolver, @Nullable NamespaceContext aNamespaceContext)
Create a newXPathwith the passed variable resolver, function resolver and namespace context using the defaultXPathFactory.- Parameters:
aVariableResolver- Variable resolver to be used. May benull.aFunctionResolver- Function resolver to be used. May benull.aNamespaceContext- Namespace context to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPath
@Nonnull public static XPath createNewXPath(@Nonnull XPathFactory aXPathFactory, @Nullable XPathVariableResolver aVariableResolver, @Nullable XPathFunctionResolver aFunctionResolver, @Nullable NamespaceContext aNamespaceContext)
Create a newXPathwith the passed variable resolver, function resolver and namespace context.- Parameters:
aXPathFactory- The XPath factory object to use. May not benull.aVariableResolver- Variable resolver to be used. May benull.aFunctionResolver- Function resolver to be used. May benull.aNamespaceContext- Namespace context to be used. May benull.- Returns:
- The created non-
nullXPathobject
-
createNewXPathExpression
@Nonnull public static XPathExpression createNewXPathExpression(@Nullable XPathVariableResolver aVariableResolver, @Nullable XPathFunctionResolver aFunctionResolver, @Nullable NamespaceContext aNamespaceContext, @Nonnull @Nonempty String sXPath)
Create a new XPath expression for evaluation using the defaultXPathFactory.- Parameters:
aVariableResolver- Variable resolver to be used. May benull.aFunctionResolver- Function resolver to be used. May benull.aNamespaceContext- Namespace context to be used. May benull.sXPath- The main XPath string to be evaluated- Returns:
- The
XPathExpressionobject to be used. - Throws:
IllegalArgumentException- if the XPath cannot be compiled
-
createNewXPathExpression
@Nonnull public static XPathExpression createNewXPathExpression(@Nullable XPathVariableResolver aVariableResolver, @Nonnull @Nonempty String sXPath)
Create a new XPath expression for evaluation using the defaultXPathFactory.- Parameters:
aVariableResolver- Variable resolver to be used. May benull.sXPath- The main XPath string to be evaluated- Returns:
- The
XPathExpressionobject to be used. - Throws:
IllegalArgumentException- if the XPath cannot be compiled
-
createNewXPathExpression
@Nonnull public static XPathExpression createNewXPathExpression(@Nullable XPathFunctionResolver aFunctionResolver, @Nonnull @Nonempty String sXPath)
Create a new XPath expression for evaluation using the defaultXPathFactory.- Parameters:
aFunctionResolver- Function resolver to be used. May benull.sXPath- The main XPath string to be evaluated- Returns:
- The
XPathExpressionobject to be used. - Throws:
IllegalArgumentException- if the XPath cannot be compiled
-
createNewXPathExpression
@Nonnull public static XPathExpression createNewXPathExpression(@Nullable NamespaceContext aNamespaceContext, @Nonnull @Nonempty String sXPath)
Create a new XPath expression for evaluation using the defaultXPathFactory.- Parameters:
aNamespaceContext- Namespace context to be used. May benull.sXPath- The main XPath string to be evaluated- Returns:
- The
XPathExpressionobject to be used. - Throws:
IllegalArgumentException- if the XPath cannot be compiled
-
createNewXPathExpression
@Nonnull public static XPathExpression createNewXPathExpression(@Nonnull @Nonempty String sXPath)
Create a new XPath expression for evaluation using the defaultXPathFactory.- Parameters:
sXPath- The main XPath string to be evaluated- Returns:
- The
XPathExpressionobject to be used. - Throws:
IllegalArgumentException- if the XPath cannot be compiled
-
createNewXPathExpression
@Nonnull public static XPathExpression createNewXPathExpression(@Nonnull XPath aXPath, @Nonnull @Nonempty String sXPath)
Create a new XPath expression for evaluation.- Parameters:
aXPath- The pre-created XPath object. May not benull.sXPath- The main XPath string to be evaluated- Returns:
- The
XPathExpressionobject to be used. - Throws:
IllegalArgumentException- if the XPath cannot be compiled
-
-