Search in sources :

Example 36 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project uPortal by Jasig.

the class BufferedXMLEventReaderTest method testBufferSomeEvents.

@Test
public void testBufferSomeEvents() throws Exception {
    final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
    final InputStream xmlStream = this.getClass().getResourceAsStream("document.xml");
    final XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(xmlStream);
    final BufferedXMLEventReader reader = new BufferedXMLEventReader(xmlEventReader, 10);
    int eventCount = 0;
    while (reader.hasNext()) {
        reader.nextEvent();
        eventCount++;
    }
    assertEquals(122, eventCount);
    reader.reset();
    while (reader.hasNext()) {
        reader.nextEvent();
        eventCount++;
    }
    assertEquals(132, eventCount);
}
Also used : InputStream(java.io.InputStream) XMLEventReader(javax.xml.stream.XMLEventReader) XMLInputFactory(javax.xml.stream.XMLInputFactory) Test(org.junit.Test)

Example 37 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project uPortal by Jasig.

the class BufferedXMLEventReaderTest method testBufferAllEvents.

@Test
public void testBufferAllEvents() throws Exception {
    final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
    final InputStream xmlStream = this.getClass().getResourceAsStream("document.xml");
    final XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(xmlStream);
    final BufferedXMLEventReader reader = new BufferedXMLEventReader(xmlEventReader, -1);
    final XMLEvent firstEvent = reader.peek();
    int eventCount = 0;
    while (reader.hasNext()) {
        reader.nextEvent();
        eventCount++;
    }
    assertEquals(122, eventCount);
    reader.reset();
    final XMLEvent firstEventAgain = reader.peek();
    assertEquals(firstEvent, firstEventAgain);
    while (reader.hasNext()) {
        reader.nextEvent();
        eventCount++;
    }
    assertEquals(244, eventCount);
}
Also used : InputStream(java.io.InputStream) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) XMLInputFactory(javax.xml.stream.XMLInputFactory) Test(org.junit.Test)

Example 38 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project uPortal by Jasig.

the class Dom2StAXTest method testDom2StAXEventReader.

@Test
public void testDom2StAXEventReader() throws Exception {
    final XMLInputFactory newFactory = XMLInputFactory.newFactory();
    final DOMSource source = new DOMSource(this.document);
    newFactory.createXMLEventReader(source);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) XMLInputFactory(javax.xml.stream.XMLInputFactory) Test(org.junit.Test)

Example 39 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project uPortal by Jasig.

the class Dom2StAXTest method testDom2StAXStreamReader.

@Test
public void testDom2StAXStreamReader() throws Exception {
    final XMLInputFactory newFactory = XMLInputFactory.newFactory();
    final DOMSource source = new DOMSource(this.document);
    newFactory.createXMLStreamReader(source);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) XMLInputFactory(javax.xml.stream.XMLInputFactory) Test(org.junit.Test)

Example 40 with XMLInputFactory

use of javax.xml.stream.XMLInputFactory in project uPortal by Jasig.

the class StaticDocumentComponent method getEventReader.

/* (non-Javadoc)
     * @see org.apereo.portal.rendering.PipelineComponent#getEventReader(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
public PipelineEventReader<XMLEventReader, XMLEvent> getEventReader(HttpServletRequest request, HttpServletResponse response) {
    final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder documentBuilder;
    try {
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
    final InputStream documentStream;
    try {
        documentStream = this.document.getInputStream();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    final Document document;
    try {
        document = documentBuilder.parse(documentStream);
    } catch (SAXException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(documentStream);
    }
    final XMLInputFactory inputFactory = XMLInputFactory.newFactory();
    final DOMSource source = new DOMSource(document);
    final XMLEventReader streamReader;
    try {
        streamReader = inputFactory.createXMLEventReader(source);
    } catch (XMLStreamException e) {
        throw new RuntimeException(e);
    }
    return new PipelineEventReaderImpl<XMLEventReader, XMLEvent>(streamReader);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) InputStream(java.io.InputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) XMLStreamException(javax.xml.stream.XMLStreamException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) XMLEventReader(javax.xml.stream.XMLEventReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

XMLInputFactory (javax.xml.stream.XMLInputFactory)182 XMLStreamReader (javax.xml.stream.XMLStreamReader)114 XMLStreamException (javax.xml.stream.XMLStreamException)74 InputStream (java.io.InputStream)54 StringReader (java.io.StringReader)45 IOException (java.io.IOException)40 XMLEventReader (javax.xml.stream.XMLEventReader)36 ByteArrayInputStream (java.io.ByteArrayInputStream)30 Test (org.junit.Test)29 InputStreamReader (java.io.InputStreamReader)19 Unmarshaller (javax.xml.bind.Unmarshaller)18 XMLEvent (javax.xml.stream.events.XMLEvent)15 StAXSource (javax.xml.transform.stax.StAXSource)15 StreamSource (javax.xml.transform.stream.StreamSource)15 ArrayList (java.util.ArrayList)14 JAXBException (javax.xml.bind.JAXBException)14 HashMap (java.util.HashMap)13 DOMSource (javax.xml.transform.dom.DOMSource)12 StartElement (javax.xml.stream.events.StartElement)10 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)10