當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。