当前位置: 首页>>代码示例>>Java>>正文


Java LSOutput.setEncoding方法代码示例

本文整理汇总了Java中org.w3c.dom.ls.LSOutput.setEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java LSOutput.setEncoding方法的具体用法?Java LSOutput.setEncoding怎么用?Java LSOutput.setEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.ls.LSOutput的用法示例。


在下文中一共展示了LSOutput.setEncoding方法的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);
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:21,代码来源:DomHelper.java

示例2: transformNonTextNodeToOutputStream

import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
/**
 * Serializes a node using a certain character encoding.
 * 
 * @param node
 *            DOM node to serialize
 * @param os
 *            output stream, to which the node is serialized
 * @param omitXmlDeclaration
 *            indicator whether to omit the XML declaration or not
 * @param encoding
 *            character encoding, can be <code>null</code>, if
 *            <code>null</code> then "UTF-8" is used
 * @throws Exception
 */
public static void transformNonTextNodeToOutputStream(Node node, OutputStream os, boolean omitXmlDeclaration, String encoding)
    throws Exception { //NOPMD
    // previously we used javax.xml.transform.Transformer, however the JDK xalan implementation did not work correctly with a specified encoding
    // therefore we switched to DOMImplementationLS
    if (encoding == null) {
        encoding = "UTF-8";
    }
    DOMImplementationRegistry domImplementationRegistry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementationRegistry.getDOMImplementation("LS");
    LSOutput lsOutput = domImplementationLS.createLSOutput();
    lsOutput.setEncoding(encoding);
    lsOutput.setByteStream(os);
    LSSerializer lss = domImplementationLS.createLSSerializer();
    lss.getDomConfig().setParameter("xml-declaration", !omitXmlDeclaration);
    lss.write(node, lsOutput);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:XmlSignatureHelper.java

示例3: asString

import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
/**
 * Returns a textual representation of an XML Object.
 * 
 * @param doc	XML Dom Document
 * @return	String containing a textual representation of the object
 */
public static String asString(Document doc) {
    try {
        DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
        LSSerializer lsSerializer = domImplementation.createLSSerializer();
        LSOutput lsOutput =  domImplementation.createLSOutput();
        lsOutput.setEncoding("UTF-8");
        return lsSerializer.writeToString(doc);
    } catch (Exception e) {
        e.printStackTrace();
        try {
            DOMSource domSource = new DOMSource(doc);
            StringWriter writer = new StringWriter();
            StreamResult result = new StreamResult(writer);
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.transform(domSource, result);
            return writer.toString();
        } catch(Exception ex) {
            logger.error(ex);
            return StackTrace.asString(ex);
        }
    }
    
}
 
开发者ID:rovemonteux,项目名称:automation_engine,代码行数:31,代码来源:XMLIO.java

示例4: 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);
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:26,代码来源:SAMLResponseCommand.java

示例5: 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);
   }
}
 
开发者ID:ngallagher,项目名称:simplexml,代码行数:18,代码来源:Formatter.java

示例6: 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();
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:17,代码来源:XMLUtils.java

示例7: 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();
	}
}
 
开发者ID:mondo-project,项目名称:mondo-hawk,代码行数:26,代码来源:ConfigFileParser.java

示例8: 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;
}
 
开发者ID:mondo-project,项目名称:mondo-hawk,代码行数:22,代码来源:MMetamodelParser.java

示例9: 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.");
	}
}
 
开发者ID:vZome,项目名称:vzome-core,代码行数:23,代码来源:DaeExporter.java

示例10: 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();
}
 
开发者ID:ArjanO,项目名称:AP-NLP,代码行数:24,代码来源:PowerDesignerExport.java

示例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;
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:27,代码来源:Helper.java

示例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.");
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:24,代码来源:StringToXmlDocumentParser.java

示例13: writeDocument

import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
/**
 * Writes a DOM Document to the given OutputStream using the "UTF-8"
 * encoding. The XML declaration is omitted.
 * 
 * @param outStream
 *            The destination OutputStream object.
 * @param doc
 *            A Document node.
 */
void writeDocument(OutputStream outStream, Document doc) {
    DOMImplementationRegistry domRegistry = null;
    try {
        domRegistry = DOMImplementationRegistry.newInstance();
    } catch (Exception e) {
        LOGR.warning(e.getMessage());
    }
    DOMImplementationLS impl = (DOMImplementationLS) domRegistry
            .getDOMImplementation("LS");
    LSSerializer writer = impl.createLSSerializer();
    writer.getDomConfig().setParameter("xml-declaration", false);
    writer.getDomConfig().setParameter("format-pretty-print", true);
    LSOutput output = impl.createLSOutput();
    output.setEncoding("UTF-8");
    output.setByteStream(outStream);
    writer.write(doc, output);
}
 
开发者ID:opengeospatial,项目名称:teamengine,代码行数:27,代码来源:CoverageMonitor.java

示例14: _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();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:WebBrowserImpl.java

示例15: getGroupings

import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
   private void getGroupings(Integer organisationId, HttpServletResponse response) throws IOException {
Document doc = OrganisationGroupServlet.docBuilder.newDocument();
Element groupsElement = doc.createElement("groups");
doc.appendChild(groupsElement);

List<OrganisationGrouping> groupings = userManagementService.findByProperty(OrganisationGrouping.class,
	"organisationId", organisationId);
for (OrganisationGrouping grouping : groupings) {
    Element groupingElement = doc.createElement("grouping");
    groupingElement.setAttribute("id", grouping.getGroupingId().toString());
    groupingElement.setAttribute("name", StringEscapeUtils.escapeXml(grouping.getName()));
    groupsElement.appendChild(groupingElement);
    for (OrganisationGroup group : grouping.getGroups()) {
	Element groupElement = doc.createElement("group");
	groupElement.setAttribute("id", group.getGroupId().toString());
	groupElement.setAttribute("name", StringEscapeUtils.escapeXml(group.getName()));
	groupingElement.appendChild(groupElement);
	for (User user : group.getUsers()) {
	    Element userElement = doc.createElement("user");
	    userElement.setAttribute("id", user.getUserId().toString());
	    userElement.setAttribute("firstname", StringEscapeUtils.escapeXml(user.getFirstName()));
	    userElement.setAttribute("lastname", StringEscapeUtils.escapeXml(user.getLastName()));
	    groupElement.appendChild(userElement);
	}
    }
}

response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");

DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
LSOutput lsOutput = domImplementation.createLSOutput();
lsOutput.setEncoding("UTF-8");
lsOutput.setByteStream(response.getOutputStream());
lsSerializer.write(doc, lsOutput);
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:OrganisationGroupServlet.java


注:本文中的org.w3c.dom.ls.LSOutput.setEncoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。