List of usage examples for org.w3c.dom.ls LSSerializer writeToString
public String writeToString(Node nodeArg) throws DOMException, LSException;
LSSerializer
interface. From source file:org.apache.manifoldcf.crawler.connectors.meridio.meridiowrapper.MeridioWrapper.java
/** Given the SOAP response received by AXIS on the successful call to a Meridio * Web Service, this helper method returns a castor DMDataSet object which represents * the XML/* w w w . j a v a 2 s.co m*/ * * This makes it much easier to subsequently manipulate the data that has been * returned from the web service, and ensures that the Meridio wrapper implementation * is as close to native .NET code as we can get. */ protected DMDataSet getDMDataSet(MessageElement[] messageElement) throws MeridioDataSetException { if (oLog != null) oLog.debug("Meridio: Entered getDMDataSet method."); try { if (messageElement.length != 2) { if (oLog != null) oLog.warn("Meridio: SOAP Message not of expected length"); if (oLog != null) oLog.debug("Meridio: Exiting getDMDataSet method with null."); return null; } /* for (int i = 0; i < messageElement.length; i++) { oLog.debug("Meridio: Message Part: " + i + " " + messageElement[i]); } */ Document document = messageElement[1].getAsDocument(); NodeList nl = document.getElementsByTagName("DMDataSet"); NodeList errors = document.getElementsByTagName("diffgr:errors"); if (errors.getLength() != 0) { String errorXML = ""; if (oLog != null) oLog.error("Found <" + errors.getLength() + "> errors in returned data set"); for (int i = 0; i < errors.getLength(); i++) { Element e = (Element) errors.item(i); Document resultDocument = new DocumentImpl(); Node node = resultDocument.importNode(e, true); resultDocument.appendChild(node); DOMImplementation domImpl = DOMImplementationImpl.getDOMImplementation(); DOMImplementationLS implLS = (DOMImplementationLS) domImpl; LSSerializer writer = implLS.createLSSerializer(); errorXML += writer.writeToString(resultDocument) + "\n"; if (oLog != null) oLog.warn("..." + errorXML); } throw new MeridioDataSetException(errorXML); } if (nl.getLength() != 1) { if (oLog != null) oLog.warn("Meridio: Returning null - could not find DMDataSet in SOAP Message"); if (oLog != null) oLog.debug("Meridio: Exiting getDMDataSet method with null."); return null; } Element e = (Element) nl.item(0); Document resultDocument = new DocumentImpl(); Node node = resultDocument.importNode(e, true); resultDocument.appendChild(node); DOMImplementation domImpl = DOMImplementationImpl.getDOMImplementation(); DOMImplementationLS implLS = (DOMImplementationLS) domImpl; LSSerializer writer = implLS.createLSSerializer(); String documentXML = writer.writeToString(resultDocument); //oLog.debug("Meridio: Result: " + documentXML); StringReader sr = new StringReader(documentXML); DMDataSet dsDM = new DMDataSet(); dsDM = DMDataSet.unmarshal(sr); if (oLog != null) oLog.debug("Meridio: Exiting getDMDataSet method."); return dsDM; } catch (ClassNotFoundException classNotFoundException) { throw new MeridioDataSetException( "Could not find the DOM Parser class when unmarshalling the Meridio Dataset", classNotFoundException); } catch (InstantiationException instantiationException) { throw new MeridioDataSetException( "Error instantiating the DOM Parser when unmarshalling the Meridio Dataset", instantiationException); } catch (IllegalAccessException illegalAccessException) { throw new MeridioDataSetException("DOM Parser illegal access when unmarshalling the Meridio Dataset", illegalAccessException); } catch (MarshalException marshalException) { throw new MeridioDataSetException("Castor error in marshalling the XML from the Meridio Dataset", marshalException); } catch (ValidationException validationException) { throw new MeridioDataSetException("Castor error in validating the XML from the Meridio Dataset", validationException); } catch (Exception ex) // from messageElement[1].getAsDocument(); { throw new MeridioDataSetException("Error retrieving the XML Document from the Web Service response", ex); } }
From source file:i5.las2peer.services.mobsos.SurveyService.java
/** * Serializes a given Document to String. * //from w w w.j a v a 2 s . com * @param doc * @return */ private String getStringFromDoc(org.w3c.dom.Document doc) { DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation(); LSSerializer lsSerializer = domImplementation.createLSSerializer(); return lsSerializer.writeToString(doc); }
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 w w . jav 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;// w w w . j av a 2s.com }
From source file:org.mitre.eren.model.ModelManager.java
/** * Convert the message into a string and then parse it using the abdera parser. * Is there a simpler way to do this?//from w w w . j a va2s . c o m * @param edxl * @param outgoing */ private void attachMessage(EDXLDistribution edxl, Node outgoing) { try { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); String str = writer.writeToString(outgoing); Abdera abdera = new Abdera(); Parser parser = abdera.getParser(); Document<Feed> feed_doc = parser.parse(new StringReader(str)); ExtensibleElement content = feed_doc.getRoot(); ContentObject co = edxl.addContentObject(); XmlContent xc = co.setXmlContent(); EmbeddedXMLContent exc = xc.addEmbeddedXMLContent(); exc.addExtension(content); } catch (ClassCastException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.oclc.oai.harvester.verb.HarvesterVerb.java
@Override public String toString() { // Element docEl = getDocument().getDocumentElement(); // return docEl.toString(); /*/*from w ww. ja va2 s . c om*/ * Source input = new DOMSource(getDocument()); StringWriter sw = new * StringWriter(); Result output = new StreamResult(sw); try { * Transformer idTransformer = xformFactory.newTransformer(); * idTransformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, * "yes"); idTransformer.transform(input, output); return sw.toString(); * } catch (TransformerException e) { return e.getMessage(); } */ //Serialize DOM // OutputFormat format = new OutputFormat(doc); // // as a String // StringWriter stringOut = new StringWriter(); // XMLSerializer serial = new XMLSerializer(stringOut, format); // try { // serial.serialize(doc); // } catch (IOException e) { // e.printStackTrace(); // } DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation(); LSSerializer lsSerializer = domImplementation.createLSSerializer(); // Display the XML return lsSerializer.writeToString(doc); }
From source file:org.wso2.carbon.datasource.utils.DataSourceUtils.java
public static String elementToString(Element element) { try {// w w w. ja v a 2 s .co 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.ndatasource.core.utils.DataSourceUtils.java
public static String elementToString(Element element) { try {/*from w w w. j av a 2 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) { log.error("Error while convering element to string: " + e.getMessage(), e); return null; } }
From source file:org.wso2.developerstudio.eclipse.security.project.ui.form.SecurityFormPage.java
/** * Gets the updated content of the source * * @return content//from w w w . j a va 2s.c o m * @throws TransformerException */ public String getUpdatedContent() throws TransformerException, InstantiationException, IllegalAccessException, ClassNotFoundException { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); final LSSerializer writer = impl.createLSSerializer(); // Set this to true if the output needs to be beautified. writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the declaration is needed to be outputted. writer.getDomConfig().setParameter("xml-declaration", false); return writer.writeToString(policyFileDOMDocument); }
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); }