Search in sources :

Example 11 with XPathFactoryConfigurationException

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);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) XPathFactoryConfigurationException(javax.xml.xpath.XPathFactoryConfigurationException) TransformerException(javax.xml.transform.TransformerException)

Example 12 with XPathFactoryConfigurationException

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);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) XPathFactoryConfigurationException(javax.xml.xpath.XPathFactoryConfigurationException) TransformerException(javax.xml.transform.TransformerException)

Aggregations

XPathExpressionException (javax.xml.xpath.XPathExpressionException)12 XPathFactoryConfigurationException (javax.xml.xpath.XPathFactoryConfigurationException)12 XPath (javax.xml.xpath.XPath)7 TransformerException (javax.xml.transform.TransformerException)4 NodeList (org.w3c.dom.NodeList)4 XPathExpression (javax.xml.xpath.XPathExpression)3 XPathFactory (javax.xml.xpath.XPathFactory)3 IOException (java.io.IOException)2 URL (java.net.URL)2 AllPermission (java.security.AllPermission)2 Policy (java.security.Policy)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Test (org.junit.Test)2 Node (org.w3c.dom.Node)2 SAXException (org.xml.sax.SAXException)2 Iterator (java.util.Iterator)1 NamespaceContext (javax.xml.namespace.NamespaceContext)1 XPathFunctionException (javax.xml.xpath.XPathFunctionException)1 XPathFunctionResolver (javax.xml.xpath.XPathFunctionResolver)1 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)1