use of javax.xml.stream.XMLEventReader in project uPortal by Jasig.
the class XSLTComponentTest method testXSLTComponent.
@Test
public void testXSLTComponent() throws Exception {
final MockHttpServletRequest mockReq = new MockHttpServletRequest();
final MockHttpServletResponse mockRes = new MockHttpServletResponse();
final XMLEventReader xmlEventReader = this.getXmlEventReader("juser.xml");
final PipelineEventReaderImpl<XMLEventReader, XMLEvent> cacheableEventReader = new PipelineEventReaderImpl<XMLEventReader, XMLEvent>(xmlEventReader);
final Transformer transformer = this.getTransformer("columns.xsl");
final StAXPipelineComponent targetComponent = EasyMock.createMock(StAXPipelineComponent.class);
final TransformerSource transformerSource = EasyMock.createMock(TransformerSource.class);
EasyMock.expect(targetComponent.getEventReader(mockReq, mockRes)).andReturn(cacheableEventReader);
EasyMock.expect(transformerSource.getTransformer(mockReq, mockRes)).andReturn(transformer);
EasyMock.replay(targetComponent, transformerSource);
final XSLTComponent xsltComponent = new XSLTComponent();
xsltComponent.setWrappedComponent(targetComponent);
xsltComponent.setTransformerSource(transformerSource);
final PipelineEventReader<XMLEventReader, XMLEvent> eventReader = xsltComponent.getEventReader(mockReq, mockRes);
Assert.assertNotNull(eventReader);
final String output = this.serializeXMLEventReader(eventReader.getEventReader());
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setFeature("http://xml.org/sax/features/namespaces", false);
dbf.setFeature("http://xml.org/sax/features/validation", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
final DocumentBuilder db = dbf.newDocumentBuilder();
XMLUnit.setIgnoreWhitespace(true);
try {
final Document expected = db.parse(this.getClass().getResourceAsStream("/org/apereo/portal/rendering/xslt/expected.xml"), "/org/apereo/portal/rendering/xslt/expected.xml");
final Document actual = db.parse(new InputSource(new StringReader(output)));
Diff d = new Diff(expected, actual);
assertTrue("Upgraded data doesn't match expected data: " + d, d.similar());
} catch (Exception e) {
throw new XmlTestException("Failed to assert similar between XSLT output and expected XML", output, e);
} catch (Error e) {
throw new XmlTestException("Failed to assert similar between XSLT output and expected XML", output, e);
}
EasyMock.verify(targetComponent, transformerSource);
}
use of javax.xml.stream.XMLEventReader in project uPortal by Jasig.
the class PortletRenderingInitiationStAXComponent 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 PipelineEventReader<XMLEventReader, XMLEvent> pipelineEventReader = this.wrappedComponent.getEventReader(request, response);
final XMLEventReader eventReader = pipelineEventReader.getEventReader();
final PortletRenderingXMLEventReader filteredEventReader = new PortletRenderingXMLEventReader(request, response, eventReader);
final Map<String, String> outputProperties = pipelineEventReader.getOutputProperties();
return new PipelineEventReaderImpl<XMLEventReader, XMLEvent>(filteredEventReader, outputProperties);
}
use of javax.xml.stream.XMLEventReader in project uPortal by Jasig.
the class UserLayoutStoreComponent method getEventReader.
@Override
public PipelineEventReader<XMLEventReader, XMLEvent> getEventReader(HttpServletRequest request, HttpServletResponse response) {
final long timestamp = System.currentTimeMillis();
logger.debug("STARTING user layout fetch for user '{}' #milestone", request.getRemoteUser());
final IUserLayoutManager userLayoutManager = getUserLayoutManager(request);
final XMLEventReader userLayoutReader = userLayoutManager.getUserLayoutReader();
logger.debug("FINISHED user layout fetch for user '{}' in {}ms #milestone", request.getRemoteUser(), Long.toString(System.currentTimeMillis() - timestamp));
return new PipelineEventReaderImpl<XMLEventReader, XMLEvent>(userLayoutReader);
}
use of javax.xml.stream.XMLEventReader in project uPortal by Jasig.
the class AbstractDom4jImporter method convertToElement.
protected Element convertToElement(Source source) {
if (source instanceof StAXSource) {
final StAXSource staxSource = (StAXSource) source;
final DOMConverter domConverter = new DOMConverter();
final Document document;
try {
XMLStreamReader xmlStreamReader = staxSource.getXMLStreamReader();
if (xmlStreamReader == null) {
final XMLEventReader xmlEventReader = staxSource.getXMLEventReader();
xmlStreamReader = new FixedXMLEventStreamReader(xmlEventReader);
}
document = domConverter.buildDocument(xmlStreamReader);
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to parse StAX Reader into Dom4J Element", e);
}
final DOMReader domReader = new DOMReader();
final org.dom4j.Document dom4JDocument = domReader.read(document);
dom4JDocument.setName(source.getSystemId());
return dom4JDocument.getRootElement();
}
throw new IllegalArgumentException("Source of type " + source.getClass() + " is not supported");
}
use of javax.xml.stream.XMLEventReader in project uPortal by Jasig.
the class BufferedXMLEventReaderTest method testBufferNoEvents.
@Test
public void testBufferNoEvents() 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);
int eventCount = 0;
while (reader.hasNext()) {
reader.nextEvent();
eventCount++;
}
assertEquals(122, eventCount);
reader.reset();
while (reader.hasNext()) {
reader.nextEvent();
eventCount++;
}
assertEquals(122, eventCount);
}
Aggregations