public class XpathUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
DOCUMENT_BUILDER_FACTORY_IMPL_CLASS_NAME
The FQCN of the desired DocumentBuilderFactory implementation.
|
private static java.lang.String |
DOCUMENT_BUILDER_FACTORY_PROP_NAME
The default property name to load the Xalan Document Builder Factory.
|
private static java.lang.String |
DTM_MANAGER_DEFAULT_PROP_NAME
The default property name to load the Xalan DTM manager.
|
private static java.lang.String |
DTM_MANAGER_IMPL_CLASS_NAME
The FQCN of the desired DTMManager implementation.
|
private static org.apache.commons.logging.Log |
log |
private static java.lang.String |
XPATH_CONTEXT_CLASS_NAME
The FQCN of the internal XPathContext class.
|
Constructor and Description |
---|
XpathUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Boolean |
asBoolean(java.lang.String expression,
org.w3c.dom.Node node)
Evaluates the specified XPath expression and returns the result as a
Boolean.
|
static java.lang.Boolean |
asBoolean(java.lang.String expression,
org.w3c.dom.Node node,
javax.xml.xpath.XPath xpath)
Same as
asBoolean(String, Node) but allows an xpath to be passed
in explicitly for reuse. |
static java.lang.Byte |
asByte(java.lang.String expression,
org.w3c.dom.Node node)
Evaluates the specified XPath expression and returns the result as a
Byte.
|
static java.lang.Byte |
asByte(java.lang.String expression,
org.w3c.dom.Node node,
javax.xml.xpath.XPath xpath)
Same as
asByte(String, Node) but allows an xpath to be passed
in explicitly for reuse. |
static java.nio.ByteBuffer |
asByteBuffer(java.lang.String expression,
org.w3c.dom.Node node)
Evaluates the specified xpath expression, base64 decodes the data and
returns the result as a ByteBuffer.
|
static java.nio.ByteBuffer |
asByteBuffer(java.lang.String expression,
org.w3c.dom.Node node,
javax.xml.xpath.XPath xpath)
Same as
asByteBuffer(String, Node) but allows an xpath to be
passed in explicitly for reuse. |
static java.util.Date |
asDate(java.lang.String expression,
org.w3c.dom.Node node)
Evaluates the specified XPath expression and returns the result as a
Date.
|
static java.util.Date |
asDate(java.lang.String expression,
org.w3c.dom.Node node,
javax.xml.xpath.XPath xpath)
Same as
asDate(String, Node) but allows an xpath to be passed
in explicitly for reuse. |
static java.lang.Double |
asDouble(java.lang.String expression,
org.w3c.dom.Node node)
Evaluates the specified XPath expression and returns the results as a
Double.
|
static java.lang.Double |
asDouble(java.lang.String expression,
org.w3c.dom.Node node,
javax.xml.xpath.XPath xpath)
Same as
asDouble(String, Node) but allows an xpath to be passed
in explicitly for reuse. |
static java.lang.Float |
asFloat(java.lang.String expression,
org.w3c.dom.Node node)
Evaluates the specified XPath expression and returns the result as a
Float.
|
static java.lang.Float |
asFloat(java.lang.String expression,
org.w3c.dom.Node node,
javax.xml.xpath.XPath xpath)
Same as
asFloat(String, Node) but allows an xpath to be passed
in explicitly for reuse. |
static java.lang.Integer |
asInteger(java.lang.String expression,
org.w3c.dom.Node node)
Evaluates the specified XPath expression and returns the result as an
Integer.
|
static java.lang.Integer |
asInteger(java.lang.String expression,
org.w3c.dom.Node node,
javax.xml.xpath.XPath xpath)
Same as
asInteger(String, Node) but allows an xpath to be passed
in explicitly for reuse. |
static java.lang.Long |
asLong(java.lang.String expression,
org.w3c.dom.Node node)
Evaluates the specified XPath expression and returns the result as a
Long.
|
static java.lang.Long |
asLong(java.lang.String expression,
org.w3c.dom.Node node,
javax.xml.xpath.XPath xpath)
Same as
asLong(String, Node) but allows an xpath to be passed
in explicitly for reuse. |
static org.w3c.dom.Node |
asNode(java.lang.String nodeName,
org.w3c.dom.Node node)
Evaluates the specified XPath expression and returns the result as a
Node.
|
static org.w3c.dom.Node |
asNode(java.lang.String nodeName,
org.w3c.dom.Node node,
javax.xml.xpath.XPath xpath)
Same as
asNode(String, Node) but allows an xpath to be
passed in explicitly for reuse. |
static java.lang.String |
asString(java.lang.String expression,
org.w3c.dom.Node node)
Evaluates the specified XPath expression and returns the result as a
string.
|
static java.lang.String |
asString(java.lang.String expression,
org.w3c.dom.Node node,
javax.xml.xpath.XPath xpath)
Same as
asString(String, Node) but allows an xpath to be passed
in explicitly for reuse. |
static org.w3c.dom.Document |
documentFrom(java.io.InputStream is)
This method closes the given input stream upon completion.
|
static org.w3c.dom.Document |
documentFrom(java.lang.String xml) |
static org.w3c.dom.Document |
documentFrom(java.net.URL url) |
private static java.lang.String |
evaluateAsString(java.lang.String expression,
org.w3c.dom.Node node,
javax.xml.xpath.XPath xpath)
Evaluates the specified expression on the specified node and returns the
result as a String.
|
static boolean |
isEmpty(org.w3c.dom.Node node)
Returns true if the specified node is null or has no children.
|
private static boolean |
isEmptyString(java.lang.String s)
Returns true if the specified string is null or empty.
|
static int |
nodeLength(org.w3c.dom.NodeList list)
Returns the length of the specified node list.
|
private static void |
speedUpDcoumentBuilderFactory()
Used to optimize performance by avoiding expensive file access every time
a DocumentBuilderFactory is constructed as a result of constructing a
Xalan document factory.
|
private static void |
speedUpDTMManager()
Used to optimize performance by avoiding expensive file access every time
a DTMManager is constructed as a result of constructing a Xalan xpath
context!
|
static javax.xml.xpath.XPath |
xpath()
Returns a new instance of XPath, which is not thread safe and not
reentrant.
|
private static final java.lang.String DTM_MANAGER_DEFAULT_PROP_NAME
private static final java.lang.String DOCUMENT_BUILDER_FACTORY_PROP_NAME
private static final java.lang.String DOCUMENT_BUILDER_FACTORY_IMPL_CLASS_NAME
private static final java.lang.String XPATH_CONTEXT_CLASS_NAME
private static final java.lang.String DTM_MANAGER_IMPL_CLASS_NAME
private static final org.apache.commons.logging.Log log
private static void speedUpDTMManager() throws java.lang.Exception
java.lang.Exception
private static void speedUpDcoumentBuilderFactory()
public static javax.xml.xpath.XPath xpath()
public static org.w3c.dom.Document documentFrom(java.io.InputStream is) throws org.xml.sax.SAXException, java.io.IOException, javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException
public static org.w3c.dom.Document documentFrom(java.lang.String xml) throws org.xml.sax.SAXException, java.io.IOException, javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException
public static org.w3c.dom.Document documentFrom(java.net.URL url) throws org.xml.sax.SAXException, java.io.IOException, javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
javax.xml.parsers.ParserConfigurationException
public static java.lang.Double asDouble(java.lang.String expression, org.w3c.dom.Node node) throws javax.xml.xpath.XPathExpressionException
This method can be expensive as a new xpath is instantiated per
invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)
instead. Note XPath
is
not thread-safe and not reentrant.
expression
- The XPath expression to evaluate.node
- The node to run the expression on.javax.xml.xpath.XPathExpressionException
- If there was a problem processing the specified XPath
expression.public static java.lang.Double asDouble(java.lang.String expression, org.w3c.dom.Node node, javax.xml.xpath.XPath xpath) throws javax.xml.xpath.XPathExpressionException
asDouble(String, Node)
but allows an xpath to be passed
in explicitly for reuse.javax.xml.xpath.XPathExpressionException
public static java.lang.String asString(java.lang.String expression, org.w3c.dom.Node node) throws javax.xml.xpath.XPathExpressionException
This method can be expensive as a new xpath is instantiated per
invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)
instead. Note XPath
is
not thread-safe and not reentrant.
expression
- The XPath expression to evaluate.node
- The node to run the expression on.javax.xml.xpath.XPathExpressionException
- If there was a problem processing the specified XPath
expression.public static java.lang.String asString(java.lang.String expression, org.w3c.dom.Node node, javax.xml.xpath.XPath xpath) throws javax.xml.xpath.XPathExpressionException
asString(String, Node)
but allows an xpath to be passed
in explicitly for reuse.javax.xml.xpath.XPathExpressionException
public static java.lang.Integer asInteger(java.lang.String expression, org.w3c.dom.Node node) throws javax.xml.xpath.XPathExpressionException
This method can be expensive as a new xpath is instantiated per
invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)
instead. Note XPath
is
not thread-safe and not reentrant.
expression
- The XPath expression to evaluate.node
- The node to run the expression on.javax.xml.xpath.XPathExpressionException
- If there was a problem processing the specified XPath
expression.public static java.lang.Integer asInteger(java.lang.String expression, org.w3c.dom.Node node, javax.xml.xpath.XPath xpath) throws javax.xml.xpath.XPathExpressionException
asInteger(String, Node)
but allows an xpath to be passed
in explicitly for reuse.javax.xml.xpath.XPathExpressionException
public static java.lang.Boolean asBoolean(java.lang.String expression, org.w3c.dom.Node node) throws javax.xml.xpath.XPathExpressionException
This method can be expensive as a new xpath is instantiated per
invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)
instead. Note XPath
is
not thread-safe and not reentrant.
expression
- The XPath expression to evaluate.node
- The node to run the expression on.javax.xml.xpath.XPathExpressionException
- If there was a problem processing the specified XPath
expression.public static java.lang.Boolean asBoolean(java.lang.String expression, org.w3c.dom.Node node, javax.xml.xpath.XPath xpath) throws javax.xml.xpath.XPathExpressionException
asBoolean(String, Node)
but allows an xpath to be passed
in explicitly for reuse.javax.xml.xpath.XPathExpressionException
public static java.lang.Float asFloat(java.lang.String expression, org.w3c.dom.Node node) throws javax.xml.xpath.XPathExpressionException
This method can be expensive as a new xpath is instantiated per
invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)
instead. Note XPath
is
not thread-safe and not reentrant.
expression
- The XPath expression to evaluate.node
- The node to run the expression on.javax.xml.xpath.XPathExpressionException
- If there was a problem processing the specified XPath
expression.public static java.lang.Float asFloat(java.lang.String expression, org.w3c.dom.Node node, javax.xml.xpath.XPath xpath) throws javax.xml.xpath.XPathExpressionException
asFloat(String, Node)
but allows an xpath to be passed
in explicitly for reuse.javax.xml.xpath.XPathExpressionException
public static java.lang.Long asLong(java.lang.String expression, org.w3c.dom.Node node) throws javax.xml.xpath.XPathExpressionException
This method can be expensive as a new xpath is instantiated per
invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)
instead. Note XPath
is
not thread-safe and not reentrant.
expression
- The XPath expression to evaluate.node
- The node to run the expression on.javax.xml.xpath.XPathExpressionException
- If there was a problem processing the specified XPath
expression.public static java.lang.Long asLong(java.lang.String expression, org.w3c.dom.Node node, javax.xml.xpath.XPath xpath) throws javax.xml.xpath.XPathExpressionException
asLong(String, Node)
but allows an xpath to be passed
in explicitly for reuse.javax.xml.xpath.XPathExpressionException
public static java.lang.Byte asByte(java.lang.String expression, org.w3c.dom.Node node) throws javax.xml.xpath.XPathExpressionException
This method can be expensive as a new xpath is instantiated per
invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)
instead. Note XPath
is
not thread-safe and not reentrant.
expression
- The XPath expression to evaluate.node
- The node to run the expression on.javax.xml.xpath.XPathExpressionException
- If there was a problem processing the specified XPath
expression.public static java.lang.Byte asByte(java.lang.String expression, org.w3c.dom.Node node, javax.xml.xpath.XPath xpath) throws javax.xml.xpath.XPathExpressionException
asByte(String, Node)
but allows an xpath to be passed
in explicitly for reuse.javax.xml.xpath.XPathExpressionException
public static java.util.Date asDate(java.lang.String expression, org.w3c.dom.Node node) throws javax.xml.xpath.XPathExpressionException
This method can be expensive as a new xpath is instantiated per
invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)
instead. Note XPath
is
not thread-safe and not reentrant.
expression
- The XPath expression to evaluate.node
- The node to run the expression on.javax.xml.xpath.XPathExpressionException
- If there was a problem processing the specified XPath
expression.public static java.util.Date asDate(java.lang.String expression, org.w3c.dom.Node node, javax.xml.xpath.XPath xpath) throws javax.xml.xpath.XPathExpressionException
asDate(String, Node)
but allows an xpath to be passed
in explicitly for reuse.javax.xml.xpath.XPathExpressionException
public static java.nio.ByteBuffer asByteBuffer(java.lang.String expression, org.w3c.dom.Node node) throws javax.xml.xpath.XPathExpressionException
This method can be expensive as a new xpath is instantiated per
invocation. Consider passing in the xpath explicitly via {
asDouble(String, Node, XPath)
instead. Note XPath
is
not thread-safe and not reentrant.
expression
- The Xpath expression to evaluate.node
- The node on which to evaluate the expression.javax.xml.xpath.XPathExpressionException
- If there are any problems evaluating the Xpath expression.public static java.nio.ByteBuffer asByteBuffer(java.lang.String expression, org.w3c.dom.Node node, javax.xml.xpath.XPath xpath) throws javax.xml.xpath.XPathExpressionException
asByteBuffer(String, Node)
but allows an xpath to be
passed in explicitly for reuse.javax.xml.xpath.XPathExpressionException
public static boolean isEmpty(org.w3c.dom.Node node)
node
- The node to test.public static org.w3c.dom.Node asNode(java.lang.String nodeName, org.w3c.dom.Node node) throws javax.xml.xpath.XPathExpressionException
nodeName
- The XPath expression to evaluate.node
- The node to run the expression on.javax.xml.xpath.XPathExpressionException
- If there was a problem processing the specified XPath
expression.public static org.w3c.dom.Node asNode(java.lang.String nodeName, org.w3c.dom.Node node, javax.xml.xpath.XPath xpath) throws javax.xml.xpath.XPathExpressionException
asNode(String, Node)
but allows an xpath to be
passed in explicitly for reuse.javax.xml.xpath.XPathExpressionException
public static int nodeLength(org.w3c.dom.NodeList list)
list
- The node list to measure.private static java.lang.String evaluateAsString(java.lang.String expression, org.w3c.dom.Node node, javax.xml.xpath.XPath xpath) throws javax.xml.xpath.XPathExpressionException
expression
- The Xpath expression to evaluate.node
- The node on which to evaluate the expression.javax.xml.xpath.XPathExpressionException
- If there are any problems evaluating the Xpath expression.private static boolean isEmptyString(java.lang.String s)
s
- The string to test.