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.cognifide.aet.job.common.datafilters.removenodes.RemoveNodesDataModifier.java

private void removeNodes(Document document) throws ProcessingException {
    try {/* www. j  av a 2s.  co  m*/
        NodeList nl = (NodeList) expr.evaluate(document, XPathConstants.NODESET);
        for (int i = 0; i < nl.getLength(); i++) {
            Node node = nl.item(i);
            node.getParentNode().removeChild(node);
        }
    } catch (XPathExpressionException e) {
        throw new ProcessingException(e.getMessage(), e);
    }
}

From source file:com.cognifide.aet.job.common.datafilters.removenodes.RemoveNodesDataModifier.java

@Override
public void setParameters(Map<String, String> params) throws ParametersException {
    if (params.containsKey(PARAM_XPATH)) {
        xpathString = params.get(PARAM_XPATH);
        XPathFactory xPathfactory = XPathFactory.newInstance();
        XPath xpath = xPathfactory.newXPath();
        try {// w w w.ja  v  a  2 s .c o m
            expr = xpath.compile(xpathString);
        } catch (XPathExpressionException e) {
            throw new ParametersException(e.getMessage(), e);
        }
    } else {
        throw new ParametersException("XPath must be provided");
    }

}

From source file:net.javacrumbs.springws.test.common.XPathExpressionEvaluator.java

public String evaluateExpression(Document document, String expression, URI uri,
        NamespaceContext namespaceContext) {
    XPathFactory factory = XPathFactory.newInstance();
    factory.setXPathVariableResolver(new WsTestXPathVariableResolver(uri));
    try {//from   w  ww.  ja v  a 2s . co  m
        XPath xpath = factory.newXPath();
        if (namespaceContext != null) {
            xpath.setNamespaceContext(namespaceContext);
        }
        String result = xpath.evaluate(expression, document);
        logger.debug("Expression \"" + expression + "\" resolved to \"" + result + "\"");
        return result;
    } catch (XPathExpressionException e) {
        throw new ExpressionResolverException(
                "Could not evaluate XPath expression \"" + expression + "\" : \"" + e.getMessage() + "\"", e);
    }
}

From source file:io.hakbot.providers.appspider.AppSpiderProvider.java

private String getScanName(String decodedScanConfig) {
    final XPathFactory xpathFactory = XPathFactory.newInstance();
    final XPath xpath = xpathFactory.newXPath();
    final InputSource source = new InputSource(new StringReader(decodedScanConfig));
    String scanName = null;//w ww  .j  av a  2s.  co m
    try {
        scanName = xpath.evaluate("/ScanConfig/Name", source);
    } catch (XPathExpressionException e) {
        LOGGER.error("Error processing scan file: " + e.getMessage());
    }
    return scanName;
}

From source file:hoot.services.controllers.wps.MarkItemsReviewedWpsTest.java

@Override
protected String verifyWpsResponse(final String responseStr) throws Exception {
    final Document responseData = XmlDocumentBuilder.parse(responseStr, false);
    Assert.assertNotNull(responseData);//from   ww  w  .  j  a  v a 2 s  .  c  o m
    System.out.println(XmlDocumentBuilder.toString(responseData));

    XPath xpath = XmlDocumentBuilder.createXPath();
    long changesetId = -1;
    try {
        Assert.assertEquals(processId, xpath.evaluate(".//Process/Identifier", responseData));
        NodeList returnedNodes = XPathAPI.selectNodeList(responseData, ".//ProcessOutputs/Output");
        Assert.assertEquals(3, returnedNodes.getLength());

        Assert.assertEquals("changesetUploadResponse",
                xpath.evaluate(".//ProcessOutputs/Output[1]/Identifier", responseData));
        Assert.assertEquals("string",
                xpath.evaluate(".//ProcessOutputs/Output[1]/Data/LiteralData/@dataType", responseData));
        final Document changesetResponse = XmlDocumentBuilder.parse(StringEscapeUtils
                .unescapeXml(xpath.evaluate(".//ProcessOutputs/Output[1]/Data/LiteralData", responseData)));
        Assert.assertNotNull(changesetResponse);
        //Changeset uploading is heavily tested in the OSM controller tests, so not testing that here;

        Assert.assertEquals("numItemsMarkedReviewed",
                xpath.evaluate(".//ProcessOutputs/Output[2]/Identifier", responseData));
        Assert.assertEquals("integer",
                xpath.evaluate(".//ProcessOutputs/Output[2]/Data/LiteralData/@dataType", responseData));
        Assert.assertEquals(5,
                Integer.parseInt(xpath.evaluate(".//ProcessOutputs/Output[2]/Data/LiteralData", responseData)));

        Assert.assertEquals("changesetId",
                xpath.evaluate(".//ProcessOutputs/Output[3]/Identifier", responseData));
        Assert.assertEquals("integer",
                xpath.evaluate(".//ProcessOutputs/Output[3]/Data/LiteralData/@dataType", responseData));
        changesetId = Integer
                .parseInt(xpath.evaluate(".//ProcessOutputs/Output[3]/Data/LiteralData", responseData));
        Assert.assertTrue(changesetId > -1);
    } catch (XPathExpressionException e) {
        Assert.fail("Error parsing response document: " + e.getMessage());
    }

    //verify the changeset data was written
    ReviewTestUtils.changesetId = changesetId;
    ReviewTestUtils.verifyDataMarkedAsReviewed(true);

    return null;
}

From source file:org.fedoracommons.funapi.pmh.AbstractPmhResolver.java

/**
 * {@inheritDoc}//from w ww.ja  v a2  s  .c o  m
 */
public UnapiFormats getFormats() throws UnapiException {
    String mdFormats = listMetadataFormats();
    UnapiFormats formats = new UnapiFormats(null);
    XPath xpath = getXPath();
    NodeList nodelist = null;
    try {
        nodelist = (NodeList) xpath.evaluate("//oai:metadataFormat",
                new InputSource(new StringReader(mdFormats)), XPathConstants.NODESET);
        for (int i = 0; i < nodelist.getLength(); i++) {
            Node node = nodelist.item(i);
            String format = xpath.evaluate("oai:metadataPrefix", node);
            String docs = xpath.evaluate("oai:schema", node);
            UnapiFormat uFormat = new UnapiFormat(format, "application/xml", docs);
            formats.addFormat(uFormat);
        }
    } catch (XPathExpressionException e) {
        throw new UnapiException(e.getMessage(), e);
    }
    return formats;
}

From source file:org.fedoracommons.funapi.pmh.AbstractPmhResolver.java

/**
 * {@inheritDoc}/*from  w  w w. j av a  2  s . c om*/
 */
public UnapiObject getObject(String id, String format) throws UnapiException {
    try {
        String record = getRecord(id, format);
        XPath xpath = getXPath();
        Node pmh = (Node) xpath.evaluate("//oai:OAI-PMH", new InputSource(new StringReader(record)),
                XPathConstants.NODE);

        Node metadata = (Node) xpath.evaluate("//oai:metadata/*", pmh, XPathConstants.NODE);

        if (metadata == null) {
            String error = xpath.evaluate("//oai:error/@code", pmh);
            if (error.equalsIgnoreCase("idDoesNotExist")) {
                throw new IdentifierException(error);
            } else if (error.equalsIgnoreCase("cannotDisseminateFormat")) {
                throw new FormatException(error);
            } else {
                throw new UnapiException(error);
            }
        }

        TransformerFactory xformFactory = TransformerFactory.newInstance();
        Transformer transformer = xformFactory.newTransformer();

        Source source = new DOMSource(metadata);
        StringWriter sw = new StringWriter();
        transformer.transform(source, new StreamResult(sw));
        InputStream in = new ByteArrayInputStream(sw.toString().getBytes("UTF-8"));
        return new UnapiObject(in, "application/xml");
    } catch (XPathExpressionException e) {
        throw new UnapiException(e.getMessage(), e);
    } catch (TransformerException e) {
        throw new UnapiException(e.getMessage(), e);
    } catch (UnsupportedEncodingException e) {
        throw new UnapiException(e.getMessage(), e);
    }
}

From source file:com.mnxfst.testing.server.cfg.PTestServerConfigurationParser.java

/**
 * Initializes the instance//from w ww  . java2  s  .  c  om
 */
public PTestServerConfigurationParser() {
    XPath xpath = XPathFactory.newInstance().newXPath();
    try {
        xpathExpressionHostname = xpath.compile(XPATH_HOSTNAME);
        xpathExpressionPort = xpath.compile(XPATH_PORT);
        xpathExpressionSocketPoolSize = xpath.compile(XPATH_SOCKET_POOL_SIZE);
        xpathExpressionAllHandlerSettings = xpath.compile(XPATH_ALL_HANDLER_SETTINGS);
        xpathExpressionHandlerClass = xpath.compile(XPATH_HANDLER_CLASS);
        xpathExpressionHandlerPath = xpath.compile(XPATH_HANDLER_PATH);
    } catch (XPathExpressionException e) {
        throw new RuntimeException(
                "Failed to create xpath expressions from preconfigured pattern. Error: " + e.getMessage());
    }
}

From source file:com.abiquo.nodecollector.domain.collectors.AbstractLibvirtCollector.java

@Override
public VirtualSystemCollectionDto getVirtualMachines() throws CollectorException {
    final VirtualSystemCollectionDto vmc = new VirtualSystemCollectionDto();
    final List<Domain> listOfDomains = new ArrayList<Domain>();

    try {//from w ww . j av  a2 s.  c  o m
        // Defined domains are the closed ones!
        for (String domainValue : connection.listDefinedDomains()) {
            if (domainValue != null) // Why null domains are returned?
            {
                listOfDomains.add(connection.domainLookupByName(domainValue));
            }
        }
        // Domains are the started ones
        for (int domainInt : connection.listDomains()) {
            listOfDomains.add(connection.domainLookupByID(domainInt));
        }

        // Create the list of Virtual Systems from the recovered domains
        for (Domain domain : listOfDomains) {
            if (!isDomain0(domain)) {
                vmc.getVirtualSystems().add(createVirtualSystemFromDomain(domain));
            }
        }
    } catch (LibvirtException e1) {
        LOGGER.error("Unhandled exception :", e1);
        throw new CollectorException(e1.getMessage(), e1);
    } catch (XPathExpressionException e) {
        LOGGER.error("Unhandled exception :", e);
        throw new CollectorException(e.getMessage(), e);
    }

    return vmc;
}

From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileT.java

@SuppressWarnings("unchecked")
protected void extendSignatureTag(Element signatureEl, Document originalData, SignatureFormat signatureFormat) {

    try {// w w  w .  j a v a2  s  . co  m

        Element qualifyingProperties = XMLUtils.getElement(signatureEl,
                "./ds:Object/xades:QualifyingProperties");
        Element unsignedPropertiesNode = XMLUtils.getElement(qualifyingProperties,
                "./xades:UnsignedProperties");

        UnsignedPropertiesType unsignedPropertiesType = null;
        if (unsignedPropertiesNode != null) {
            unsignedPropertiesType = ((JAXBElement<UnsignedPropertiesType>) unmarshaller
                    .unmarshal(unsignedPropertiesNode)).getValue();
        } else {
            unsignedPropertiesType = xadesObjectFactory.createUnsignedPropertiesType();
        }

        extendSignatureTag(signatureEl, unsignedPropertiesType, signatureFormat);

        if (unsignedPropertiesNode != null) {
            qualifyingProperties.removeChild(unsignedPropertiesNode);
        }
        marshaller.marshal(xadesObjectFactory.createUnsignedProperties(unsignedPropertiesType),
                qualifyingProperties);
    } catch (XPathExpressionException e) {
        throw new RuntimeException(e);

    } catch (JAXBException e) {
        throw new RuntimeException("JAXB error: " + e.getMessage(), e);

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}