List of usage examples for org.w3c.dom.ls LSSerializer write
public boolean write(Node nodeArg, LSOutput destination) throws LSException;
LSSerializer
interface. From source file:org.sakaiproject.util.StorageUtils.java
/** * Write a DOM Document to an xml file.//from w ww . j av a 2 s . c o m * * @param doc * The DOM Document to write. * @param fileName * The complete file name path. */ public static void writeDocument(Document doc, String fileName) { OutputStream out = null; try { out = new FileOutputStream(fileName); // get an instance of the DOMImplementation registry DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); DOMImplementationLS feature = (DOMImplementationLS) impl.getFeature("LS", "3.0"); LSSerializer serializer = feature.createLSSerializer(); LSOutput output = feature.createLSOutput(); output.setByteStream(out); output.setEncoding("UTF-8"); serializer.write(doc, output); out.close(); } catch (Exception any) { M_log.warn("writeDocument: " + any.toString()); } finally { if (out != null) { try { out.close(); } catch (IOException e) { } } } }
From source file:org.sakaiproject.util.StorageUtils.java
/** * Write a DOM Document to an output stream. * //from w w w .j a va 2s.c o m * @param doc * The DOM Document to write. * @param out * The output stream. */ public static String writeDocumentToString(Document doc) { try { StringWriter sw = new StringWriter(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); DOMImplementationLS feature = (DOMImplementationLS) impl.getFeature("LS", "3.0"); LSSerializer serializer = feature.createLSSerializer(); LSOutput output = feature.createLSOutput(); output.setCharacterStream(sw); output.setEncoding("UTF-8"); serializer.write(doc, output); sw.flush(); return sw.toString(); } catch (Exception any) { M_log.warn("writeDocumentToString: " + any.toString()); return null; } }
From source file:org.wso2.appserver.webapp.security.utils.SSOUtils.java
/** * Serializes the specified SAML 2.0 based XML content representation to its corresponding actual XML syntax * representation./*from ww w .j a v a 2s.c o m*/ * * @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); } }
From source file:org.wso2.carbon.identity.application.authenticator.samlsso.util.SSOUtils.java
/** * Serializing a SAML2 object into a String * * @param xmlObject object that needs to serialized. * @return serialized object//www .j a v a2 s. c om * @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); } }
From source file:org.wso2.carbon.identity.auth.saml2.common.SAML2AuthUtils.java
public static String marshall(XMLObject xmlObject) { try {//from w w w . ja va 2 s. co m 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(StandardCharsets.UTF_8.toString()); } catch (InstantiationException | MarshallingException | IllegalAccessException | UnsupportedEncodingException | ClassNotFoundException e) { throw new IdentityRuntimeException("Error marshalling the XML object", e); } }
From source file:org.wso2.carbon.identity.authenticator.saml2.sso.common.Util.java
/** * Serializing a SAML2 object into a String * * @param xmlObject object that needs to serialized. * @return serialized object/*w ww.ja v a 2s .c o m*/ * @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); } }
From source file:org.wso2.carbon.identity.authenticator.saml2.sso.ui.Util.java
/** * Serializing a SAML2 object into a String * * @param xmlObject object that needs to serialized. * @return serialized object//from w ww . java2s . com * @throws org.wso2.carbon.identity.authenticator.saml2.sso.ui.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); } }
From source file:org.wso2.carbon.identity.entitlement.pep.agent.wsxacml.WSXACMLEntitlementServiceClient.java
/** * Serialize XML objects//from w ww . j a va 2 s . c om * * @param xmlObject : XACML or SAML objects to be serialized * @return serialized XACML or SAML objects */ private String marshall(XMLObject xmlObject) throws EntitlementAgentException { 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 EntitlementAgentException("Error Serializing the SAML Response", e); } }
From source file:org.wso2.carbon.identity.entitlement.proxy.wsxacml.WSXACMLEntitlementServiceClient.java
/** * Serialize XML objects/*from w w w . ja v a 2 s.co m*/ * * @param xmlObject : XACML or SAML objects to be serialized * @return serialized XACML or SAML objects */ private String marshall(XMLObject xmlObject) throws EntitlementProxyException { try { doBootstrap(); System.setProperty(DOCUMENT_BUILDER_FACTORY, DOCUMENT_BUILDER_FACTORY_IMPL); 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 new String(byteArrayOutputStrm.toByteArray(), Charset.forName("UTF-8")); } catch (Exception e) { log.error("Error Serializing the SAML Response"); throw new EntitlementProxyException("Error Serializing the SAML Response", e); } }
From source file:org.wso2.carbon.identity.entitlement.wsxacml.WSXACMLMessageReceiver.java
/** * `/*from ww w . j a v a 2 s . c o m*/ * 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); } }