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


Java DOMImplementationLS.createLSOutput方法代码示例

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


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

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

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

示例3: toXml

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

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

示例5: asString

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

示例6: marshall

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

示例7: format

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

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

示例9: writeXmlDocumentToFile

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

示例10: getXmlString

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

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

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

示例13: marshall

import org.w3c.dom.ls.DOMImplementationLS; //导入方法依赖的package包/类
private static String marshall(XMLObject xmlObject) throws org.wso2.carbon.identity.base.IdentityException {
    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("UTF-8");
    } catch (Exception e) {
        log.error("Error Serializing the SAML Response");
        throw IdentityException.error("Error Serializing the SAML Response", e);
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:24,代码来源:ErrorResponseBuilder.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 Exception
 */
public static String marshall(XMLObject xmlObject) throws Exception {
    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) {
        throw new Exception("Error Serializing the SAML Response", e);
    }
}
 
开发者ID:wso2,项目名称:carbon-commons,代码行数:31,代码来源:Util.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.createLSOutput方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。