Search in sources :

Example 1 with ChunkingEventReader

use of org.apereo.portal.xml.stream.ChunkingEventReader 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)

Aggregations

StringWriter (java.io.StringWriter)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLEventWriter (javax.xml.stream.XMLEventWriter)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLEvent (javax.xml.stream.events.XMLEvent)1 CharacterEventBufferReader (org.apereo.portal.character.stream.CharacterEventBufferReader)1 CharacterEvent (org.apereo.portal.character.stream.events.CharacterEvent)1 ChunkingEventReader (org.apereo.portal.xml.stream.ChunkingEventReader)1