use of javax.xml.xpath.XPathFactoryConfigurationException in project santuario-java by apache.
the class JDKXPathAPI method evaluate.
/**
* Evaluate an XPath string and return true if the output is to be included or not.
* @param contextNode The node to start searching from.
* @param xpathnode The XPath node
* @param str The XPath expression
* @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
*/
public boolean evaluate(Node contextNode, Node xpathnode, String str, Node namespaceNode) throws TransformerException {
if (!str.equals(xpathStr) || xpathExpression == null) {
if (xpf == null) {
xpf = XPathFactory.newInstance();
try {
xpf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
} catch (XPathFactoryConfigurationException ex) {
throw new TransformerException(ex);
}
}
XPath xpath = xpf.newXPath();
xpath.setNamespaceContext(new DOMNamespaceContext(namespaceNode));
xpathStr = str;
try {
xpathExpression = xpath.compile(xpathStr);
} catch (XPathExpressionException ex) {
throw new TransformerException(ex);
}
}
try {
return (Boolean) xpathExpression.evaluate(contextNode, XPathConstants.BOOLEAN);
} catch (XPathExpressionException ex) {
throw new TransformerException(ex);
}
}
use of javax.xml.xpath.XPathFactoryConfigurationException in project santuario-java by apache.
the class JDKXPathAPI method selectNodeList.
/**
* Use an XPath string to select a nodelist.
* XPath namespace prefixes are resolved from the namespaceNode.
*
* @param contextNode The node to start searching from.
* @param xpathnode
* @param str
* @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
* @return A NodeIterator, should never be null.
*
* @throws TransformerException
*/
public NodeList selectNodeList(Node contextNode, Node xpathnode, String str, Node namespaceNode) throws TransformerException {
if (!str.equals(xpathStr) || xpathExpression == null) {
if (xpf == null) {
xpf = XPathFactory.newInstance();
try {
xpf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
} catch (XPathFactoryConfigurationException ex) {
throw new TransformerException(ex);
}
}
XPath xpath = xpf.newXPath();
xpath.setNamespaceContext(new DOMNamespaceContext(namespaceNode));
xpathStr = str;
try {
xpathExpression = xpath.compile(xpathStr);
} catch (XPathExpressionException ex) {
throw new TransformerException(ex);
}
}
try {
return (NodeList) xpathExpression.evaluate(contextNode, XPathConstants.NODESET);
} catch (XPathExpressionException ex) {
throw new TransformerException(ex);
}
}
Aggregations