Search in sources :

Example 86 with DOMException

use of org.w3c.dom.DOMException in project Lucee by lucee.

the class XMLElementStruct method setIdAttributeNS.

// used only with java 7, do not set @Override
public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) throws DOMException {
    // dynamic load to support jre 1.4 and 1.5
    try {
        Method m = element.getClass().getMethod("setIdAttributeNS", new Class[] { namespaceURI.getClass(), localName.getClass(), boolean.class });
        m.invoke(element, new Object[] { namespaceURI, localName, Caster.toBoolean(isId) });
    } catch (Exception e) {
        throw new PageRuntimeException(Caster.toPageException(e));
    }
}
Also used : Method(java.lang.reflect.Method) PageRuntimeException(lucee.runtime.exp.PageRuntimeException) DOMException(org.w3c.dom.DOMException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Example 87 with DOMException

use of org.w3c.dom.DOMException in project keycloak by keycloak.

the class SubsystemParsingAllowedClockSkewTestCase method setSubsystemXml.

private void setSubsystemXml(String value, String unit) throws IOException {
    try {
        String template = readResource("keycloak-saml-1.4.xml");
        if (value != null) {
            // assign the AllowedClockSkew element using DOM
            DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = db.parse(new InputSource(new StringReader(template)));
            // create the skew element
            Element allowedClockSkew = doc.createElement(Constants.XML.ALLOWED_CLOCK_SKEW);
            if (unit != null) {
                allowedClockSkew.setAttribute(Constants.XML.ALLOWED_CLOCK_SKEW_UNIT, unit);
            }
            allowedClockSkew.setTextContent(value);
            // locate the IDP and insert the node
            XPath xPath = XPathFactory.newInstance().newXPath();
            NodeList nodeList = (NodeList) xPath.compile("/subsystem/secure-deployment[1]/SP/IDP").evaluate(doc, XPathConstants.NODESET);
            nodeList.item(0).appendChild(allowedClockSkew);
            // transform again to XML
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            StringWriter writer = new StringWriter();
            transformer.transform(new DOMSource(doc), new StreamResult(writer));
            subsystemXml = writer.getBuffer().toString();
        } else {
            subsystemXml = template;
        }
    } catch (DOMException | ParserConfigurationException | SAXException | TransformerException | XPathExpressionException e) {
        throw new IOException(e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) XPathExpressionException(javax.xml.xpath.XPathExpressionException) PathElement(org.jboss.as.controller.PathElement) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) DOMException(org.w3c.dom.DOMException) StringWriter(java.io.StringWriter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerException(javax.xml.transform.TransformerException)

Example 88 with DOMException

use of org.w3c.dom.DOMException in project keycloak by keycloak.

the class SubsystemParsingAllowedClockSkewTestCase method setSubsystemXml.

private void setSubsystemXml(String value, String unit) throws IOException {
    try {
        String template = readResource("keycloak-saml-1.4.xml");
        if (value != null) {
            // assign the AllowedClockSkew element using DOM
            DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = db.parse(new InputSource(new StringReader(template)));
            // create the skew element
            Element allowedClockSkew = doc.createElement(Constants.XML.ALLOWED_CLOCK_SKEW);
            if (unit != null) {
                allowedClockSkew.setAttribute(Constants.XML.ALLOWED_CLOCK_SKEW_UNIT, unit);
            }
            allowedClockSkew.setTextContent(value);
            // locate the IDP and insert the node
            XPath xPath = XPathFactory.newInstance().newXPath();
            NodeList nodeList = (NodeList) xPath.compile("/subsystem/secure-deployment[1]/SP/IDP").evaluate(doc, XPathConstants.NODESET);
            nodeList.item(0).appendChild(allowedClockSkew);
            // transform again to XML
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            StringWriter writer = new StringWriter();
            transformer.transform(new DOMSource(doc), new StreamResult(writer));
            subsystemXml = writer.getBuffer().toString();
        } else {
            subsystemXml = template;
        }
    } catch (DOMException | ParserConfigurationException | SAXException | TransformerException | XPathExpressionException e) {
        throw new IOException(e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) XPathExpressionException(javax.xml.xpath.XPathExpressionException) PathElement(org.jboss.as.controller.PathElement) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) DOMException(org.w3c.dom.DOMException) StringWriter(java.io.StringWriter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TransformerException(javax.xml.transform.TransformerException)

Example 89 with DOMException

use of org.w3c.dom.DOMException in project keycloak by keycloak.

the class DeploymentArchiveProcessor method getKeycloakResolverClass.

private String getKeycloakResolverClass(Document doc) {
    try {
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        XPathExpression expr = xpath.compile("//web-app/context-param[param-name='keycloak.config.resolver']/param-value/text()");
        NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
        if (nodes != null && nodes.getLength() > 0) {
            return nodes.item(0).getNodeValue();
        }
    } catch (DOMException e) {
        throw new IllegalStateException(e);
    } catch (XPathExpressionException e) {
        throw new IllegalStateException(e);
    }
    return null;
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathFactory(javax.xml.xpath.XPathFactory) DOMException(org.w3c.dom.DOMException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList)

Example 90 with DOMException

use of org.w3c.dom.DOMException in project oozie by apache.

the class OozieCLI method parseDocument.

// Canibalized from Hadoop <code>Configuration.loadResource()</code>.
private Properties parseDocument(Document doc, Properties conf) throws IOException {
    try {
        Element root = doc.getDocumentElement();
        if (!"configuration".equals(root.getLocalName())) {
            throw new RuntimeException("bad conf file: top-level element not <configuration>");
        }
        NodeList props = root.getChildNodes();
        for (int i = 0; i < props.getLength(); i++) {
            Node propNode = props.item(i);
            if (!(propNode instanceof Element)) {
                continue;
            }
            Element prop = (Element) propNode;
            if (!"property".equals(prop.getLocalName())) {
                throw new RuntimeException("bad conf file: element not <property>");
            }
            NodeList fields = prop.getChildNodes();
            String attr = null;
            String value = null;
            for (int j = 0; j < fields.getLength(); j++) {
                Node fieldNode = fields.item(j);
                if (!(fieldNode instanceof Element)) {
                    continue;
                }
                Element field = (Element) fieldNode;
                if ("name".equals(field.getLocalName()) && field.hasChildNodes()) {
                    attr = ((Text) field.getFirstChild()).getData();
                }
                if ("value".equals(field.getLocalName()) && field.hasChildNodes()) {
                    value = ((Text) field.getFirstChild()).getData();
                }
            }
            if (attr != null && value != null) {
                conf.setProperty(attr, value);
            }
        }
        return conf;
    } catch (DOMException e) {
        throw new IOException(e);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IOException(java.io.IOException)

Aggregations

DOMException (org.w3c.dom.DOMException)323 Document (org.w3c.dom.Document)165 Element (org.w3c.dom.Element)131 Node (org.w3c.dom.Node)73 NodeList (org.w3c.dom.NodeList)57 DocumentBuilder (javax.xml.parsers.DocumentBuilder)42 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)42 Attr (org.w3c.dom.Attr)40 DOMImplementation (org.w3c.dom.DOMImplementation)37 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)28 FrameworkException (org.structr.common.error.FrameworkException)27 IOException (java.io.IOException)26 NamedNodeMap (org.w3c.dom.NamedNodeMap)25 DocumentType (org.w3c.dom.DocumentType)19 ArrayList (java.util.ArrayList)17 Text (org.w3c.dom.Text)17 DOMNode (org.structr.web.entity.dom.DOMNode)16 XPathExpressionException (javax.xml.xpath.XPathExpressionException)15 SAXException (org.xml.sax.SAXException)13 TransformerException (javax.xml.transform.TransformerException)12