Example usage for javax.xml.xpath XPathExpressionException getMessage

List of usage examples for javax.xml.xpath XPathExpressionException getMessage

Introduction

In this page you can find the example usage for javax.xml.xpath XPathExpressionException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.cloud.hypervisor.kvm.resource.LibvirtComputingResourceTest.java

static void assertXpath(final Document doc, final String xPathExpr, final String expected) {
    try {//from   w w w .j a v  a  2s .  c  om
        Assert.assertEquals(expected, XPathFactory.newInstance().newXPath().evaluate(xPathExpr, doc));
    } catch (final XPathExpressionException e) {
        Assert.fail("Could not evaluate xpath" + xPathExpr + ":" + e.getMessage());
    }
}

From source file:org.ala.documentmapper.XMLDocumentMapper.java

/**
 * Map the property using the xpath mapping supplied.
 * /*  ww w  .j  a  v a 2  s .c o m*/
 * @param document
 * @param parsedDoc
 * @param isDublinCore
 * @param xpath
 * @param mapping
 */
private void performXPathMapping(Document document, ParsedDocument parsedDoc, boolean isDublinCore, XPath xpath,
        Mapping mapping) {
    try {

        NodeList nodes = (NodeList) xpath.evaluate(mapping.getQueryString(), document, XPathConstants.NODESET);

        for (int i = 0; i < nodes.getLength(); i++) {

            String value = extractValue(nodes.item(i));
            if (value != null) {

                if (mapping.isGuid) {
                    parsedDoc.setGuid(value);
                }
                //create the triples
                createTriples(parsedDoc, isDublinCore, mapping, value);
            }
        }
    } catch (XPathExpressionException e) {
        //throw new Exception("Failed to extract XPath property: "+ e.getMessage(), e);
        // To handle the XPATH expressions which don't represent a nodelist. 
        String value;
        try {
            value = trim(xpath.evaluate(mapping.getQueryString(), document));
            if (value != null || !"".equals(value)) {
                value = value.replaceAll("[\\s&&[^ ]]{1,}", "");
                value = value.replaceAll("[ ]{2,}", " ");
                //create the triples
                createTriples(parsedDoc, isDublinCore, mapping, value);
            }
        } catch (XPathExpressionException e1) {
            logger.warn(e.getMessage(), e);
        }
    }
}

From source file:org.alfresco.repo.content.metadata.xml.XPathMetadataExtracter.java

/**
 * A utility method to convert mapping properties to the Map form.
 * /*  w w  w. jav a2  s. c o  m*/
 * @see #setMappingProperties(Properties)
 */
@SuppressWarnings("rawtypes")
protected void readXPathMappingProperties(Properties xpathMappingProperties) {
    // Get the namespaces
    for (Map.Entry entry : xpathMappingProperties.entrySet()) {
        String propertyName = (String) entry.getKey();
        if (propertyName.startsWith("namespace.prefix.")) {
            String prefix = propertyName.substring(17);
            String namespace = (String) entry.getValue();
            namespacesByPrefix.put(prefix, namespace);
        }
    }
    // Create the mapping
    for (Map.Entry entry : xpathMappingProperties.entrySet()) {
        String documentProperty = (String) entry.getKey();
        String xpathStr = (String) entry.getValue();
        if (documentProperty.startsWith(NAMESPACE_PROPERTY_PREFIX)) {
            // Ignore these now
            continue;
        }
        // Construct the XPath
        XPath xpath = xpathFactory.newXPath();
        xpath.setNamespaceContext(this);
        XPathExpression xpathExpression = null;
        try {
            xpathExpression = xpath.compile(xpathStr);
        } catch (XPathExpressionException e) {
            throw new AlfrescoRuntimeException(
                    "\n" + "Failed to create XPath expression: \n" + "   Document property: " + documentProperty
                            + "\n" + "   XPath:             " + xpathStr + "\n" + "   Error: " + e.getMessage(),
                    e);
        }
        // Persist it
        xpathExpressionMapping.put(documentProperty, xpathExpression);
        if (logger.isDebugEnabled()) {
            logger.debug("Added mapping from " + documentProperty + " to " + xpathStr);
        }
    }
    // Done
}

From source file:org.apache.ode.bpel.compiler.v1.xpath10.jaxp.JaxpXPath10ExpressionCompilerImpl.java

/**
 * Verifies validity of a xpath expression.
 *///from  w  w w. ja v  a 2s  .co  m
protected void doJaxpCompile(OXPath10Expression out, Expression source) throws CompilationException {
    String xpathStr;
    Node node = source.getExpression();
    if (node == null) {
        throw new IllegalStateException("XPath string and xpath node are both null");
    }

    xpathStr = node.getNodeValue();
    xpathStr = xpathStr.trim();
    if (xpathStr.length() == 0) {
        throw new CompilationException(__msgs.errXPathSyntax(xpathStr));
    }

    try {
        __log.debug("JAXP compile: xpath = " + xpathStr);
        // use default XPath implementation
        XPathFactory xpf = XPathFactory.newInstance();
        __log.debug("JAXP compile: XPathFactory impl = " + xpf.getClass());
        XPath xpath = xpf.newXPath();
        xpath.setXPathFunctionResolver(
                new JaxpFunctionResolver(_compilerContext, out, source.getNamespaceContext(), _bpelNsURI));
        xpath.setXPathVariableResolver(new JaxpVariableResolver(_compilerContext, out));
        xpath.setNamespaceContext(source.getNamespaceContext());
        XPathExpression xpe = xpath.compile(xpathStr);
        // dummy evaluation to resolve variables and functions (hopefully complete...)
        xpe.evaluate(DOMUtils.newDocument());
        out.xpath = xpathStr;
    } catch (XPathExpressionException e) {
        throw new CompilationException(__msgs.errUnexpectedCompilationError(e.getMessage()), e);
    }
}

From source file:org.apache.solr.core.SolrXmlConfig.java

private static Properties loadProperties(Config config) {
    try {//from www  .  jav  a 2s. c o m
        Node node = ((NodeList) config.evaluate("solr", XPathConstants.NODESET)).item(0);
        XPath xpath = config.getXPath();
        NodeList props = (NodeList) xpath.evaluate("property", node, XPathConstants.NODESET);
        Properties properties = new Properties();
        for (int i = 0; i < props.getLength(); i++) {
            Node prop = props.item(i);
            properties.setProperty(DOMUtil.getAttr(prop, NAME),
                    PropertiesUtil.substituteProperty(DOMUtil.getAttr(prop, "value"), null));
        }
        return properties;
    } catch (XPathExpressionException e) {
        log.warn("Error parsing solr.xml: " + e.getMessage());
        return null;
    }
}

From source file:org.asimba.wa.integrationtest.saml2.model.Assertion.java

private void parseAttributes() {
    String xpathQuery = "/saml2p:Response/saml2:Assertion/saml2:AttributeStatement/saml2:Attribute";

    if (_responseDocument == null) {
        _logger.error("No document specified.");
        return;//  ww w .jav  a  2 s.  c om
    }

    Map<String, String> attributeMap = new HashMap<>();

    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(new SimpleSAMLNamespaceContext(null));

    try {
        NodeList nodes = (NodeList) xpath.compile(xpathQuery).evaluate(_responseDocument,
                XPathConstants.NODESET);
        if (nodes != null) {
            for (int i = 0; i < nodes.getLength(); i++) {
                // get value of @Name attribute
                Node n = nodes.item(i);

                String name = n.getAttributes().getNamedItem("Name").getNodeValue();

                // get the first AttributeValue childnode
                NodeList valueNodes = n.getChildNodes();
                for (int ci = 0; ci < valueNodes.getLength(); ci++) {
                    Node cn = valueNodes.item(ci);
                    String nodename = cn.getLocalName();
                    if ("AttributeValue".equals(nodename)) {
                        String value = cn.getTextContent().trim();
                        attributeMap.put(name, value);
                    }
                }
            }
        }
    } catch (XPathExpressionException e) {
        _logger.error("Exception when getting attributes: {}", e.getMessage(), e);
        return;
    }

    _responseAttributes = attributeMap;
}

From source file:org.asimba.wa.integrationtest.saml2.model.Assertion.java

public Node getAssertionNode() {
    if (_responseDocument == null)
        return null;

    String xpathQuery = "/saml2p:Response/saml2:Assertion";

    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(new SimpleSAMLNamespaceContext(null));

    try {/*from  w ww .ja  v a2s . c o m*/
        return (Node) xpath.compile(xpathQuery).evaluate(_responseDocument, XPathConstants.NODE);
    } catch (XPathExpressionException e) {
        _logger.error("Exception when processing XPath Query: {}", e.getMessage(), e);
        return null;
    }

}

From source file:org.asqatasun.processing.ProcessRemarkServiceImpl.java

/**
 * This methods search the line where the current node is present in
 * the source code/* w w  w .  j  a v  a  2s  .c o  m*/
 * @param node
 * @return
 */
private int getNodeIndex(Node node) {
    try {
        XPathExpression xPathExpression = xpath.compile("//" + node.getNodeName().toUpperCase());
        Object result = xPathExpression.evaluate(document, XPathConstants.NODESET);
        NodeList nodeList = (NodeList) result;
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node current = nodeList.item(i);
            if (current.equals(node)) {
                return i;
            }
        }
    } catch (XPathExpressionException ex) {
        LOGGER.error("Error occured while searching index of a node " + ex.getMessage());
        throw new RuntimeException(ex);
    }
    return -1;
}

From source file:org.asqatasun.processor.DOMHandlerImpl.java

/**
 * @deprecated Kept for backward compatibility.
 * @param expr/*  w w  w. ja va  2s. co m*/
 * @return
 */
@Override
@Deprecated
public TestSolution checkEachWithXpath(String expr) {
    Collection<TestSolution> resultSet = new ArrayList<TestSolution>();
    for (Node node : selectedElementList) {
        TestSolution tempResult = TestSolution.PASSED;
        try {
            XPathExpression xPathExpression = xpath.compile(expr);
            Boolean check = (Boolean) xPathExpression.evaluate(node, XPathConstants.BOOLEAN);
            if (!check.booleanValue()) {
                tempResult = TestSolution.FAILED;
                // addSourceCodeRemark(result, node,
                // "wrong value, does not respect xpath expression : " +
                // expr, node.getNodeValue());
            }
        } catch (XPathExpressionException ex) {
            LOGGER.error(ex.getMessage() + " occured requesting " + expr + " on " + ssp.getURI());
            throw new RuntimeException(ex);
        }
        resultSet.add(tempResult);
    }
    return RuleHelper.synthesizeTestSolutionCollection(resultSet);
}

From source file:org.cruxframework.crux.core.declarativeui.ViewParser.java

/**
 * @param cruxPageDocument//  ww  w  .  jav a2s.co m
 * @return
 * @throws ViewParserException
 */
private Element getPageBodyElement(Document cruxPageDocument) throws ViewParserException {
    try {
        NodeList bodyNodes = (NodeList) findCruxPagesBodyExpression.evaluate(cruxPageDocument,
                XPathConstants.NODESET);
        if (bodyNodes.getLength() > 0) {
            return (Element) bodyNodes.item(0);
        }
        Element bodyElement = cruxPageDocument.createElementNS(XHTML_NAMESPACE, "body");
        cruxPageDocument.getDocumentElement().appendChild(bodyElement);
        return bodyElement;
    } catch (XPathExpressionException e) {
        throw new ViewParserException(e.getMessage(), e);
    }
}