當前位置: 首頁>>代碼示例>>Java>>正文


Java DOMImplementationLS.createLSSerializer方法代碼示例

本文整理匯總了Java中org.w3c.dom.ls.DOMImplementationLS.createLSSerializer方法的典型用法代碼示例。如果您正苦於以下問題:Java DOMImplementationLS.createLSSerializer方法的具體用法?Java DOMImplementationLS.createLSSerializer怎麽用?Java DOMImplementationLS.createLSSerializer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.w3c.dom.ls.DOMImplementationLS的用法示例。


在下文中一共展示了DOMImplementationLS.createLSSerializer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testCreateNewItem2Sell

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
/**
 * Check for DOMErrorHandler handling DOMError. Before fix of bug 4890927
 * DOMConfiguration.setParameter("well-formed",true) throws an exception.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testCreateNewItem2Sell() throws Exception {
    String xmlFile = XML_DIR + "novelsInvalid.xml";

    Document document = DocumentBuilderFactory.newInstance()
            .newDocumentBuilder().parse(xmlFile);

    document.getDomConfig().setParameter("well-formed", true);

    DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
    DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
    MyDOMOutput domOutput = new MyDOMOutput();
    domOutput.setByteStream(System.out);
    LSSerializer writer = impl.createLSSerializer();
    writer.write(document, domOutput);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:AuctionController.java

示例2: main

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();

    DOMImplementation impl = document.getImplementation();
    DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0");
    LSSerializer dsi = implLS.createLSSerializer();

    /* We should have here incorrect document without getXmlVersion() method:
     * Such Document is generated by replacing the JDK bootclasses with it's
     * own Node,Document and DocumentImpl classes (see run.sh). According to
     * XERCESJ-1007 the AbstractMethodError should be thrown in such case.
     */
    String result = dsi.writeToString(document);
    System.out.println("Result:" + result);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:AbstractMethodErrorTest.java

示例3: testLSInputParsingString

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
@Test
public void testLSInputParsingString() throws Exception {
    DOMImplementationLS impl = (DOMImplementationLS) getDocumentBuilder().getDOMImplementation();
    String xml = "<?xml version='1.0'?><test>runDocumentLS_Q6</test>";

    LSParser domParser = impl.createLSParser(MODE_SYNCHRONOUS, null);
    LSSerializer domSerializer = impl.createLSSerializer();
    // turn off xml decl in serialized string for comparison
    domSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE);
    LSInput src = impl.createLSInput();
    src.setStringData(xml);
    assertEquals(src.getStringData(), xml);

    Document doc = domParser.parse(src);
    String result = domSerializer.writeToString(doc);

    assertEquals(result, "<test>runDocumentLS_Q6</test>");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:DocumentLSTest.java

示例4: format

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
public static String format(String xml) {

        try {
            final InputSource src = new InputSource(new StringReader(xml));
            final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
            final Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml"));

            //May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");


            final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
            final LSSerializer writer = impl.createLSSerializer();

            writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
            writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted.

            return writer.writeToString(document);
        } catch (Exception e) {
            return xml;
        }
    }
 
開發者ID:iotoasis,項目名稱:SI,代碼行數:23,代碼來源:Utils.java

示例5: transformNonTextNodeToOutputStream

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的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

示例6: testCreateNewItem2SellRetry

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
/**
 * Check for DOMErrorHandler handling DOMError. Before fix of bug 4896132
 * test throws DOM Level 1 node error.
 *
 * @throws Exception If any errors occur.
 */
@Test(groups = {"readLocalFiles"})
public void testCreateNewItem2SellRetry() throws Exception  {
    String xmlFile = XML_DIR + "accountInfo.xml";

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    Document document = dbf.newDocumentBuilder().parse(xmlFile);

    DOMConfiguration domConfig = document.getDomConfig();
    MyDOMErrorHandler errHandler = new MyDOMErrorHandler();
    domConfig.setParameter("error-handler", errHandler);

    DOMImplementationLS impl =
         (DOMImplementationLS) DOMImplementationRegistry.newInstance()
                 .getDOMImplementation("LS");
    LSSerializer writer = impl.createLSSerializer();
    MyDOMOutput domoutput = new MyDOMOutput();

    domoutput.setByteStream(System.out);
    writer.write(document, domoutput);

    document.normalizeDocument();
    writer.write(document, domoutput);
    assertFalse(errHandler.isError());
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:32,代碼來源:AuctionController.java

示例7: marshall

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
/**
 * `
 * Serialize XML objects
 *
 * @param xmlObject : XACML or SAML objects to be serialized
 * @return serialized XACML or SAML objects
 * @throws EntitlementException
 */
private String marshall(XMLObject xmlObject) throws EntitlementException {

    try {
        doBootstrap();
        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

        MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
        Element element = marshaller.marshall(xmlObject);

        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS impl =
                (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = impl.createLSSerializer();
        LSOutput output = impl.createLSOutput();
        output.setByteStream(byteArrayOutputStream);
        writer.write(element, output);
        return byteArrayOutputStream.toString();
    } catch (Exception e) {
        log.error("Error Serializing the SAML Response");
        throw new EntitlementException("Error Serializing the SAML Response", e);
    }
}
 
開發者ID:wso2,項目名稱:carbon-identity-framework,代碼行數:34,代碼來源:WSXACMLMessageReceiver.java

示例8: marshall

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
/**
 * Serializes the specified SAML 2.0 based XML content representation to its corresponding actual XML syntax
 * representation.
 *
 * @param xmlObject the SAML 2.0 based XML content object
 * @return a {@link String} representation of the actual XML representation of the SAML 2.0 based XML content
 * representation
 * @throws SSOException if an error occurs during the marshalling process
 */
public static String marshall(XMLObject xmlObject) throws SSOException {
    try {
        Marshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(xmlObject);
        Element element = null;
        if (marshaller != null) {
            element = marshaller.marshall(xmlObject);
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS implementation = (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = implementation.createLSSerializer();
        LSOutput output = implementation.createLSOutput();
        output.setByteStream(byteArrayOutputStream);
        writer.write(element, output);
        return new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
    } catch (ClassNotFoundException | InstantiationException | MarshallingException | IllegalAccessException e) {
        throw new SSOException("Error in marshalling SAML 2.0 Assertion", e);
    }
}
 
開發者ID:wso2-extensions,項目名稱:tomcat-extension-samlsso,代碼行數:29,代碼來源:SSOUtils.java

示例9: load

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
public void load(File f) throws ConfigPersisterException {
    try {
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = factory.newDocumentBuilder();
		Document doc = builder.parse(f);

		DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
	    LSSerializer lsSerializer = domImplementation.createLSSerializer();
	    String configString = lsSerializer.writeToString(doc);

    	_config = (Config) _xstream.fromXML(convertToCurrent(configString));
    	setConfigPath(f);
	} catch (Exception e) {
		throw new ConfigPersisterException(e);
	}
}
 
開發者ID:clidev,項目名稱:spike.x,代碼行數:17,代碼來源:ConfigPersister.java

示例10: formatHtml

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
protected String formatHtml(String html) throws MojoExecutionException {
try {
	InputSource src = new InputSource(new StringReader(html));
	Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
	Boolean keepDeclaration = Boolean.valueOf(html.startsWith("<?xml"));
	
	DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
	DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
	LSSerializer writer = impl.createLSSerializer();
	
	writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
	writer.getDomConfig().setParameter("xml-declaration", keepDeclaration);
	
	return writer.writeToString(document);
} catch (Exception e) {
	throw new MojoExecutionException(e.getMessage(), e);
}
  }
 
開發者ID:fastconnect,項目名稱:tibco-fcunit,代碼行數:19,代碼來源:UnitTestsIndexMojo.java

示例11: nodeToString

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
protected static String nodeToString(Node n, boolean pretty) {
	try {
		final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
		final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
		final LSSerializer writer = impl.createLSSerializer();

		writer.getDomConfig().setParameter("xml-declaration", false);
		if (pretty) {
			writer.getDomConfig().setParameter("format-pretty-print", true);
		}

		return writer.writeToString(n);
	} catch (final Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:openimaj,項目名稱:openimaj,代碼行數:17,代碼來源:Readability.java

示例12: indentXML

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
/**
* Method to generated idented XML
* Credit: Steve McLeod and DaoWen.
* Code from http://stackoverflow.com/a/11519668
* @param xml input xml in string format
* @return indented xml in string format
*/
  public static String indentXML(String xml) {

      try {
          final InputSource src = new InputSource(new StringReader(xml));
          final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
          final Boolean keepDeclaration = xml.startsWith("<?xml");

      //May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");


          final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
          final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
          final LSSerializer writer = impl.createLSSerializer();

          writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
          writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted.

          return writer.writeToString(document);
      } catch (Exception e) {
          throw new RuntimeException(e);
      }
  }
 
開發者ID:raulmrebane,項目名稱:LaTeXEE,代碼行數:30,代碼來源:OutputWriter.java

示例13: serialize

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的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

示例14: marshall

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的package包/類
/**
 * Serializing a SAML2 object into a String
 *
 * @param xmlObject object that needs to serialized.
 * @return serialized object
 * @throws SAMLSSOException
 */
public static String marshall(XMLObject xmlObject) throws SAMLSSOException {
    try {

        System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
                "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

        MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration
                .getMarshallerFactory();
        Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
        Element element = marshaller.marshall(xmlObject);

        ByteArrayOutputStream byteArrayOutputStrm = new ByteArrayOutputStream();
        DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
        DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
        LSSerializer writer = impl.createLSSerializer();
        LSOutput output = impl.createLSOutput();
        output.setByteStream(byteArrayOutputStrm);
        writer.write(element, output);
        return byteArrayOutputStrm.toString();
    } catch (Exception e) {
        log.error("Error Serializing the SAML Response");
        throw new SAMLSSOException("Error Serializing the SAML Response", e);
    }
}
 
開發者ID:wso2-attic,項目名稱:carbon-identity,代碼行數:32,代碼來源:SSOUtils.java

示例15: serializeDOM_LS

import org.w3c.dom.ls.DOMImplementationLS; //導入方法依賴的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


注:本文中的org.w3c.dom.ls.DOMImplementationLS.createLSSerializer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。