本文整理汇总了Java中org.w3c.dom.ls.LSOutput.setByteStream方法的典型用法代码示例。如果您正苦于以下问题:Java LSOutput.setByteStream方法的具体用法?Java LSOutput.setByteStream怎么用?Java LSOutput.setByteStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.ls.LSOutput
的用法示例。
在下文中一共展示了LSOutput.setByteStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: marshall
import org.w3c.dom.ls.LSOutput; //导入方法依赖的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.LSOutput; //导入方法依赖的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: transformNonTextNodeToOutputStream
import org.w3c.dom.ls.LSOutput; //导入方法依赖的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);
}
示例4: marshall
import org.w3c.dom.ls.LSOutput; //导入方法依赖的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);
}
}
示例5: marshall
import org.w3c.dom.ls.LSOutput; //导入方法依赖的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);
}
}
示例6: marshall
import org.w3c.dom.ls.LSOutput; //导入方法依赖的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);
}
}
示例7: marshall
import org.w3c.dom.ls.LSOutput; //导入方法依赖的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);
}
}
示例8: serializeDOM_LS
import org.w3c.dom.ls.LSOutput; //导入方法依赖的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);
}
示例9: writeDocument
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
/**
* Writes a DOM Document to the given OutputStream using the "UTF-8"
* encoding. The XML declaration is omitted.
*
* @param outStream
* The destination OutputStream object.
* @param doc
* A Document node.
*/
void writeDocument(OutputStream outStream, Document doc) {
DOMImplementationRegistry domRegistry = null;
try {
domRegistry = DOMImplementationRegistry.newInstance();
} catch (Exception e) {
LOGR.warning(e.getMessage());
}
DOMImplementationLS impl = (DOMImplementationLS) domRegistry
.getDOMImplementation("LS");
LSSerializer writer = impl.createLSSerializer();
writer.getDomConfig().setParameter("xml-declaration", false);
writer.getDomConfig().setParameter("format-pretty-print", true);
LSOutput output = impl.createLSOutput();
output.setEncoding("UTF-8");
output.setByteStream(outStream);
writer.write(doc, output);
}
示例10: elementToString
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
private static String elementToString(Element e) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DOMImplementationLS ls = (DOMImplementationLS) e.getOwnerDocument().getImplementation().getFeature("LS", "3.0"); // NOI18N
LSOutput output = ls.createLSOutput();
output.setByteStream(baos);
LSSerializer ser = ls.createLSSerializer();
ser.write(e, output);
return baos.toString();
}
示例11: writeNode
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
/**
* Writes a Node out to an OutputStream using the DOM, level 3, Load/Save serializer. The written content
* is encoded using the encoding specified in the output stream configuration.
*
* @param node the node to write out
* @param output the output stream to write the XML to
* @param serializerParams parameters to pass to the {@link DOMConfiguration} of the serializer
* instance, obtained via {@link LSSerializer#getDomConfig()}. May be null.
*/
public static void writeNode(Node node, OutputStream output, Map<String, Object> serializerParams) {
DOMImplementationLS domImplLS = getLSDOMImpl(node);
LSSerializer serializer = getLSSerializer(domImplLS, serializerParams);
LSOutput serializerOut = domImplLS.createLSOutput();
serializerOut.setByteStream(output);
serializer.write(node, serializerOut);
}
示例12: getGroupings
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void getGroupings(Integer organisationId, HttpServletResponse response) throws IOException {
Document doc = OrganisationGroupServlet.docBuilder.newDocument();
Element groupsElement = doc.createElement("groups");
doc.appendChild(groupsElement);
List<OrganisationGrouping> groupings = userManagementService.findByProperty(OrganisationGrouping.class,
"organisationId", organisationId);
for (OrganisationGrouping grouping : groupings) {
Element groupingElement = doc.createElement("grouping");
groupingElement.setAttribute("id", grouping.getGroupingId().toString());
groupingElement.setAttribute("name", StringEscapeUtils.escapeXml(grouping.getName()));
groupsElement.appendChild(groupingElement);
for (OrganisationGroup group : grouping.getGroups()) {
Element groupElement = doc.createElement("group");
groupElement.setAttribute("id", group.getGroupId().toString());
groupElement.setAttribute("name", StringEscapeUtils.escapeXml(group.getName()));
groupingElement.appendChild(groupElement);
for (User user : group.getUsers()) {
Element userElement = doc.createElement("user");
userElement.setAttribute("id", user.getUserId().toString());
userElement.setAttribute("firstname", StringEscapeUtils.escapeXml(user.getFirstName()));
userElement.setAttribute("lastname", StringEscapeUtils.escapeXml(user.getLastName()));
groupElement.appendChild(userElement);
}
}
}
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
LSOutput lsOutput = domImplementation.createLSOutput();
lsOutput.setEncoding("UTF-8");
lsOutput.setByteStream(response.getOutputStream());
lsSerializer.write(doc, lsOutput);
}
示例13: write
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
public void write(Document doc) {
File file = getOutputFile(testClass);
try (FileOutputStream outputStream = new FileOutputStream(file)) {
DOMImplementationRegistry reg = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) reg.getDOMImplementation("LS");
LSSerializer serializer = impl.createLSSerializer();
LSOutput output = impl.createLSOutput();
output.setByteStream(outputStream);
serializer.write(doc, output);
} catch (Exception e) {
throw new CucumberException(Constants.errorPrefix + "Failed to write document to disc", e);
}
}
示例14: write
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
public static void write(Document document, OutputStream stream)
{
DOMImplementationLS impl = (DOMImplementationLS)REGISTRY.getDOMImplementation("LS");
LSSerializer writer = impl.createLSSerializer();
LSOutput output=impl.createLSOutput();
output.setByteStream(stream);
writer.write(document, output);
}
示例15: createLSOutput
import org.w3c.dom.ls.LSOutput; //导入方法依赖的package包/类
/** Returns a <code>LSOutput</code> instance.
* @param impl A <code>DOMImplementationLS</code> instance
* @param os Optional <code>OutputStream</code> instance
* @param encoding Optional character encoding, default is UTF-8
* @return A <code>LSOutput</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 LSOutput createLSOutput(DOMImplementationLS impl, OutputStream os, String encoding) {
LSOutput out = impl.createLSOutput();
if (os != null) {
out.setByteStream(os);
}
if (encoding != null) {
out.setEncoding(encoding);
}
return out;
}