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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations