Search in sources :

Example 91 with XPath

use of javax.xml.xpath.XPath in project jangaroo-tools by CoreMedia.

the class PomConverter method addDependencyType.

public void addDependencyType(String dependencyType) throws MojoExecutionException {
    try {
        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xPath = xPathFactory.newXPath();
        NodeList dependencyNodes = (NodeList) xPath.evaluate("/project/dependencies/dependency", document, NODESET);
        for (int i = 0; i < dependencyNodes.getLength(); i++) {
            Node dependencyNode = dependencyNodes.item(i);
            Element typeNode = document.createElement("type");
            typeNode.appendChild(document.createTextNode(dependencyType));
            insertChildWithWhitespace(dependencyNode, typeNode, null);
        }
    } catch (XPathException e) {
        throw new MojoExecutionException("error while trying to add dependency type to POM", e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) XPathException(javax.xml.xpath.XPathException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 92 with XPath

use of javax.xml.xpath.XPath in project verify-hub by alphagov.

the class SoapMessageManager method unwrapSoapMessage.

public Element unwrapSoapMessage(Element soapElement) {
    XPath xpath = XPathFactory.newInstance().newXPath();
    NamespaceContextImpl context = new NamespaceContextImpl();
    context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
    context.startPrefixMapping("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
    context.startPrefixMapping("ds", "http://www.w3.org/2000/09/xmldsig#");
    xpath.setNamespaceContext(context);
    try {
        final String expression = "/soapenv:Envelope/soapenv:Body/samlp:Response";
        Element element = (Element) xpath.evaluate(expression, soapElement, XPathConstants.NODE);
        if (element == null) {
            String errorMessage = format("Document{0}{1}{0}does not have element {2} inside it.", NEW_LINE, writeToString(soapElement), expression);
            LOG.error(errorMessage);
            throw new IllegalArgumentException(errorMessage);
        }
        return element;
    } catch (XPathExpressionException e) {
        throw propagate(e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NamespaceContextImpl(org.apache.ws.commons.util.NamespaceContextImpl) Element(org.w3c.dom.Element) XmlUtils.writeToString(uk.gov.ida.shared.utils.xml.XmlUtils.writeToString)

Example 93 with XPath

use of javax.xml.xpath.XPath in project verify-hub by alphagov.

the class SoapMessageManagerTest method getAttributeQuery.

private Element getAttributeQuery(Document document) throws XPathExpressionException {
    XPath xpath = XPathFactory.newInstance().newXPath();
    NamespaceContextImpl context = new NamespaceContextImpl();
    context.startPrefixMapping("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
    context.startPrefixMapping("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
    xpath.setNamespaceContext(context);
    return (Element) xpath.evaluate("//samlp:Response", document, XPathConstants.NODE);
}
Also used : XPath(javax.xml.xpath.XPath) NamespaceContextImpl(org.apache.ws.commons.util.NamespaceContextImpl) Element(org.w3c.dom.Element)

Example 94 with XPath

use of javax.xml.xpath.XPath in project oxTrust by GluuFederation.

the class AsimbaXMLConfigurationService method parse.

/**
 * Parse Asimba XML configuration file.
 */
private void parse() {
    try {
        // check for asimba config availability
        File configFile = new File(getConfigurationFilePath());
        if (!configFile.exists())
            return;
        // parse XML
        Document document = xmlService.getXmlDocument(FileUtils.readFileToByteArray(configFile));
        XPath xPath = XPathFactory.newInstance().newXPath();
        keystoreFilePath = xPath.evaluate("/asimba-server/crypto/signing/signingfactory/keystore/file", document);
        log.info("AsimbaXMLConfig keystoreFilePath: " + keystoreFilePath);
        keystoreType = xPath.evaluate("/asimba-server/crypto/signing/signingfactory/keystore/type", document);
        if (keystoreType == null || "".equals(keystoreType))
            keystoreType = KeyStore.getDefaultType();
        log.info("AsimbaXMLConfig keystoreType: " + keystoreType);
        keystorePassword = xPath.evaluate("/asimba-server/crypto/signing/signingfactory/keystore/keystore_password", document);
        asimbaAias = xPath.evaluate("/asimba-server/crypto/signing/signingfactory/keystore/alias", document);
        asimbaAiasPassword = xPath.evaluate("/asimba-server/crypto/signing/signingfactory/keystore/password", document);
    } catch (Exception e) {
        log.error("parse() exception", e);
        keystoreFilePath = null;
        keystoreType = null;
        asimbaAias = null;
        asimbaAiasPassword = null;
    }
}
Also used : XPath(javax.xml.xpath.XPath) Document(org.w3c.dom.Document) File(java.io.File) UploadedFile(org.richfaces.model.UploadedFile) IOException(java.io.IOException)

Example 95 with XPath

use of javax.xml.xpath.XPath in project cayenne by apache.

the class DefaultUpgradeService method getAdditionalDatamapResources.

List<Resource> getAdditionalDatamapResources(UpgradeUnit upgradeUnit) {
    List<Resource> resources = new ArrayList<>();
    try {
        XPath xpath = XPathFactory.newInstance().newXPath();
        NodeList nodes = (NodeList) xpath.evaluate("/domain/map/@name", upgradeUnit.getDocument(), XPathConstants.NODESET);
        for (int i = 0; i < nodes.getLength(); i++) {
            Node mapNode = nodes.item(i);
            // in version 3.0.0.1 and earlier map tag had attribute location,
            // but it was always equal to data map name + ".map.xml"
            Resource mapResource = upgradeUnit.getResource().getRelativeResource(mapNode.getNodeValue() + ".map.xml");
            resources.add(mapResource);
        }
    } catch (Exception ex) {
        logger.warn("Can't get additional dataMap resources: ", ex);
    }
    return resources;
}
Also used : XPath(javax.xml.xpath.XPath) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Resource(org.apache.cayenne.resource.Resource) ArrayList(java.util.ArrayList) SAXException(org.xml.sax.SAXException) ConfigurationException(org.apache.cayenne.ConfigurationException)

Aggregations

XPath (javax.xml.xpath.XPath)526 Document (org.w3c.dom.Document)254 NodeList (org.w3c.dom.NodeList)230 XPathFactory (javax.xml.xpath.XPathFactory)215 Node (org.w3c.dom.Node)171 XPathExpressionException (javax.xml.xpath.XPathExpressionException)159 XPathExpression (javax.xml.xpath.XPathExpression)142 DocumentBuilder (javax.xml.parsers.DocumentBuilder)125 Element (org.w3c.dom.Element)118 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)97 IOException (java.io.IOException)89 Test (org.junit.Test)80 InputSource (org.xml.sax.InputSource)59 File (java.io.File)57 SAXException (org.xml.sax.SAXException)57 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)51 ByteArrayInputStream (java.io.ByteArrayInputStream)44 ArrayList (java.util.ArrayList)44 InputStream (java.io.InputStream)39 DSNamespaceContext (org.apache.xml.security.test.dom.DSNamespaceContext)37