Search in sources :

Example 76 with DOMImplementation

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

the class VsmCommand method getVServiceNode.

public static String getVServiceNode(String vlanId, String ipAddr) {
    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(configVServiceNodeDetails(doc, vlanId, ipAddr));
        editConfig.appendChild(config);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while adding vservice node for vlan " + vlanId + ", " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while adding vservice node for vlan " + vlanId + ", " + 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 77 with DOMImplementation

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

the class VsmCommand method getDeletePortProfile.

public static String getDeletePortProfile(String portName) {
    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(deletePortProfileDetails(doc, portName));
        editConfig.appendChild(config);
        return serialize(domImpl, doc);
    } catch (ParserConfigurationException e) {
        s_logger.error("Error while creating delete port profile message : " + e.getMessage());
        return null;
    } catch (DOMException e) {
        s_logger.error("Error while creating delete 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 78 with DOMImplementation

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

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 79 with DOMImplementation

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

the class XMLUtil method createDocument.

// ~~~~~~~~~~~~~~~~~~~~~ DOM related ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/**
     * Creates an empty DOM document. E.g.:
     * <pre>
     * Document doc = createDocument("book", null, null, null);
     * </pre> creates new DOM of a well-formed document with root element named
     * book.
     *
     * @param rootQName       qualified name of root element, for example
     *                        <code>myroot</code> or <code>ns:myroot</code>
     * @param namespaceURI    URI of root element namespace or <code>null</code>
     * @param doctypePublicID public ID of DOCTYPE or <code>null</code>
     * @param doctypeSystemID system ID of DOCTYPE or <code>null</code> if no
     *                        DOCTYPE required and doctypePublicID is also
     *                        <code>null</code>
     *
     * @throws DOMException              if new DOM with passed parameters can
     *                                   not be created
     * @throws FactoryConfigurationError Application developers should never
     *                                   need to directly catch errors of this
     *                                   type.
     *
     * @return new DOM Document
     */
public static Document createDocument(String rootQName, String namespaceURI, String doctypePublicID, String doctypeSystemID) throws DOMException {
    DOMImplementation impl = getDOMImplementation();
    if ((doctypePublicID != null) && (doctypeSystemID == null)) {
        //NOI18N
        throw new IllegalArgumentException("System ID cannot be null if public ID specified. ");
    }
    DocumentType dtd = null;
    if (doctypeSystemID != null) {
        dtd = impl.createDocumentType(rootQName, doctypePublicID, doctypeSystemID);
    }
    return impl.createDocument(namespaceURI, rootQName, dtd);
}
Also used : DOMImplementation(org.w3c.dom.DOMImplementation) DocumentType(org.w3c.dom.DocumentType)

Example 80 with DOMImplementation

use of org.w3c.dom.DOMImplementation in project jdk8u_jdk by JetBrains.

the class MergeStdCommentTest method main.

public static void main(String[] args) throws Exception {
    String format = "javax_imageio_1.0";
    BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
    ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
    IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
    DOMImplementationRegistry registry;
    registry = DOMImplementationRegistry.newInstance();
    DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
    Document doc = impl.createDocument(null, format, null);
    Element root, text, entry;
    root = doc.getDocumentElement();
    root.appendChild(text = doc.createElement("Text"));
    text.appendChild(entry = doc.createElement("TextEntry"));
    // keyword isn't #REQUIRED by the standard metadata format.
    // However, it is required by the PNG format, so we include it here.
    entry.setAttribute("keyword", "Comment");
    entry.setAttribute("value", "Some demo comment");
    meta.mergeTree(format, root);
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) Element(org.w3c.dom.Element) ImageWriter(javax.imageio.ImageWriter) DOMImplementationRegistry(org.w3c.dom.bootstrap.DOMImplementationRegistry) DOMImplementation(org.w3c.dom.DOMImplementation) Document(org.w3c.dom.Document) BufferedImage(java.awt.image.BufferedImage) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier)

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