Search in sources :

Example 6 with DOMException

use of org.w3c.dom.DOMException 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 7 with DOMException

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

the class VsmPortProfileResponse method parseData.

protected void parseData(Node data) {
    try {
        NodeList list = ((Element) data).getElementsByTagName(s_portProfileDetails);
        if (list.getLength() > 0) {
            NodeList readOnlyList = ((Element) list.item(0)).getElementsByTagName("__readonly__");
            Element readOnly = (Element) readOnlyList.item(0);
            for (Node node = readOnly.getFirstChild(); node != null; node = node.getNextSibling()) {
                String currentNode = node.getNodeName();
                String value = node.getTextContent();
                if ("port_binding".equalsIgnoreCase(currentNode)) {
                    setPortBinding(value);
                } else if ("profile_name".equalsIgnoreCase(currentNode)) {
                    // Set the port profile name.
                    _portProfile.profileName = value;
                } else if ("profile_cfg".equalsIgnoreCase(currentNode)) {
                    setProfileConfiguration(value);
                } else if ("type".equalsIgnoreCase(currentNode)) {
                    setPortType(value);
                } else if ("status".equalsIgnoreCase(currentNode)) {
                    // Has the profile been enabled.
                    if (value.equalsIgnoreCase("1")) {
                        _portProfile.status = true;
                    }
                } else if ("max_ports".equalsIgnoreCase(currentNode)) {
                    // Has the profile been enabled.
                    _portProfile.maxPorts = Integer.parseInt(value.trim());
                }
            }
        }
    } catch (DOMException e) {
        s_logger.error("Error parsing the response : " + e.toString());
    }
}
Also used : DOMException(org.w3c.dom.DOMException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node)

Example 8 with DOMException

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

the class MyAttrNode method test1.

public static void test1() {
    IIOMetadataNode parent = new IIOMetadataNode("parent");
    IIOMetadataNode elem = new IIOMetadataNode("elem");
    MyAttrNode attrNode = new MyAttrNode("name", "value");
    elem.setAttributeNode(attrNode);
    attrNode.setOwnerElement(elem);
    try {
        parent.setAttributeNode(attrNode);
    } catch (DOMException e) {
        if (e.code != DOMException.INUSE_ATTRIBUTE_ERR) {
            throw new RuntimeException("Test 1 failed: " + "Invalid exception code: " + e.code);
        }
        return;
    }
    throw new RuntimeException("Test 1 failed: DOMException not thrown");
}
Also used : DOMException(org.w3c.dom.DOMException) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode)

Example 9 with DOMException

use of org.w3c.dom.DOMException in project midpoint by Evolveum.

the class XPathHolder method toElement.

// really ugly implementation... (ignores overall context of serialization, so produces <c:path> elements even if common is default namespace) TODO rework [med]
public Element toElement(String elementNamespace, String localElementName, Document document) {
    Element element = document.createElementNS(elementNamespace, localElementName);
    if (!StringUtils.isBlank(elementNamespace)) {
        String prefix = GlobalDynamicNamespacePrefixMapper.getPreferredPrefix(elementNamespace);
        if (!StringUtils.isBlank(prefix)) {
            try {
                element.setPrefix(prefix);
            } catch (DOMException e) {
                throw new SystemException("Error setting XML prefix '" + prefix + "' to element {" + elementNamespace + "}" + localElementName + ": " + e.getMessage(), e);
            }
        }
    }
    element.setTextContent(getXPathWithDeclarations());
    Map<String, String> namespaceMap = getNamespaceMap();
    if (namespaceMap != null) {
        for (Entry<String, String> entry : namespaceMap.entrySet()) {
            DOMUtil.setNamespaceDeclaration(element, entry.getKey(), entry.getValue());
        }
    }
    return element;
}
Also used : DOMException(org.w3c.dom.DOMException) SystemException(com.evolveum.midpoint.util.exception.SystemException) Element(org.w3c.dom.Element)

Example 10 with DOMException

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

the class DomTest method testRenameNodeOtherThanElementOrAttribute.

public void testRenameNodeOtherThanElementOrAttribute() {
    for (Node node : allNodes) {
        if (node.getNodeType() == Node.ATTRIBUTE_NODE || node.getNodeType() == Node.ELEMENT_NODE) {
            continue;
        }
        try {
            document.renameNode(node, null, "foo");
            fail();
        } catch (DOMException e) {
        }
    }
}
Also used : DOMException(org.w3c.dom.DOMException) Node(org.w3c.dom.Node)

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