use of javax.xml.stream.XMLEventReader in project uPortal by Jasig.
the class WindowStateSettingsStAXComponent 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 IStylesheetDescriptor stylesheetDescriptor = stylesheetAttributeSource.getStylesheetDescriptor(request);
final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
final XMLEventReader filteredEventReader;
if (portalRequestInfo.getTargetedPortletWindowId() == null) {
final IStylesheetParameterDescriptor defaultWindowStateParam = stylesheetDescriptor.getStylesheetParameterDescriptor("dashboardForcedWindowState");
if (defaultWindowStateParam != null) {
//Set all window states to the specified default
final WindowState windowState = PortletUtils.getWindowState(defaultWindowStateParam.getDefaultValue());
filteredEventReader = new SinglePortletWindowStateSettingXMLEventReader(request, eventReader, windowState);
} else {
//Make sure there aren't any portlets in a "targeted" window state
filteredEventReader = new NonTargetedPortletWindowStateSettingXMLEventReader(request, eventReader);
}
} else {
//Not mobile, don't bother filtering
filteredEventReader = 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 XsltPortalUrlProviderTest method setup.
@Before
public void setup() throws Exception {
final ResourceLoaderURIResolver resolver = new ResourceLoaderURIResolver(new ClassRelativeResourceLoader(getClass()));
this.tFactory = TransformerFactory.newInstance();
this.tFactory.setURIResolver(resolver);
this.tFactory.setErrorListener(new SimpleTransformErrorListener(LogFactory.getLog(getClass())));
//Load the XML document so it reads the same way the rendering pipeline reads XML
final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
final XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(this.getClass().getResourceAsStream("test.xml"));
final XMLStreamReader streamReader = new FixedXMLEventStreamReader(eventReader);
xmlSource = new StAXSource(streamReader);
xslTemplate = tFactory.newTemplates(new StreamSource(this.getClass().getResourceAsStream("test.xsl")));
expected = IOUtils.toString(this.getClass().getResourceAsStream("result.xml"));
}
use of javax.xml.stream.XMLEventReader in project uPortal by Jasig.
the class XSLTComponentTest method getXmlEventReader.
protected XMLEventReader getXmlEventReader(String file) throws SAXException, IOException, ParserConfigurationException {
final InputStream xmlStream = this.getClass().getResourceAsStream(file);
final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
final Document document = documentBuilder.parse(xmlStream);
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
final XMLEventReader xmlEventReader;
try {
xmlEventReader = inputFactory.createXMLEventReader(new DOMSource(document, "foobar"));
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to create XMLStreamReader for file '" + file + "'", e);
}
return xmlEventReader;
}
use of javax.xml.stream.XMLEventReader in project uPortal by Jasig.
the class CachingStAXPipelineComponentTest method testCacheMiss.
@Test
public void testCacheMiss() {
final MockHttpServletRequest mockReq = new MockHttpServletRequest();
final MockHttpServletResponse mockRes = new MockHttpServletResponse();
final CacheKey cacheKey = CacheKey.build("testCacheKey");
final List<XMLEvent> eventBuffer = Collections.emptyList();
final PipelineEventReader<XMLEventReader, XMLEvent> eventReader = new PipelineEventReaderImpl<XMLEventReader, XMLEvent>(new XMLEventBufferReader(eventBuffer.listIterator()));
final Ehcache cache = createMock(Ehcache.class);
final StAXPipelineComponent targetComponent = createMock(StAXPipelineComponent.class);
final ResourcesElementsProvider elementsProvider = createMock(ResourcesElementsProvider.class);
expect(elementsProvider.getDefaultIncludedType()).andReturn(Included.AGGREGATED);
expect(targetComponent.getCacheKey(mockReq, mockRes)).andReturn(cacheKey);
expect(cache.get(cacheKey)).andReturn(null);
expect(targetComponent.getEventReader(mockReq, mockRes)).andReturn(eventReader);
cache.put((Element) notNull());
expectLastCall();
replay(cache, targetComponent, elementsProvider);
final CachingStAXPipelineComponent cachingComponent = new CachingStAXPipelineComponent();
cachingComponent.setCache(cache);
cachingComponent.setWrappedComponent(targetComponent);
cachingComponent.setResourcesElementsProvider(elementsProvider);
final PipelineEventReader<XMLEventReader, XMLEvent> actualEventReader = cachingComponent.getEventReader(mockReq, mockRes);
Assert.assertNotNull(actualEventReader);
Assert.assertNotNull(actualEventReader.getEventReader());
Assert.assertFalse(actualEventReader.getEventReader().hasNext());
verify(cache, targetComponent, elementsProvider);
}
use of javax.xml.stream.XMLEventReader in project galley by Commonjava.
the class XMLInfrastructure method fallbackParseDocument.
private Document fallbackParseDocument(String xml, final Object docSource, final Exception e) throws GalleyMavenXMLException {
logger.debug("Failed to parse: {}. DOM error: {}. Trying STaX parse with IS_REPLACING_ENTITY_REFERENCES == false...", e, docSource, e.getMessage());
try {
Source source;
if (safeInputFactory != null) {
xml = repairXmlDeclaration(xml);
final XMLEventReader eventReader = safeInputFactory.createXMLEventReader(new StringReader(xml));
source = new StAXSource(eventReader);
} else {
// Deal with ø and other undeclared entities...
xml = escapeNonXMLEntityRefs(xml);
final XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setFeature("http://xml.org/sax/features/validation", false);
source = new SAXSource(reader, new InputSource(new StringReader(xml)));
}
final DOMResult result = new DOMResult();
final Transformer transformer = newTransformer();
transformer.transform(source, result);
return (Document) result.getNode();
} catch (final TransformerException e1) {
throw new GalleyMavenXMLException("Failed to parse: %s. Transformer error: %s.\nOriginal DOM error: %s", e1, docSource, e1.getMessage(), e.getMessage());
} catch (final SAXException e1) {
throw new GalleyMavenXMLException("Failed to parse: %s. SAX error: %s.\nOriginal DOM error: %s", e1, docSource, e1.getMessage(), e.getMessage());
} catch (final XMLStreamException e1) {
throw new GalleyMavenXMLException("Failed to parse: %s. STaX error: %s.\nOriginal DOM error: %s", e1, docSource, e1.getMessage(), e.getMessage());
}
}
Aggregations