use of javax.xml.transform.stream.StreamSource in project camel by apache.
the class XmlConverterTest method testToStreamSourceByStAXSource.
public void testToStreamSourceByStAXSource() throws Exception {
XmlConverter conv = new XmlConverter();
StAXSource source = conv.toStAXSource("<foo>bar</foo>", null);
StreamSource out = conv.toStreamSource(source, null);
assertNotSame(source, out);
assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
use of javax.xml.transform.stream.StreamSource in project camel by apache.
the class XmlConverterTest method testToStreamSourceByInputStream.
public void testToStreamSourceByInputStream() throws Exception {
XmlConverter conv = new XmlConverter();
InputStream is = context.getTypeConverter().convertTo(InputStream.class, "<foo>bar</foo>");
StreamSource out = conv.toStreamSource(is);
assertNotNull(out);
assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
use of javax.xml.transform.stream.StreamSource in project camel by apache.
the class StAX2SAXSourceTest method testDefaultPrefixInRootElementWithCopyTransformer.
public void testDefaultPrefixInRootElementWithCopyTransformer() throws Exception {
TransformerFactory trf = TransformerFactory.newInstance();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLStreamReader reader = context.getTypeConverter().mandatoryConvertTo(XMLStreamReader.class, new StringReader(TEST_XML));
// ensure UTF-8 encoding
Exchange exchange = new DefaultExchange(context);
exchange.setProperty(Exchange.CHARSET_NAME, UTF_8.toString());
XMLStreamWriter writer = context.getTypeConverter().mandatoryConvertTo(XMLStreamWriter.class, exchange, baos);
StAX2SAXSource staxSource = new StAX2SAXSource(reader);
StreamSource templateSource = new StreamSource(getClass().getResourceAsStream("/xslt/common/copy.xsl"));
Transformer transformer = trf.newTransformer(templateSource);
log.info("Used transformer: {}", transformer.getClass().getName());
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(staxSource, new StreamResult(baos));
writer.flush();
baos.flush();
assertThat(new String(baos.toByteArray()), equalTo(TEST_XML));
}
use of javax.xml.transform.stream.StreamSource in project camel by apache.
the class XmlConverterTest method testToStreamSourceByStreamSource.
public void testToStreamSourceByStreamSource() throws Exception {
Exchange exchange = new DefaultExchange(context);
XmlConverter conv = new XmlConverter();
StreamSource source = conv.toStreamSource("<foo>bar</foo>".getBytes(), exchange);
StreamSource out = conv.toStreamSource(source, null);
assertSame(source, out);
}
use of javax.xml.transform.stream.StreamSource in project camel by apache.
the class XmlConverterTest method testToStreamSourceByByteBuffer.
public void testToStreamSourceByByteBuffer() throws Exception {
Exchange exchange = new DefaultExchange(context);
XmlConverter conv = new XmlConverter();
ByteBuffer bytes = context.getTypeConverter().convertTo(ByteBuffer.class, "<foo>bar</foo>");
StreamSource out = conv.toStreamSource(bytes, exchange);
assertNotNull(out);
assertEquals("<foo>bar</foo>", conv.toString(out, null));
}
Aggregations