use of javax.xml.stream.XMLEventWriter in project spring-framework by spring-projects.
the class XMLEventStreamWriterTests method createStreamReader.
@Before
public void createStreamReader() throws Exception {
stringWriter = new StringWriter();
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(stringWriter);
streamWriter = new XMLEventStreamWriter(eventWriter, XMLEventFactory.newInstance());
}
use of javax.xml.stream.XMLEventWriter in project spring-framework by spring-projects.
the class ListBasedXMLEventReaderTests method standard.
@Test
public void standard() throws Exception {
String xml = "<foo><bar>baz</bar></foo>";
List<XMLEvent> events = readEvents(xml);
ListBasedXMLEventReader reader = new ListBasedXMLEventReader(events);
StringWriter resultWriter = new StringWriter();
XMLEventWriter writer = this.outputFactory.createXMLEventWriter(resultWriter);
writer.add(reader);
assertThat(resultWriter.toString(), isSimilarTo(xml));
}
use of javax.xml.stream.XMLEventWriter in project uPortal by Jasig.
the class StAXSerializingComponent method getEventReader.
@Override
public PipelineEventReader<CharacterEventReader, CharacterEvent> getEventReader(HttpServletRequest request, HttpServletResponse response) {
final PipelineEventReader<XMLEventReader, XMLEvent> eventReader = this.wrappedComponent.getEventReader(request, response);
//Writer shared by the ChunkingEventReader and the StAX Serializer
final StringWriter writer = new StringWriter();
final XMLOutputFactory outputFactory = this.xmlUtilities.getHtmlOutputFactory();
final XMLEventWriter xmlEventWriter;
try {
xmlEventWriter = outputFactory.createXMLEventWriter(writer);
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to create XMLEventWriter", e);
}
//Add the chunking wrapper to the XMLEventReader
final XMLEventReader xmlEventReader = eventReader.getEventReader();
final ChunkingEventReader chunkingEventReader = new ChunkingEventReader(request, this.chunkingElements, this.chunkingPatternEventSources, this.chunkingPatterns, xmlEventReader, xmlEventWriter, writer);
try {
xmlEventWriter.add(chunkingEventReader);
xmlEventWriter.flush();
xmlEventWriter.close();
chunkingEventReader.close();
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to write events to Writer", e);
}
//Return the chunked data
final List<CharacterEvent> characterEvents = chunkingEventReader.getCharacterEvents();
final CharacterEventBufferReader characterEventReader = new CharacterEventBufferReader(characterEvents.listIterator());
final Map<String, String> outputProperties = eventReader.getOutputProperties();
return new PipelineEventReaderImpl<CharacterEventReader, CharacterEvent>(characterEventReader, outputProperties);
}
use of javax.xml.stream.XMLEventWriter in project uPortal by Jasig.
the class XmlUtilitiesImpl method convertToDom.
@Override
public Node convertToDom(XMLEventReader xmlEventReader) throws XMLStreamException {
//Convert the XmlEventReader into a DOM
final XMLOutputFactory xmlOutputFactory = this.getXmlOutputFactory();
final DOMResult sourceDom = new DOMResult(DocumentFactory.getThreadDocument());
final XMLEventWriter sourceWriter = xmlOutputFactory.createXMLEventWriter(sourceDom);
sourceWriter.add(xmlEventReader);
sourceWriter.flush();
sourceWriter.close();
return sourceDom.getNode();
}
Aggregations