use of javax.xml.transform.stream.StreamResult in project camel by apache.
the class SaxonUriResolverTest method test.
@Test
public void test() throws Exception {
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
Source xsl = fromClasspath(XSL_PATH);
xsl.setSystemId("classpath:/" + XSL_PATH);
Source xml = fromString(XML_DATA);
TransformerFactory factory = new TransformerFactoryImpl();
Transformer transformer = factory.newTransformer(xsl);
transformer.setURIResolver(new XsltUriResolver(context(), XSL_PATH));
transformer.transform(xml, result);
Assert.assertEquals(XML_RESP, writer.toString());
}
use of javax.xml.transform.stream.StreamResult in project camel by apache.
the class EipDocumentationEnricherMojo method saveToFile.
private void saveToFile(Document document, File outputFile, Transformer transformer) throws FileNotFoundException, TransformerException {
StreamResult result = new StreamResult(new FileOutputStream(outputFile));
DOMSource source = new DOMSource(document);
transformer.transform(source, result);
}
use of javax.xml.transform.stream.StreamResult in project camel by apache.
the class SpringBootStarterMojo method writeXmlFormatted.
private void writeXmlFormatted(Document pom, File destination) throws Exception {
XPathExpression xpath = XPathFactory.newInstance().newXPath().compile("//text()[normalize-space(.) = '']");
NodeList emptyNodes = (NodeList) xpath.evaluate(pom, XPathConstants.NODESET);
// Remove empty text nodes
for (int i = 0; i < emptyNodes.getLength(); i++) {
Node emptyNode = emptyNodes.item(i);
emptyNode.getParentNode().removeChild(emptyNode);
}
pom.setXmlStandalone(true);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
DOMSource source = new DOMSource(pom);
String content;
try (StringWriter out = new StringWriter()) {
StreamResult result = new StreamResult(out);
transformer.transform(source, result);
content = out.toString();
}
// Fix header formatting problem
content = content.replaceFirst("-->", "-->\n").replaceFirst("\\?><!--", "\\?>\n<!--");
writeIfChanged(content, destination);
}
use of javax.xml.transform.stream.StreamResult in project camel by apache.
the class ConsumerEndpointMappingByBeanNameRouteTest method testBeanName.
@Test
public void testBeanName() throws Exception {
StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuote));
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
webServiceTemplate.sendSourceAndReceiveToResult(source, result);
assertNotNull(result);
TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString());
}
use of javax.xml.transform.stream.StreamResult in project camel by apache.
the class ConsumerEndpointMappingResponseHandlingRouteTest method testRootQName.
@Test
public void testRootQName() throws Exception {
StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuote));
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
webServiceTemplate.sendSourceAndReceiveToResult(source, result);
assertNotNull(result);
TestUtil.assertEqualsIgnoreNewLinesSymbol(expectedResponse, sw.toString());
}
Aggregations