use of org.w3c.dom.ls.DOMImplementationLS in project CloudStack-archive by CloudStack-extras.
the class VsmCommand method serialize.
private static String serialize(DOMImplementation domImpl, Document document) {
DOMImplementationLS ls = (DOMImplementationLS) domImpl;
LSSerializer lss = ls.createLSSerializer();
return lss.writeToString(document);
}
use of org.w3c.dom.ls.DOMImplementationLS 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.ls.DOMImplementationLS in project wildfly by wildfly.
the class UsernameTokenCallbackHandler method toString.
private String toString(Node node) {
String str = null;
if (node != null) {
DOMImplementationLS lsImpl = (DOMImplementationLS) node.getOwnerDocument().getImplementation().getFeature("LS", "3.0");
LSSerializer serializer = lsImpl.createLSSerializer();
//by default its true, so set it to false to get String without xml-declaration
serializer.getDomConfig().setParameter("xml-declaration", false);
str = serializer.writeToString(node);
}
return str;
}
use of org.w3c.dom.ls.DOMImplementationLS in project cloudstack by apache.
the class VsmCommand method serialize.
private static String serialize(DOMImplementation domImpl, Document document) {
DOMImplementationLS ls = (DOMImplementationLS) domImpl;
LSSerializer lss = ls.createLSSerializer();
return lss.writeToString(document);
}
use of org.w3c.dom.ls.DOMImplementationLS in project ddf by codice.
the class XPathHelper method print.
/**
* Prints a given node as a String
*
* @param n
* - the node to print as a String
* @param encoding
* - the character encoding to use for the returned String
* @return the Node as a String, null if an exception is thrown or null is passed in.
*/
public static String print(Node n, String encoding) {
if (n == null) {
return null;
}
try {
Document document = null;
if (n instanceof Document) {
document = (Document) n;
} else {
document = n.getOwnerDocument();
}
StringWriter stringOut = new StringWriter();
DOMImplementationLS domImpl = (DOMImplementationLS) document.getImplementation();
LSSerializer serializer = domImpl.createLSSerializer();
LSOutput lsOut = domImpl.createLSOutput();
lsOut.setEncoding(encoding);
lsOut.setCharacterStream(stringOut);
serializer.write(n, lsOut);
return stringOut.toString();
} catch (DOMException | LSException e) {
LOGGER.debug(e.getMessage(), e);
}
return null;
}
Aggregations