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;
}
}
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());
}
}
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");
}
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;
}
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) {
}
}
}
Aggregations