Search in sources :

Example 11 with XMLEventWriter

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());
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLEventWriter(javax.xml.stream.XMLEventWriter) Before(org.junit.Before)

Example 12 with XMLEventWriter

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));
}
Also used : StringWriter(java.io.StringWriter) XMLEventWriter(javax.xml.stream.XMLEventWriter) XMLEvent(javax.xml.stream.events.XMLEvent) Test(org.junit.Test)

Example 13 with XMLEventWriter

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);
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) ChunkingEventReader(org.apereo.portal.xml.stream.ChunkingEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) CharacterEventBufferReader(org.apereo.portal.character.stream.CharacterEventBufferReader) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEventWriter(javax.xml.stream.XMLEventWriter) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader)

Example 14 with XMLEventWriter

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();
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) DOMResult(javax.xml.transform.dom.DOMResult) XMLEventWriter(javax.xml.stream.XMLEventWriter) IndentingXMLEventWriter(org.apereo.portal.xml.stream.IndentingXMLEventWriter)

Aggregations

XMLEventWriter (javax.xml.stream.XMLEventWriter)14 StringWriter (java.io.StringWriter)10 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)9 XMLEvent (javax.xml.stream.events.XMLEvent)5 Test (org.junit.Test)5 XMLStreamException (javax.xml.stream.XMLStreamException)4 XMLEventReader (javax.xml.stream.XMLEventReader)3 DOMResult (javax.xml.transform.dom.DOMResult)3 Result (javax.xml.transform.Result)2 StAXResult (javax.xml.transform.stax.StAXResult)2 StreamResult (javax.xml.transform.stream.StreamResult)2 IndentingXMLEventWriter (org.apereo.portal.xml.stream.IndentingXMLEventWriter)2 ImmutableList (com.google.common.collect.ImmutableList)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Nullable (javax.annotation.Nullable)1 FactoryConfigurationError (javax.xml.stream.FactoryConfigurationError)1 XMLEventFactory (javax.xml.stream.XMLEventFactory)1