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


Java LSSerializer.getDomConfig方法代码示例

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


在下文中一共展示了LSSerializer.getDomConfig方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLSSerializer

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
/**
 * Obtain a the DOM, level 3, Load/Save serializer {@link LSSerializer} instance from the
 * given {@link DOMImplementationLS} instance.
 * 
 * <p>
 * The serializer instance will be configured with the parameters passed as the <code>serializerParams</code>
 * argument. It will also be configured with an {@link LSSerializerFilter} that shows all nodes to the filter, 
 * and accepts all nodes shown.
 * </p>
 * 
 * @param domImplLS the DOM Level 3 Load/Save implementation to use
 * @param serializerParams parameters to pass to the {@link DOMConfiguration} of the serializer
 *         instance, obtained via {@link LSSerializer#getDomConfig()}. May be null.
 *         
 * @return a new LSSerializer instance
 */
public static LSSerializer getLSSerializer(DOMImplementationLS domImplLS, Map<String, Object> serializerParams) {
    LSSerializer serializer = domImplLS.createLSSerializer();
    
    serializer.setFilter(new LSSerializerFilter() {

        public short acceptNode(Node arg0) {
            return FILTER_ACCEPT;
        }

        public int getWhatToShow() {
            return SHOW_ALL;
        }
    });
    
    
    if (serializerParams != null) {
        DOMConfiguration serializerDOMConfig = serializer.getDomConfig();
        for (String key : serializerParams.keySet()) {
            serializerDOMConfig.setParameter(key, serializerParams.get(key));
        }
    }
    
    return serializer;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:41,代码来源:XMLHelper.java

示例2: toXml

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的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

示例3: format

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的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

示例4: serialize

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的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

示例5: write

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的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

示例6: serializeDOM_LS

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
protected void serializeDOM_LS(Element elt, OutputStream out, boolean pretty) throws LSException
{
    DOMImplementationLS impl = (DOMImplementationLS)XMLImplFinder.getDOMImplementation(); 
    
    // init and configure serializer
    LSSerializer serializer = impl.createLSSerializer();
    DOMConfiguration config = serializer.getDomConfig();
    config.setParameter("format-pretty-print", pretty);
    
    // wrap output stream
    LSOutput output = impl.createLSOutput();
    output.setByteStream(out);
    
    // launch serialization
    serializer.write(elt, output);
}
 
开发者ID:sensiasoft,项目名称:lib-swe-common,代码行数:17,代码来源:XMLDocument.java

示例7: prettyPrintXmlDocument

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的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

示例8: writeDocument

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
public static void writeDocument(Document doc, Writer out) throws IOException
{
  // happy to replace this code w/ the non-deprecated code, but I couldn't get the transformer
  // approach to work.
//    OutputFormat format = new OutputFormat(doc);
//    format.setIndenting(true);
//    format.setIndent(2);
//    XMLSerializer serializer = new XMLSerializer(out, format);
//    serializer.serialize(doc);

  DOMImplementationLS impl = (DOMImplementationLS) doc.getImplementation();
  LSSerializer writer = impl.createLSSerializer();
  DOMConfiguration config = writer.getDomConfig();

  if (config.canSetParameter("format-pretty-print", Boolean.TRUE))
  {
    config.setParameter("format-pretty-print", Boolean.TRUE);
  }


  // what a crappy way to force the stream to be UTF-8.  yuck!
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  LSOutput output = impl.createLSOutput();
  output.setEncoding("UTF-8");
  output.setByteStream(baos);

  writer.write(doc, output);

  out.write(baos.toString());
  out.flush();
}
 
开发者ID:ngageoint,项目名称:mrgeo,代码行数:32,代码来源:XmlUtils.java

示例9: prettyPrintXMLDocument

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
/**
	 * Create a pretty String representation of a DOM Document
	 * @param node
	 * @return String of the given document
	 */
	public static String prettyPrintXMLDocument(Node node) {
		if (node == null) {
			return "";
		}
		DocumentBuilder builder = null;
		try {
			builder = getDocumentBuilder();
		} catch (ParserConfigurationException exception) {
			System.err.println(exception);
			return "";
		}
		DOMImplementation implementation = builder.getDOMImplementation();
		Object object = implementation.getFeature("LS", "3.0");
		if (!(object instanceof DOMImplementationLS)) {
			return "";
		}
		DOMImplementationLS loadSave = (DOMImplementationLS)object;
		LSSerializer serializer = loadSave.createLSSerializer();
		DOMConfiguration config = serializer.getDomConfig();
		if (config.canSetParameter("format-pretty-print", true)) {
			config.setParameter("format-pretty-print", true);
		}
		
		LSOutput loadSaveOut = loadSave.createLSOutput();
		StringWriter string = new StringWriter();
		loadSaveOut.setCharacterStream(string);
		loadSaveOut.setEncoding("UTF-8");
		serializer.write(node, loadSaveOut);
		String result = string.toString();
		
//		String result = serializer.writeToString(node);
		return result;
	}
 
开发者ID:woboq,项目名称:p300,代码行数:39,代码来源:DOMUtils.java

示例10: write

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
/**
 * Write a RIFCS document to an output stream.
 *
 * @param os
 *        The OutputStream to write the data to
 */
public final void write(final OutputStream os) {
    DOMImplementation impl = doc.getImplementation();
    DOMImplementationLS implLS =
            (DOMImplementationLS) impl.getFeature("LS", "3.0");

    LSOutput lso = implLS.createLSOutput();
    lso.setByteStream(os);
    LSSerializer writer = implLS.createLSSerializer();
    DOMConfiguration domConfig = writer.getDomConfig();
    domConfig.setParameter("format-pretty-print", Boolean.TRUE);
    writer.write(doc, lso);
}
 
开发者ID:au-research,项目名称:ANDS-RIFCS-API,代码行数:19,代码来源:RIFCSWrapper.java

示例11: prettyPrint

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
public void prettyPrint() {
	final String xml = xmlPane.getText();
	final InputSource src = new InputSource(new StringReader(xml));
       org.w3c.dom.Document document;
	try {
		document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src);
	} catch (SAXException | IOException | ParserConfigurationException e) {
		return;
	}
	
	final Pattern p = Pattern.compile("^<\\?xml.*\\?>");
	final Matcher m = p.matcher(xml);
	final String xmlDecl = (m.find()) ? m.group() : "";
	
	// 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+.
       final DOMImplementation domImplementation = document.getImplementation();
	if (!domImplementation.hasFeature("LS", "3.0") || !domImplementation.hasFeature("Core", "2.0")) {
		return;
	}
	final DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0");
	final LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
	final DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
	if (domConfiguration.canSetParameter("format-pretty-print", true)) {
		domConfiguration.setParameter("format-pretty-print", true);
	}
	if (domConfiguration.canSetParameter("xml-declaration", false)) {
		domConfiguration.setParameter("xml-declaration", false);
	}
	
	final LSOutput lsOutput = domImplementationLS.createLSOutput();
	lsOutput.setEncoding("UTF-8");
	final StringWriter stringWriter = new StringWriter();
	if (!xmlDecl.isEmpty()) {
		stringWriter.write(xmlDecl);
		stringWriter.write("\n");
	}
	lsOutput.setCharacterStream(stringWriter);
	lsSerializer.write(document, lsOutput);
	final String xmlOut = stringWriter.toString();
	xmlPane.setText(xmlOut);
}
 
开发者ID:kiwiwings,项目名称:poi-visualizer,代码行数:43,代码来源:XMLEditor.java

示例12: newInputSource

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
public InputSource newInputSource(String filename) throws Exception {
    // Create DOMImplementationLS, and DOM L3 LSParser
    DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
    DocumentBuilder bldr = fact.newDocumentBuilder();
    DOMImplementationLS impl = (DOMImplementationLS) bldr.getDOMImplementation();
    LSParser domparser = impl.createLSParser(MODE_SYNCHRONOUS, null);
    domparser.setFilter(new MyDOMBuilderFilter());

    // Parse the xml document to create the DOM Document using
    // the DOM L3 LSParser and a LSInput (formerly LSInputSource)
    Document doc = null;
    LSInput src = impl.createLSInput();
    // register the input file with the input source...
    String systemId = filenameToURL(filename);
    src.setSystemId(systemId);
    try (Reader reader = new FileReader(filename)) {
        src.setCharacterStream(reader);
        src.setEncoding("UTF-8");
        doc = domparser.parse(src);
    }

    // Use DOM L3 LSSerializer (previously called a DOMWriter)
    // to serialize the xml doc DOM to a file stream.
    String tmpCatalog = Files.createTempFile(Paths.get(USER_DIR), "catalog.xml", null).toString();

    LSSerializer domserializer = impl.createLSSerializer();
    domserializer.setFilter(new MyDOMWriterFilter());
    domserializer.getNewLine();
    DOMConfiguration config = domserializer.getDomConfig();
    config.setParameter("xml-declaration", Boolean.TRUE);
    String result = domserializer.writeToString(doc);
    try (FileWriter os = new FileWriter(tmpCatalog, false)) {
        os.write(result);
        os.flush();
    }

    // Return the Input Source created from the Serialized DOM L3 Document.
    InputSource catsrc = new InputSource(new InputStreamReader(new ByteArrayInputStream(Files.readAllBytes(Paths.get(tmpCatalog)))));
    catsrc.setSystemId(systemId);
    return catsrc;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:DOML3InputSourceFactoryImpl.java

示例13: newInputSource

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
public InputSource newInputSource(String filename) throws Exception {
    // Create DOMImplementationLS, and DOM L3 LSParser
    DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
    DocumentBuilder bldr = fact.newDocumentBuilder();
    DOMImplementationLS impl = (DOMImplementationLS) bldr.getDOMImplementation();
    LSParser domparser = impl.createLSParser(MODE_SYNCHRONOUS, null);
    domparser.setFilter(new MyDOMBuilderFilter());

    // Parse the xml document to create the DOM Document using
    // the DOM L3 LSParser and a LSInput (formerly LSInputSource)
    Document doc = null;
    LSInput src = impl.createLSInput();
    // register the input file with the input source...
    String systemId = filenameToURL(filename);
    src.setSystemId(systemId);
    try (Reader reader = new FileReader(filename)) {
        src.setCharacterStream(reader);
        src.setEncoding("UTF-8");
        doc = domparser.parse(src);
    }

    // Use DOM L3 LSSerializer (previously called a DOMWriter)
    // to serialize the xml doc DOM to a file stream.
    String tmpCatalog = Files.createTempFile(Paths.get("").toAbsolutePath(), "catalog.xml", null).toString();

    LSSerializer domserializer = impl.createLSSerializer();
    domserializer.setFilter(new MyDOMWriterFilter());
    domserializer.getNewLine();
    DOMConfiguration config = domserializer.getDomConfig();
    config.setParameter("xml-declaration", Boolean.TRUE);
    String result = domserializer.writeToString(doc);
    try (FileWriter os = new FileWriter(tmpCatalog, false)) {
        os.write(result);
        os.flush();
    }

    // Return the Input Source created from the Serialized DOM L3 Document.
    InputSource catsrc = new InputSource(new InputStreamReader(new ByteArrayInputStream(Files.readAllBytes(Paths.get(tmpCatalog)))));
    catsrc.setSystemId(systemId);
    return catsrc;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:42,代码来源:DOML3InputSourceFactoryImpl.java

示例14: createLSSerializer

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
/** Returns a <code>LSSerializer</code> instance.
 * @param impl A <code>DOMImplementationLS</code> instance
 * @param includeXmlDeclaration If set to <code>true</code>,
 * the xml declaration will be included in the output
 * @param enablePrettyPrint If set to <code>true</code>, the
 * output will be formatted in human-readable form. If set to
 * <code>false</code>, the entire document will consist of a single line.
 * @return A <code>LSSerializer</code> instance
 * @see <a href="http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/">DOM Level 3 Load and Save Specification</a>
 */
public static LSSerializer createLSSerializer(DOMImplementationLS impl, boolean includeXmlDeclaration, boolean enablePrettyPrint) {
    LSSerializer writer = impl.createLSSerializer();
    DOMConfiguration domConfig = writer.getDomConfig();
    domConfig.setParameter("xml-declaration", includeXmlDeclaration);
    domConfig.setParameter("format-pretty-print", enablePrettyPrint);
    return writer;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:18,代码来源:UtilXml.java


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