use of org.springframework.xml.transform.StringSource in project spring-integration by spring-projects.
the class XsltPayloadTransformer method transformString.
private String transformString(String stringPayload, Transformer transformer) throws TransformerException {
StringResult result = new StringResult();
Source source;
if (this.alwaysUseSourceFactory) {
source = this.sourceFactory.createSource(stringPayload);
} else {
source = new StringSource(stringPayload);
}
transformer.transform(source, result);
return result.toString();
}
use of org.springframework.xml.transform.StringSource in project spring-integration by spring-projects.
the class StringSourceTests method testWithString.
@Test
public void testWithString() throws Exception {
String docString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><item>one</item>";
StringSource source = (StringSource) sourceFactory.createSource(docString);
BufferedReader reader = new BufferedReader(source.getReader());
String docAsString = reader.readLine();
assertXMLEqual("Wrong content in StringSource", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><item>one</item>", docAsString);
}
use of org.springframework.xml.transform.StringSource in project spring-integration by spring-projects.
the class StringSourceTests method testWithUnsupportedPayload.
@Test(expected = MessagingException.class)
public void testWithUnsupportedPayload() throws Exception {
String docString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><item>one</item>";
StringBuffer buffer = new StringBuffer(docString);
StringSource source = (StringSource) sourceFactory.createSource(buffer);
BufferedReader reader = new BufferedReader(source.getReader());
String docAsString = reader.readLine();
assertXMLEqual("Wrong content in StringSource", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><item>one</item>", docAsString);
}
use of org.springframework.xml.transform.StringSource in project spring-integration by spring-projects.
the class StubMarshaller method marshal.
public void marshal(Object graph, Result result) throws XmlMappingException, IOException {
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
StringSource stringSource = new StringSource("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><root>" + graph.toString() + "</root>");
transformer.transform(stringSource, result);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.springframework.xml.transform.StringSource in project spring-integration by spring-projects.
the class XsltPayloadTransformerTests method testSourceAsPayload.
@Test
public void testSourceAsPayload() throws Exception {
Object transformed = transformer.doTransform(buildMessage(new StringSource(docAsString)));
assertEquals("Wrong return type for source payload", DOMResult.class, transformed.getClass());
DOMResult result = (DOMResult) transformed;
assertXMLEqual("Document incorrect after transformation", XmlTestUtil.getDocumentForString(outputAsString), (Document) result.getNode());
}
Aggregations