use of org.w3c.dom.DOMImplementation in project CloudStack-archive by CloudStack-extras.
the class VsmCommand method getPortProfile.
public static String getPortProfile(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 portProfile = doc.createElement("port-profile");
show.appendChild(portProfile);
Element nameNode = doc.createElement("name");
portProfile.appendChild(nameNode);
// Profile name
Element profileName = doc.createElement("profile_name");
profileName.setTextContent(name);
nameNode.appendChild(profileName);
return serialize(domImpl, doc);
} catch (ParserConfigurationException e) {
s_logger.error("Error while creating the message to get port profile details: " + e.getMessage());
return null;
} catch (DOMException e) {
s_logger.error("Error while creating the message to get port profile details: " + e.getMessage());
return null;
}
}
use of org.w3c.dom.DOMImplementation in project CloudStack-archive by CloudStack-extras.
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;
}
}
use of org.w3c.dom.DOMImplementation in project openhab1-addons by openhab.
the class Helper method documentToString.
/***
* Helper method which converts XML Document into pretty formatted string
*
* @param doc to convert
* @return converted XML as String
*/
public static String documentToString(Document doc) {
String strMsg = "";
try {
DOMImplementation domImpl = doc.getImplementation();
DOMImplementationLS domImplLS = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");
LSSerializer lsSerializer = domImplLS.createLSSerializer();
lsSerializer.getDomConfig().setParameter("format-pretty-print", true);
Writer stringWriter = new StringWriter();
LSOutput lsOutput = domImplLS.createLSOutput();
lsOutput.setEncoding("UTF-8");
lsOutput.setCharacterStream(stringWriter);
lsSerializer.write(doc, lsOutput);
strMsg = stringWriter.toString();
} catch (Exception e) {
logger.warn("Error occured when converting document to string", e);
}
return strMsg;
}
use of org.w3c.dom.DOMImplementation in project wildfly by wildfly.
the class DOMImplementationRegistryTestCase method testDOMImplementationRegistry.
@Test
@Ignore("[WFLY-4416] Cannot obtain DOMImplementationRegistry instance")
public void testDOMImplementationRegistry() throws Exception {
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementation domImpl = registry.getDOMImplementation("LS 3.0");
Assert.assertNotNull("DOMImplementation not null", domImpl);
}
use of org.w3c.dom.DOMImplementation in project robovm by robovm.
the class CreateDocument method testCreateDocument2.
public void testCreateDocument2() throws Throwable {
String namespaceURI = null;
String qualifiedName = "k:local";
Document doc;
DocumentType docType = null;
DOMImplementation domImpl;
doc = (Document) load("staffNS", builder);
domImpl = doc.getImplementation();
boolean success = false;
try {
domImpl.createDocument(namespaceURI, qualifiedName, docType);
} catch (DOMException ex) {
success = (ex.code == DOMException.NAMESPACE_ERR);
}
assertTrue("throw_NAMESPACE_ERR", success);
}
Aggregations