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


Java LSSerializer.write方法代码示例

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


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

示例1: testCreateNewItem2Sell

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

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的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
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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:AuctionController.java

示例3: testCreateNewItem2Sell

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的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(groups = {"readLocalFiles"})
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:campolake,项目名称:openjdk9,代码行数:23,代码来源:AuctionController.java

示例4: testCreateNewItem2SellRetry

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

示例5: marshall

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

示例6: marshall

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

示例7: 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

示例8: transformNonTextNodeToOutputStream

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

示例9: getXmlString

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

示例10: marshall

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

示例11: 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

示例12: writeXmlDocumentToFile

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

示例13: 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

示例14: marshall

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

import org.w3c.dom.ls.LSSerializer; //导入方法依赖的package包/类
/**
 * Serializing a SAML2 object into a String
 *
 * @param xmlObject object that needs to serialized.
 * @return serialized object
 * @throws SAML2SSOUIAuthenticatorException
 */
public static String marshall(XMLObject xmlObject) throws SAML2SSOUIAuthenticatorException {

    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 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 SAML2SSOUIAuthenticatorException("Error Serializing the SAML Response", e);
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:33,代码来源:Util.java


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