use of javax.xml.transform.stream.StreamResult in project cas by apereo.
the class SamlUtils method transformSamlObject.
/**
* Transform saml object to String.
*
* @param configBean the config bean
* @param samlObject the saml object
* @return the string
* @throws SamlException the saml exception
*/
public static StringWriter transformSamlObject(final OpenSamlConfigBean configBean, final XMLObject samlObject) throws SamlException {
final StringWriter writer = new StringWriter();
try {
final Marshaller marshaller = configBean.getMarshallerFactory().getMarshaller(samlObject.getElementQName());
if (marshaller != null) {
final Element element = marshaller.marshall(samlObject);
final DOMSource domSource = new DOMSource(element);
final StreamResult result = new StreamResult(writer);
final TransformerFactory tf = TransformerFactory.newInstance();
final Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
}
} catch (final Exception e) {
throw new SamlException(e.getMessage(), e);
}
return writer;
}
use of javax.xml.transform.stream.StreamResult in project asciidoctor-fopub by asciidoctor.
the class InputHandler method transformTo.
/**
* In contrast to render(Fop) this method only performs the XSLT stage and saves the
* intermediate XSL-FO file to the output file.
* @param out OutputStream to write the transformation result to.
* @throws FOPException in case of an error during processing
*/
public void transformTo(OutputStream out) throws FOPException {
Result res = new StreamResult(out);
transformTo(res);
}
use of javax.xml.transform.stream.StreamResult in project cas by apereo.
the class DefaultRelyingPartyTokenProducer method serializeRelyingPartyToken.
private String serializeRelyingPartyToken(final Element rpToken) {
try {
final StringWriter sw = new StringWriter();
final Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, BooleanUtils.toStringYesNo(Boolean.TRUE));
t.transform(new DOMSource(rpToken), new StreamResult(sw));
return sw.toString();
} catch (final TransformerException e) {
throw Throwables.propagate(e);
}
}
use of javax.xml.transform.stream.StreamResult in project bazel by bazelbuild.
the class ManifestMergerAction method removePermissions.
private static Path removePermissions(Path manifest, Path outputDir) throws IOException, ParserConfigurationException, TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError, SAXException {
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = docBuilder.parse(manifest.toFile());
for (String tag : PERMISSION_TAGS) {
NodeList permissions = doc.getElementsByTagName(tag);
if (permissions != null) {
for (int i = permissions.getLength() - 1; i >= 0; i--) {
Node permission = permissions.item(i);
permission.getParentNode().removeChild(permission);
}
}
}
// Write resulting manifest to the output directory, maintaining full path to prevent collisions
Path output = outputDir.resolve(manifest.toString().replaceFirst("^/", ""));
Files.createDirectories(output.getParent());
TransformerFactory.newInstance().newTransformer().transform(new DOMSource(doc), new StreamResult(output.toFile()));
return output;
}
use of javax.xml.transform.stream.StreamResult in project gwt-test-utils by gwt-test-utils.
the class XMLParserTest method convertXMLFileToString.
private String convertXMLFileToString(String fileName) {
try {
InputStream inputStream = this.getClass().getResourceAsStream(fileName);
org.w3c.dom.Document doc = XmlUtils.newDocumentBuilder().parse(inputStream);
StringWriter stw = new StringWriter();
Transformer serializer = TransformerFactory.newInstance().newTransformer();
serializer.transform(new DOMSource(doc), new StreamResult(stw));
return stw.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations