本文整理汇总了Java中org.w3c.dom.ls.LSOutput.setCharacterStream方法的典型用法代码示例。如果您正苦于以下问题:Java LSOutput.setCharacterStream方法的具体用法?Java LSOutput.setCharacterStream怎么用?Java LSOutput.setCharacterStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.ls.LSOutput
的用法示例。
在下文中一共展示了LSOutput.setCharacterStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toXml
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
public static String toXml(Document domDoc) throws TransformerException {
DOMImplementation domImplementation = domDoc.getImplementation();
if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) {
DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0");
LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
if (domConfiguration.canSetParameter("xml-declaration", Boolean.TRUE))
lsSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE);
if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) {
lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
LSOutput lsOutput = domImplementationLS.createLSOutput();
lsOutput.setEncoding("UTF-8");
StringWriter stringWriter = new StringWriter();
lsOutput.setCharacterStream(stringWriter);
lsSerializer.write(domDoc, lsOutput);
return stringWriter.toString();
}
}
return toXml((Node)domDoc);
}
示例2: marshall
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
/**
* Marshall a SAML XML object into a W3C DOM and then into a String
*
* @param pXMLObject SAML Object to marshall
* @return XML version of the SAML Object in string form
*/
private String marshall(XMLObject pXMLObject) {
try {
MarshallerFactory lMarshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
Marshaller lMarshaller = lMarshallerFactory.getMarshaller(pXMLObject);
Element lElement = lMarshaller.marshall(pXMLObject);
DOMImplementationLS lDOMImplementationLS = (DOMImplementationLS) DOMImplementationRegistry.newInstance().getDOMImplementation("LS");
LSSerializer lSerializer = lDOMImplementationLS.createLSSerializer();
LSOutput lOutput = lDOMImplementationLS.createLSOutput();
lOutput.setEncoding("UTF-8");
Writer lStringWriter = new StringWriter();
lOutput.setCharacterStream(lStringWriter);
lSerializer.write(lElement, lOutput);
return lStringWriter.toString();
}
catch (Exception e) {
throw new ExInternal("Error Serializing the SAML Response", e);
}
}
示例3: format
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
private void format(Document document, Writer writer) {
DOMImplementation implementation = document.getImplementation();
if(implementation.hasFeature(LS_FEATURE_KEY, LS_FEATURE_VERSION) && implementation.hasFeature(CORE_FEATURE_KEY, CORE_FEATURE_VERSION)) {
DOMImplementationLS implementationLS = (DOMImplementationLS) implementation.getFeature(LS_FEATURE_KEY, LS_FEATURE_VERSION);
LSSerializer serializer = implementationLS.createLSSerializer();
DOMConfiguration configuration = serializer.getDomConfig();
configuration.setParameter("format-pretty-print", Boolean.TRUE);
configuration.setParameter("comments", preserveComments);
LSOutput output = implementationLS.createLSOutput();
output.setEncoding("UTF-8");
output.setCharacterStream(writer);
serializer.write(document, output);
}
}
示例4: getXmlString
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
private String getXmlString(Node node) {
try {
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS implementationLS = (DOMImplementationLS)registry.getDOMImplementation("LS");
LSOutput output = implementationLS.createLSOutput();
output.setEncoding(this.xmlEncoding);
output.setCharacterStream(new StringWriter());
LSSerializer serializer = implementationLS.createLSSerializer();
serializer.write(node, output);
return output.getCharacterStream().toString();
} catch (Exception e1) {
e1.printStackTrace();
}
return null;
}
示例5: serialize
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
public static String serialize(Document document, boolean prettyPrint) {
DOMImplementationLS impl = getDOMImpl();
LSSerializer serializer = impl.createLSSerializer();
// document.normalizeDocument();
DOMConfiguration config = serializer.getDomConfig();
if (prettyPrint && config.canSetParameter("format-pretty-print", Boolean.TRUE)) {
config.setParameter("format-pretty-print", true);
}
config.setParameter("xml-declaration", true);
LSOutput output = impl.createLSOutput();
output.setEncoding("UTF-8");
Writer writer = new StringWriter();
output.setCharacterStream(writer);
serializer.write(document, output);
return writer.toString();
}
示例6: writeXmlDocumentToFile
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
/** Utility methods */
private void writeXmlDocumentToFile(Node node, String filename) {
try {
// find file or create one and save all info
File file = new File(filename);
if(!file.exists()) {
file.createNewFile();
}
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS implementationLS = (DOMImplementationLS)registry.getDOMImplementation("LS");
LSOutput output = implementationLS.createLSOutput();
output.setEncoding("UTF-8");
output.setCharacterStream(new FileWriter(file));
LSSerializer serializer = implementationLS.createLSSerializer();
serializer.getDomConfig().setParameter("format-pretty-print", true);
serializer.write(node, output);
} catch (Exception e1) {
e1.printStackTrace();
}
}
示例7: write
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
void write( Writer writer )
{
// Pretty-prints a DOM document to XML using DOM Load and Save's LSSerializer.
// Note that the "format-pretty-print" DOM configuration parameter can only be set in JDK 1.6+.
DOMImplementation domImplementation = doc .getImplementation();
if (domImplementation .hasFeature("LS", "3.0") && domImplementation .hasFeature( "Core", "2.0" ) ) {
DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation .getFeature( "LS", "3.0" );
LSSerializer lsSerializer = domImplementationLS .createLSSerializer();
DOMConfiguration domConfiguration = lsSerializer .getDomConfig();
if (domConfiguration .canSetParameter( "format-pretty-print", Boolean.TRUE )) {
lsSerializer .getDomConfig() .setParameter( "format-pretty-print", Boolean.TRUE );
LSOutput lsOutput = domImplementationLS .createLSOutput();
lsOutput .setEncoding( "UTF-8" );
lsOutput .setCharacterStream( writer );
lsSerializer.write( doc, lsOutput );
} else {
throw new RuntimeException("DOMConfiguration 'format-pretty-print' parameter isn't settable.");
}
} else {
throw new RuntimeException("DOM 3.0 LS and/or DOM 2.0 Core not supported.");
}
}
示例8: export
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
public String export(ArrayList<Class> classes) {
Document doc = exportDoc(classes);
// Output the document to string.
DOMImplementation impl = doc.getImplementation();
DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0");
LSSerializer lsSerializer = implLS.createLSSerializer();
LSOutput lsOutput = implLS.createLSOutput();
lsOutput.setEncoding("UTF-8");
Writer stringWriter = new StringWriter();
lsOutput.setCharacterStream(stringWriter);
lsSerializer.write(doc, lsOutput);
String output = stringWriter.toString();
//Write to file
file.setContent(output);
file.write();
return file.getPath();
}
示例9: dom2String2
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
public static String dom2String2(Document document) {
DOMImplementationRegistry registry;
try {
registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS domImplLS = (DOMImplementationLS)registry.getDOMImplementation("LS");
LSSerializer ser = domImplLS.createLSSerializer(); // Create a serializer for the DOM
LSOutput out = domImplLS.createLSOutput();
StringWriter stringOut = new StringWriter(); // Writer will be a String
out.setCharacterStream(stringOut);
ser.write(document, out); // Serialize the DOM
System.out.println( "STRXML = "
+ stringOut.toString() ); // Spit out the DOM as a String
return stringOut.toString();
} catch (Exception e) {
System.err.println("Cannot create registry: "+e.getMessage());
}
return null;
}
示例10: prettyFormat
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
private static String prettyFormat(Document document, boolean keepXmlDeclaration) {
try {
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS domImplementation = (DOMImplementationLS) registry.getDOMImplementation("LS");
Writer stringWriter = new StringWriter();
LSOutput formattedOutput = domImplementation.createLSOutput();
formattedOutput.setCharacterStream(stringWriter);
LSSerializer domSerializer = domImplementation.createLSSerializer();
domSerializer.getDomConfig().setParameter("format-pretty-print", true);
// Set this to true if the declaration is needed to be in the output.
domSerializer.getDomConfig().setParameter("xml-declaration", keepXmlDeclaration);
domSerializer.write(document, formattedOutput);
return stringWriter.toString();
} catch (Exception e) {
throw new RuntimeException(FORMAT_ERROR, e);
}
}
示例11: documentToString
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
/***
* 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 occurred when converting document to string", e);
}
return strMsg;
}
示例12: prettyPrintXmlDocument
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
private static String prettyPrintXmlDocument(Document document) {
// Pretty-prints a DOM document to XML using DOM Load and Save's LSSerializer.
// Note that the "format-pretty-print" DOM configuration parameter can only be set in JDK 1.6+.
DOMImplementation domImplementation = document.getImplementation();
if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) {
DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0");
LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) {
lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
LSOutput lsOutput = domImplementationLS.createLSOutput();
lsOutput.setEncoding("UTF-8");
StringWriter stringWriter = new StringWriter();
lsOutput.setCharacterStream(stringWriter);
lsSerializer.write(document, lsOutput);
return stringWriter.toString();
} else {
throw new RuntimeException("DOMConfiguration 'format-pretty-print' parameter isn't settable.");
}
} else {
throw new RuntimeException("DOM 3.0 LS and/or DOM 2.0 Core not supported.");
}
}
示例13: _dumpDocument
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
private void _dumpDocument( Document doc, String title ) {
if( null == title || title.isEmpty() ) {
title = NbBundle.getMessage(WebBrowserImpl.class, "Lbl_GenericDomDumpTitle");
}
InputOutput io = IOProvider.getDefault().getIO( title, true );
io.select();
try {
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation( "XML 3.0 LS 3.0" ); //NOI18N
if( null == impl ) {
io.getErr().println( NbBundle.getMessage(WebBrowserImpl.class, "Err_DOMImplNotFound") );
return;
}
LSSerializer serializer = impl.createLSSerializer();
if( serializer.getDomConfig().canSetParameter( "format-pretty-print", Boolean.TRUE ) ) { //NOI18N
serializer.getDomConfig().setParameter( "format-pretty-print", Boolean.TRUE ); //NOI18N
}
LSOutput output = impl.createLSOutput();
output.setEncoding("UTF-8"); //NOI18N
output.setCharacterStream( io.getOut() );
serializer.write(doc, output);
io.getOut().println();
} catch( Exception ex ) {
ex.printStackTrace( io.getErr() );
} finally {
if( null != io ) {
io.getOut().close();
io.getErr().close();
}
}
}
示例14: writeNode
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
/**
* Writes a Node out to a Writer using the DOM, level 3, Load/Save serializer. The written content is encoded using
* the encoding specified in the writer configuration.
*
* @param node the node to write out
* @param output the writer to write the XML to
* @param serializerParams parameters to pass to the {@link DOMConfiguration} of the serializer
* instance, obtained via {@link LSSerializer#getDomConfig()}. May be null.
*/
public static void writeNode(Node node, Writer output, Map<String, Object> serializerParams) {
DOMImplementationLS domImplLS = getLSDOMImpl(node);
LSSerializer serializer = getLSSerializer(domImplLS, serializerParams);
LSOutput serializerOut = domImplLS.createLSOutput();
serializerOut.setCharacterStream(output);
serializer.write(node, serializerOut);
}
示例15: prettyPrintDOMResult
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
public String prettyPrintDOMResult(DOMResult dr) throws ClassNotFoundException, InstantiationException,
IllegalAccessException, ClassCastException
{
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS domImplementationLS = (DOMImplementationLS)registry.getDOMImplementation("LS");
StringWriter writer = new StringWriter();
LSOutput formattedOutput = domImplementationLS.createLSOutput();
formattedOutput.setCharacterStream(writer);
LSSerializer domSerializer = domImplementationLS.createLSSerializer();
domSerializer.getDomConfig().setParameter("format-pretty-print", true);
domSerializer.getDomConfig().setParameter("xml-declaration", false);
domSerializer.write(dr.getNode(), formattedOutput);
return writer.toString();
}