本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}