Search in sources :

Example 56 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project robovm by robovm.

the class DocumentCreateElementNS method testCreateElementNS6.

public void testCreateElementNS6() throws Throwable {
    Document doc;
    Document newDoc;
    DocumentType docType = null;
    DOMImplementation domImpl;
    String namespaceURI = "http://www.w3.org/xml/1998/namespace ";
    String qualifiedName = "xml:root";
    doc = (Document) load("staffNS", builder);
    domImpl = doc.getImplementation();
    newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test", "dom:doc", docType);
    {
        boolean success = false;
        try {
            newDoc.createElementNS(namespaceURI, qualifiedName);
        } catch (DOMException ex) {
            success = (ex.code == DOMException.NAMESPACE_ERR);
        }
        assertTrue("documentcreateelementNS06", success);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentType(org.w3c.dom.DocumentType) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document)

Example 57 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project CloudStack-archive by CloudStack-extras.

the class VsmCommand method getAddPortProfile.

public static String getAddPortProfile(String name, PortProfileType type, BindingType binding, SwitchPortMode mode, int vlanid) {
    try {
        // Create the document and root element.
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        DOMImplementation domImpl = docBuilder.getDOMImplementation();
        Document doc = createDocument(domImpl);
        // Edit configuration command.
        Element editConfig = doc.createElement("nf:edit-config");
        doc.getDocumentElement().appendChild(editConfig);
        // Command to get into exec configure mode.
        Element target = doc.createElement("nf:target");
        Element running = doc.createElement("nf:running");
        target.appendChild(running);
        editConfig.appendChild(target);
        // Command to create the port profile with the desired configuration.
        Element config = doc.createElement("nf:config");
        config.appendChild(configPortProfileDetails(doc, name, type, binding, mode, vlanid));
        editConfig.appendChild(config);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating add port profile message : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating add port profile message : " + e.getMessage());
        return null;
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Example 58 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project CloudStack-archive by CloudStack-extras.

the class VsmCommand method getServicePolicy.

public static String getServicePolicy(String policyMap, String portProfile, boolean attach) {
    try {
        // Create the document and root element.
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        DOMImplementation domImpl = docBuilder.getDOMImplementation();
        Document doc = createDocument(domImpl);
        // Edit configuration command.
        Element editConfig = doc.createElement("nf:edit-config");
        doc.getDocumentElement().appendChild(editConfig);
        // Command to get into exec configure mode.
        Element target = doc.createElement("nf:target");
        Element running = doc.createElement("nf:running");
        target.appendChild(running);
        editConfig.appendChild(target);
        // Command to create the port profile with the desired configuration.
        Element config = doc.createElement("nf:config");
        config.appendChild(serviceDetails(doc, policyMap, portProfile, attach));
        editConfig.appendChild(config);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating attach/detach service policy message : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating attach/detach service policy message : " + e.getMessage());
        return null;
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Example 59 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project CloudStack-archive by CloudStack-extras.

the class VsmCommand method getAddPolicyMap.

public static String getAddPolicyMap(String name, int averageRate, int maxRate, int burstRate) {
    try {
        // Create the document and root element.
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        DOMImplementation domImpl = docBuilder.getDOMImplementation();
        Document doc = createDocument(domImpl);
        // Edit configuration command.
        Element editConfig = doc.createElement("nf:edit-config");
        doc.getDocumentElement().appendChild(editConfig);
        // Command to get into exec configure mode.
        Element target = doc.createElement("nf:target");
        Element running = doc.createElement("nf:running");
        target.appendChild(running);
        editConfig.appendChild(target);
        // Command to create the port profile with the desired configuration.
        Element config = doc.createElement("nf:config");
        config.appendChild(policyMapDetails(doc, name, averageRate, maxRate, burstRate));
        editConfig.appendChild(config);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating policy map message : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating policy map message : " + e.getMessage());
        return null;
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Example 60 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project CloudStack-archive by CloudStack-extras.

the class VsmCommand method getHello.

public static String getHello() {
    try {
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        DOMImplementation domImpl = docBuilder.getDOMImplementation();
        // Root elements.
        Document doc = domImpl.createDocument(s_namespace, "nc:hello", null);
        // Client capacity. We are only supporting basic capacity.
        Element capabilities = doc.createElement("nc:capabilities");
        Element capability = doc.createElement("nc:capability");
        capability.setTextContent("urn:ietf:params:xml:ns:netconf:base:1.0");
        capabilities.appendChild(capability);
        doc.getDocumentElement().appendChild(capabilities);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating hello message : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating hello message : " + e.getMessage());
        return null;
    }
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document)

Aggregations

DOMImplementation (org.w3c.dom.DOMImplementation)82 Document (org.w3c.dom.Document)67 DOMException (org.w3c.dom.DOMException)35 Element (org.w3c.dom.Element)34 DocumentType (org.w3c.dom.DocumentType)28 DocumentBuilder (javax.xml.parsers.DocumentBuilder)25 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)22 ArrayList (java.util.ArrayList)8 TransformerException (javax.xml.transform.TransformerException)6 DOMImplementationRegistry (org.w3c.dom.bootstrap.DOMImplementationRegistry)6 DOMImplementationLS (org.w3c.dom.ls.DOMImplementationLS)6 IOException (java.io.IOException)5 Transformer (javax.xml.transform.Transformer)5 DOMSource (javax.xml.transform.dom.DOMSource)5 StreamResult (javax.xml.transform.stream.StreamResult)5 Node (org.w3c.dom.Node)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 NodeList (org.w3c.dom.NodeList)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3