Search in sources :

Example 96 with XPath

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

the class UpgradeHandler_V7 method processProjectDom.

@Override
public void processProjectDom(UpgradeUnit upgradeUnit) {
    Element domain = upgradeUnit.getDocument().getDocumentElement();
    domain.setAttribute("project-version", getVersion());
    XPath xpath = XPathFactory.newInstance().newXPath();
    Node node;
    try {
        node = (Node) xpath.evaluate("/domain/property[@name='cayenne.DataDomain.usingExternalTransactions']", upgradeUnit.getDocument(), XPathConstants.NODE);
    } catch (Exception ex) {
        return;
    }
    if (node != null) {
        domain.removeChild(node);
    }
}
Also used : XPath(javax.xml.xpath.XPath) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node)

Example 97 with XPath

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

the class Shibboleth3ConfService method isFederationMetadata.

public boolean isFederationMetadata(String spMetaDataFN) {
    if (spMetaDataFN == null) {
        return false;
    }
    File spMetaDataFile = new File(getSpMetadataFilePath(spMetaDataFN));
    InputStream is = null;
    InputStreamReader isr = null;
    Document xmlDocument = null;
    try {
        is = FileUtils.openInputStream(spMetaDataFile);
        isr = new InputStreamReader(is, "UTF-8");
        try {
            xmlDocument = xmlService.getXmlDocument(new InputSource(isr));
        } catch (Exception ex) {
            log.error("Failed to parse metadata file '{}'", spMetaDataFile.getAbsolutePath(), ex);
            ex.printStackTrace();
        }
    } catch (IOException ex) {
        log.error("Failed to read metadata file '{}'", spMetaDataFile.getAbsolutePath(), ex);
        ex.printStackTrace();
    } finally {
        IOUtils.closeQuietly(isr);
        IOUtils.closeQuietly(is);
    }
    if (xmlDocument == null) {
        return false;
    }
    XPathFactory factory = XPathFactory.newInstance();
    XPath xPath = factory.newXPath();
    String federationTag = null;
    try {
        federationTag = xPath.compile("count(//*[local-name() = 'EntitiesDescriptor'])").evaluate(xmlDocument);
    } catch (XPathExpressionException ex) {
        log.error("Failed to find IDP metadata file in relaying party file '{}'", spMetaDataFile.getAbsolutePath(), ex);
        ex.printStackTrace();
    }
    return Integer.parseInt(federationTag) > 0;
}
Also used : XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SubversionFile(org.gluu.oxtrust.model.SubversionFile) File(java.io.File) InvalidConfigurationException(org.xdi.util.exception.InvalidConfigurationException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) EncryptionException(org.xdi.util.security.StringEncrypter.EncryptionException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 98 with XPath

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

the class Response method getAttributes.

public Map<String, List<String>> getAttributes() throws XPathExpressionException {
    Map<String, List<String>> result = new HashMap<String, List<String>>();
    XPath xPath = XPathFactory.newInstance().newXPath();
    xPath.setNamespaceContext(NAMESPACES);
    XPathExpression query = xPath.compile("/samlp:Response/saml:Assertion/saml:AttributeStatement/saml:Attribute");
    NodeList nodes = (NodeList) query.evaluate(xmlDoc, XPathConstants.NODESET);
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        Node nameNode = node.getAttributes().getNamedItem("Name");
        if (nameNode == null) {
            continue;
        }
        String attributeName = nameNode.getNodeValue();
        List<String> attributeValues = new ArrayList<String>();
        NodeList nameChildNodes = node.getChildNodes();
        for (int j = 0; j < nameChildNodes.getLength(); j++) {
            Node nameChildNode = nameChildNodes.item(j);
            if ("urn:oasis:names:tc:SAML:2.0:assertion".equalsIgnoreCase(nameChildNode.getNamespaceURI()) && "AttributeValue".equals(nameChildNode.getLocalName())) {
                NodeList valueChildNodes = nameChildNode.getChildNodes();
                for (int k = 0; k < valueChildNodes.getLength(); k++) {
                    Node valueChildNode = valueChildNodes.item(k);
                    attributeValues.add(valueChildNode.getNodeValue());
                }
            }
        }
        result.put(attributeName, attributeValues);
    }
    return result;
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Example 99 with XPath

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

the class Response method isAuthnFailed.

public boolean isAuthnFailed() throws Exception {
    XPath xPath = XPathFactory.newInstance().newXPath();
    xPath.setNamespaceContext(NAMESPACES);
    XPathExpression query = xPath.compile("/samlp:Response/samlp:Status/samlp:StatusCode");
    NodeList nodes = (NodeList) query.evaluate(xmlDoc, XPathConstants.NODESET);
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node.getAttributes().getNamedItem("Value") == null) {
            continue;
        }
        String statusCode = node.getAttributes().getNamedItem("Value").getNodeValue();
        if (SAML_RESPONSE_STATUS_SUCCESS.equalsIgnoreCase(statusCode)) {
            return false;
        } else if (SAML_RESPONSE_STATUS_AUTHNFAILED.equalsIgnoreCase(statusCode)) {
            return true;
        } else if (SAML_RESPONSE_STATUS_RESPONDER.equalsIgnoreCase(statusCode)) {
            // nothing?
            continue;
        }
    }
    return false;
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node)

Example 100 with XPath

use of javax.xml.xpath.XPath in project knime-core by knime.

the class AbstractInjector method run.

/**
 * {@inheritDoc}
 */
@Override
public final void run() {
    try {
        prepareData();
        m_introFileLock.lock();
        try {
            DocumentBuilder parser = m_parserFactory.newDocumentBuilder();
            parser.setEntityResolver(EmptyDoctypeResolver.INSTANCE);
            Document doc = parser.parse(m_templateFile);
            XPath xpath = m_xpathFactory.newXPath();
            injectData(doc, xpath);
            processIntroProperties(doc, xpath);
            writeFile(doc);
            refreshIntroEditor();
        } finally {
            m_introFileLock.unlock();
        }
    } catch (Exception ex) {
        NodeLogger.getLogger(getClass()).warn("Could not modify intro page: " + ex.getMessage(), ex);
    }
}
Also used : XPath(javax.xml.xpath.XPath) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Document(org.w3c.dom.Document) XPathExpressionException(javax.xml.xpath.XPathExpressionException) TransformerException(javax.xml.transform.TransformerException) PartInitException(org.eclipse.ui.PartInitException) AssertionFailedException(org.eclipse.core.runtime.AssertionFailedException) IOException(java.io.IOException)

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