Search in sources :

Example 26 with DOMImplementation

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

the class VsmCommand method getUpdatePortProfile.

public static String getUpdatePortProfile(String name, SwitchPortMode mode, List<Pair<VsmCommand.OperationType, String>> params) {
    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 update the port profile with the desired configuration.
        Element config = doc.createElement("nf:config");
        config.appendChild(configPortProfileDetails(doc, name, mode, params));
        editConfig.appendChild(config);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating update port profile message : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating update 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 27 with DOMImplementation

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

the class VsmCommand method getDeletePolicyMap.

public static String getDeletePolicyMap(String name) {
    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(deletePolicyMapDetails(doc, name));
        editConfig.appendChild(config);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating delete policy map message : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating delete 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 28 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project ACS by ACS-Community.

the class ExtraDataFeatureUtil method getExtraDataMap.

public String getExtraDataMap(DAOOperations dao, String path, Set<String> expectedAttributes, Set<String> expectedElements) throws CDBFieldDoesNotExistEx, WrongCDBDataTypeEx, ParserConfigurationException, TransformerException {
    Document xmldoc;
    DocumentBuilder builder = documentBuilderObjectPool.borrowObject();
    try {
        DOMImplementation impl = builder.getDOMImplementation();
        xmldoc = impl.createDocument(null, "data", null);
    } finally {
        documentBuilderObjectPool.returnObject(builder);
    }
    Element root = xmldoc.getDocumentElement();
    if (getExtraDataMap(root, dao, path, expectedAttributes, expectedElements)) {
        StringWriter stringWriter = new StringWriter();
        StreamResult streamResult = new StreamResult(stringWriter);
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer serializer = tf.newTransformer();
        serializer.setOutputProperty(OutputKeys.INDENT, "yes");
        serializer.transform(new DOMSource(xmldoc), streamResult);
        String ret = stringWriter.toString();
        // Oracle XMLTYPE attributes don't like empty XML, thus we convert it to null
        if (ret != null && ret.trim().isEmpty()) {
            ret = null;
        }
        return ret;
    } else {
        return null;
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document)

Example 29 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project cloudstack by apache.

the class VsmCommand method getPolicyMap.

public static String getPolicyMap(String name) {
    try {
        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        DOMImplementation domImpl = docBuilder.getDOMImplementation();
        Document doc = createDocument(domImpl);
        Element get = doc.createElement("nf:get");
        doc.getDocumentElement().appendChild(get);
        Element filter = doc.createElement("nf:filter");
        filter.setAttribute("type", "subtree");
        get.appendChild(filter);
        // Create the show port-profile name <profile-name> command.
        Element show = doc.createElement("show");
        filter.appendChild(show);
        Element policyMap = doc.createElement("policy-map");
        show.appendChild(policyMap);
        Element nameNode = doc.createElement("name");
        nameNode.setTextContent(name);
        policyMap.appendChild(nameNode);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating the message to get policy map details : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating the message to get policy map details : " + 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 30 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project cloudstack by apache.

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)

Aggregations

DOMImplementation (org.w3c.dom.DOMImplementation)73 Document (org.w3c.dom.Document)61 DOMException (org.w3c.dom.DOMException)35 Element (org.w3c.dom.Element)32 DocumentType (org.w3c.dom.DocumentType)28 DocumentBuilder (javax.xml.parsers.DocumentBuilder)23 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)22 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)20 ArrayList (java.util.ArrayList)7 TransformerException (javax.xml.transform.TransformerException)6 Transformer (javax.xml.transform.Transformer)4 DOMSource (javax.xml.transform.dom.DOMSource)4 StreamResult (javax.xml.transform.stream.StreamResult)4 NodeList (org.w3c.dom.NodeList)4 DOMImplementationRegistry (org.w3c.dom.bootstrap.DOMImplementationRegistry)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 Node (org.w3c.dom.Node)3 DOMImplementationLS (org.w3c.dom.ls.DOMImplementationLS)3 BufferedImage (java.awt.image.BufferedImage)2