use of javax.xml.transform.Result in project spring-framework by spring-projects.
the class Jaxb2MarshallerTests method marshalInvalidClass.
@Test(expected = XmlMappingException.class)
public void marshalInvalidClass() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(FlightType.class);
marshaller.afterPropertiesSet();
Result result = new StreamResult(new StringWriter());
Flights flights = new Flights();
marshaller.marshal(flights, result);
}
use of javax.xml.transform.Result in project spring-framework by spring-projects.
the class XStreamMarshallerTests method marshalStaxResultXMLStreamWriter.
@Test
public void marshalStaxResultXMLStreamWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
Result result = StaxUtils.createStaxResult(streamWriter);
marshaller.marshal(flight, result);
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
}
use of javax.xml.transform.Result in project spring-framework by spring-projects.
the class MarshallingMessageConverter method convertToInternal.
@Override
protected Object convertToInternal(Object payload, MessageHeaders headers, Object conversionHint) {
Assert.notNull(this.marshaller, "Property 'marshaller' is required");
try {
if (byte[].class == getSerializedPayloadClass()) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Result result = new StreamResult(out);
this.marshaller.marshal(payload, result);
payload = out.toByteArray();
} else {
Writer writer = new StringWriter();
Result result = new StreamResult(writer);
this.marshaller.marshal(payload, result);
payload = writer.toString();
}
} catch (Exception ex) {
throw new MessageConversionException("Could not marshal XML: " + ex.getMessage(), ex);
}
return payload;
}
use of javax.xml.transform.Result in project spring-framework by spring-projects.
the class AbstractMarshallerTests method marshalStaxResultEventWriter.
@Test
public void marshalStaxResultEventWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
StringWriter writer = new StringWriter();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
Result result = StaxUtils.createStaxResult(eventWriter);
marshaller.marshal(flights, result);
assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
}
use of javax.xml.transform.Result in project cubrid-manager by CUBRID.
the class XMLMemento method save.
/**
* Save this Memento to a stream.
*
* @param os OutputStream the output stream
* @throws IOException if anything goes wrong
*/
public void save(OutputStream os) throws IOException {
Result result = new StreamResult(os);
Source source = new DOMSource(document);
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2");
transformer.transform(source, result);
} catch (Exception e) {
throw (IOException) (new IOException().initCause(e));
}
}
Aggregations