List of usage examples for org.w3c.dom Document getImplementation
public DOMImplementation getImplementation();
DOMImplementation
object that handles this document. From source file:org.adeptnet.auth.saml.SAMLClient.java
private String _createAuthnRequest(final String requestId) throws SAMLException { final AuthnRequest request = createAuthnRequest(requestId); try {/*from w ww. ja v a 2 s.c om*/ // samlobject to xml dom object final Element elem = Configuration.getMarshallerFactory().getMarshaller(request).marshall(request); // and to a string... final Document document = elem.getOwnerDocument(); final DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation(); final LSSerializer serializer = domImplLS.createLSSerializer(); serializer.getDomConfig().setParameter("xml-declaration", false); return serializer.writeToString(elem); } catch (MarshallingException e) { throw new SAMLException(e); } }
From source file:org.apache.juddi.mapping.MappingApiToModel.java
private static String serializeTransformElement(Element xformEl) throws DOMException, LSException { Document document = xformEl.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation(); LSSerializer serializer = domImplLS.createLSSerializer(); // serializer.getDomConfig().setParameter("namespaces", true); // serializer.getDomConfig().setParameter("namespace-declarations", true); serializer.getDomConfig().setParameter("canonical-form", false); serializer.getDomConfig().setParameter("xml-declaration", false); String str = serializer.writeToString(xformEl); return str;/*from w w w . ja va2 s. c om*/ }
From source file:org.hawkular.wildfly.module.installer.XmlConfigBuilderTest.java
private void printDocument(Document doc) { try {//from w ww . jav a 2 s .c o m DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation(); System.out.println("XML DOCUMENT:\n" + domImplementation.createLSSerializer().writeToString(doc)); } catch (Throwable t) { System.out.println("Can't print doc: " + t); } }
From source file:org.wso2.carbon.datasource.utils.DataSourceUtils.java
public static String elementToString(Element element) { try {// w w w . j a v a2 s . c o m if (element == null) { /* return an empty string because, the other way around works the same, where if we give a empty string as the XML, we get a null element from "stringToElement" */ return ""; } Document document = element.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation(); LSSerializer serializer = domImplLS.createLSSerializer(); //by default its true, so set it to false to get String without xml-declaration serializer.getDomConfig().setParameter(XML_DECLARATION, false); return serializer.writeToString(element); } catch (Exception e) { logger.error("Error while converting element to string: " + e.getMessage(), e); return null; } }
From source file:org.wso2.carbon.mediation.configadmin.util.XMLPrettyPrinter.java
/** * XML Pretty Print method with XML Comments support. * * @return XML formatted String//from w w w . j a v a 2 s . com */ public String xmlFormatWithComments() { String xmlOutput = null; Document doc; LSSerializer lsSerializer; try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); doc = documentBuilderFactory.newDocumentBuilder().parse(in); DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation(); lsSerializer = domImplementation.createLSSerializer(); lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); LSOutput lsOutput = domImplementation.createLSOutput(); lsOutput.setEncoding(encoding); Writer stringWriter = new StringWriter(); lsOutput.setCharacterStream(stringWriter); lsSerializer.write(doc, lsOutput); xmlOutput = stringWriter.toString(); } catch (IOException e) { log.error("XML Pretty Printer Error reading data from given InputStream to XML Document ", e); } catch (SAXException e) { log.error("XML Pretty Printer Error parsing the given InputStream to XML Document", e); } catch (Exception e) { log.error("XML Pretty Printer failed. ", e); } return xmlOutput; }
From source file:org.wso2.carbon.ndatasource.core.utils.DataSourceUtils.java
public static String elementToString(Element element) { try {/*from w ww. ja v a 2 s .c om*/ if (element == null) { /* return an empty string because, the other way around works the same, where if we give a empty string as the XML, we get a null element from "stringToElement" */ return ""; } Document document = element.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation(); LSSerializer serializer = domImplLS.createLSSerializer(); //by default its true, so set it to false to get String without xml-declaration serializer.getDomConfig().setParameter(XML_DECLARATION, false); return serializer.writeToString(element); } catch (Exception e) { log.error("Error while convering element to string: " + e.getMessage(), e); return null; } }
From source file:org.xwiki.platform.patchservice.web.PatchServiceAction.java
private void outputXml(Document doc, XWikiResponse response) { response.setContentType("text/xml"); DOMImplementationLS ls = (DOMImplementationLS) doc.getImplementation(); try {/*from ww w .j a v a 2 s . c o m*/ response.getWriter().write(ls.createLSSerializer().writeToString(doc)); } catch (Exception e) { } }
From source file:org.xwiki.platform.patchservice.web.PatchServiceServlet.java
private void outputXml(Document doc, XWikiResponse response) { response.setContentType("text/xml"); DOMImplementationLS ls = (DOMImplementationLS) doc.getImplementation(); try {//from w w w. j ava2 s . c om LSOutput o = ls.createLSOutput(); o.setByteStream(response.getOutputStream()); ls.createLSSerializer().write(doc, o); } catch (Exception e) { } }
From source file:org.zaproxy.zap.extension.exportreport.Export.ReportExport.java
public static String getStringFromDoc(Document doc) { DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation(); LSSerializer lsSerializer = domImplementation.createLSSerializer(); return lsSerializer.writeToString(doc); }
From source file:tufts.vue.ds.XMLIngest.java
public static Schema ingestXML(XmlSchema schema, org.xml.sax.InputSource input, String itemKey) { final org.w3c.dom.Document doc = parseXML(input, false); //doc.normalizeDocument(); if (DEBUG.DR) { try {/*ww w. j a v a 2s. c om*/ errout("XML parsed, document built:"); errout("org.w3c.dom.Document: " + Util.tags(doc)); final org.w3c.dom.DocumentType type = doc.getDoctype(); //errout("InputEncoding: " + doc.getInputEncoding()); // AbstractMethodError ? //errout("xmlEncoding: " + doc.getXmlEncoding()); // AbstractMethodError //errout("xmlVersion: " + doc.getXmlVersion()); // AbstractMethodError errout("docType: " + Util.tags(type)); if (type != null) { errout("docType.name: " + Util.tags(type.getName())); errout("docType.entities: " + Util.tags(type.getEntities())); errout("docType.notations: " + Util.tags(type.getNotations())); errout("docType.publicId: " + Util.tags(type.getPublicId())); errout("docType.systemId: " + Util.tags(type.getSystemId())); } errout("impl: " + Util.tags(doc.getImplementation().getClass())); errout("docElement: " + Util.tags(doc.getDocumentElement().getClass())); // toString() can dump whole document! } catch (Throwable t) { Log.error("debug failure", t); } } //out("element: " + Util.tags(doc.getDocumentElement())); //outln("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); //outln("<!-- created by RSSTest " + new Date() + " from " + src + " -->"); if (schema == null) schema = new XmlSchema(tufts.vue.Resource.instance(input), itemKey); else schema.flushData(); if (false) XPathExtract(schema, doc); else scanNode(schema, doc.getDocumentElement(), null, null); if (DEBUG.DR || DEBUG.SCHEMA) schema.dumpSchema(System.err); return schema; }