Search in sources :

Example 71 with SAXSource

use of javax.xml.transform.sax.SAXSource in project camel by apache.

the class XmlConverterTest method testOutOptionsFromCamelContext.

public void testOutOptionsFromCamelContext() throws Exception {
    CamelContext context = new DefaultCamelContext();
    Exchange exchange = new DefaultExchange(context);
    // shows how to set the OutputOptions from camelContext
    context.getGlobalOptions().put(XmlConverter.OUTPUT_PROPERTIES_PREFIX + OutputKeys.ENCODING, "UTF-8");
    context.getGlobalOptions().put(XmlConverter.OUTPUT_PROPERTIES_PREFIX + OutputKeys.STANDALONE, "no");
    XmlConverter conv = new XmlConverter();
    SAXSource source = conv.toSAXSource("<foo>bar</foo>", exchange);
    DOMSource out = conv.toDOMSource(source, exchange);
    assertNotSame(source, out);
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><foo>bar</foo>", conv.toString(out, exchange));
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DOMSource(javax.xml.transform.dom.DOMSource) SAXSource(javax.xml.transform.sax.SAXSource) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 72 with SAXSource

use of javax.xml.transform.sax.SAXSource in project camel by apache.

the class XmlConverterTest method testToDomElement.

public void testToDomElement() throws Exception {
    XmlConverter conv = new XmlConverter();
    SAXSource source = conv.toSAXSource("<foo>bar</foo>", null);
    Element out = conv.toDOMElement(source);
    assertNotNull(out);
    assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, out));
}
Also used : SAXSource(javax.xml.transform.sax.SAXSource) Element(org.w3c.dom.Element)

Example 73 with SAXSource

use of javax.xml.transform.sax.SAXSource in project camel by apache.

the class MultiCastParallelAndStreamCachingTest method testSourceCache.

public void testSourceCache() throws Exception {
    String input = "<A>a</A>";
    MockEndpoint mock = getMockEndpoint("mock:resulta");
    mock.expectedBodiesReceived(input);
    mock = getMockEndpoint("mock:resultb");
    mock.expectedBodiesReceived(input);
    StringSource ss = new StringSource(input);
    SAXSource saxSource = new SAXSource(SAXSource.sourceToInputSource(ss));
    template.sendBody("direct:start", saxSource);
    assertMockEndpointsSatisfied();
}
Also used : SAXSource(javax.xml.transform.sax.SAXSource) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) StringSource(org.apache.camel.StringSource)

Example 74 with SAXSource

use of javax.xml.transform.sax.SAXSource in project camel by apache.

the class XmlConverterTest method testToReaderFromSource.

public void testToReaderFromSource() throws Exception {
    XmlConverter conv = new XmlConverter();
    SAXSource source = conv.toSAXSource("<foo>bar</foo>", null);
    Reader out = conv.toReaderFromSource(source, null);
    assertNotNull(out);
    assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, out));
}
Also used : SAXSource(javax.xml.transform.sax.SAXSource) Reader(java.io.Reader)

Example 75 with SAXSource

use of javax.xml.transform.sax.SAXSource in project camel by apache.

the class XmlConverterTest method testToSaxSourceFromFile.

public void testToSaxSourceFromFile() throws Exception {
    XmlConverter conv = new XmlConverter();
    template.sendBodyAndHeader("file:target/xml", "<foo>bar</foo>", Exchange.FILE_NAME, "myxml.xml");
    File file = new File("target/xml/myxml.xml");
    SAXSource out = conv.toSAXSource(file, null);
    assertNotNull(out);
    assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, out));
}
Also used : SAXSource(javax.xml.transform.sax.SAXSource) File(java.io.File)

Aggregations

SAXSource (javax.xml.transform.sax.SAXSource)111 InputSource (org.xml.sax.InputSource)81 XMLReader (org.xml.sax.XMLReader)38 Source (javax.xml.transform.Source)28 StreamSource (javax.xml.transform.stream.StreamSource)28 DOMSource (javax.xml.transform.dom.DOMSource)27 SAXException (org.xml.sax.SAXException)26 TransformerException (javax.xml.transform.TransformerException)24 SAXParserFactory (javax.xml.parsers.SAXParserFactory)20 Unmarshaller (javax.xml.bind.Unmarshaller)17 SAXParser (javax.xml.parsers.SAXParser)17 Transformer (javax.xml.transform.Transformer)17 StreamResult (javax.xml.transform.stream.StreamResult)16 Test (org.junit.Test)16 StringReader (java.io.StringReader)15 IOException (java.io.IOException)14 JAXBContext (javax.xml.bind.JAXBContext)14 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)11 ValidationEvent (javax.xml.bind.ValidationEvent)10