use of org.apereo.portal.character.stream.events.CharacterEvent in project uPortal by Jasig.
the class LoggingCharacterComponent method getEventReader.
/* (non-Javadoc)
* @see org.apereo.portal.rendering.PipelineComponent#getEventReader(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public PipelineEventReader<CharacterEventReader, CharacterEvent> getEventReader(HttpServletRequest request, HttpServletResponse response) {
final PipelineEventReader<CharacterEventReader, CharacterEvent> pipelineEventReader = this.wrappedComponent.getEventReader(request, response);
final CharacterEventReader eventReader = pipelineEventReader.getEventReader();
final LoggingCharacterEventReader loggingEventReader = new LoggingCharacterEventReader(eventReader);
final Map<String, String> outputProperties = pipelineEventReader.getOutputProperties();
return new PipelineEventReaderImpl<CharacterEventReader, CharacterEvent>(loggingEventReader, outputProperties);
}
use of org.apereo.portal.character.stream.events.CharacterEvent in project uPortal by Jasig.
the class DynamicRenderingPipeline method renderState.
@Override
public void renderState(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
//Disable page caching
res.setHeader("pragma", "no-cache");
res.setHeader("Cache-Control", "no-cache, max-age=0, must-revalidate");
res.setDateHeader("Expires", 0);
final long startTime = System.nanoTime();
final PipelineEventReader<CharacterEventReader, CharacterEvent> pipelineEventReader = this.pipeline.getEventReader(req, res);
final String mediaType = getMediaType(req, res, pipelineEventReader);
// set the response mime type
final String contentType = mediaType + "; charset=" + CHARACTER_SET;
res.setContentType(contentType);
final PrintWriter writer = res.getWriter();
for (final CharacterEvent event : pipelineEventReader) {
if (CharacterEventTypes.CHARACTER != event.getEventType()) {
throw new RenderingPipelineConfigurationException("Only " + CharacterEventTypes.CHARACTER + " events are supported in the top level renderer. " + event.getEventType() + " is not supported.");
}
final String data = ((CharacterDataEvent) event).getData();
writer.print(data);
writer.flush();
res.flushBuffer();
}
final long executionTime = System.nanoTime() - startTime;
final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(req);
this.portalEventFactory.publishPortalRenderEvent(req, this, req.getPathInfo(), executionTime, portalRequestInfo);
}
use of org.apereo.portal.character.stream.events.CharacterEvent in project uPortal by Jasig.
the class StAXSerializingComponentTest method testSerializing.
@Test
public void testSerializing() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
final IPortletWindowRegistry portletWindowRegistry = mock(IPortletWindowRegistry.class);
when(xmlUtilities.getHtmlOutputFactory()).thenReturn(XMLOutputFactory.newFactory());
//Setup a simple pass-through parent
staxSerializingComponent.setWrappedComponent(new SimpleStAXSource());
staxSerializingComponent.setXmlUtilities(xmlUtilities);
final IPortletWindow portletWindow = mock(IPortletWindow.class);
when(portletWindowRegistry.getPortletWindow(Matchers.eq(request), Matchers.any(StartElement.class))).thenReturn(new Tuple<IPortletWindow, StartElement>(portletWindow, null));
when(portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(Matchers.eq(request), Matchers.anyString())).thenReturn(portletWindow);
final PortletContentPlaceholderEventSource contentPlaceholderEventSource = new PortletContentPlaceholderEventSource();
contentPlaceholderEventSource.setPortletWindowRegistry(portletWindowRegistry);
final PortletHeaderPlaceholderEventSource headerPlaceholderEventSource = new PortletHeaderPlaceholderEventSource();
headerPlaceholderEventSource.setPortletWindowRegistry(portletWindowRegistry);
final PortletTitlePlaceholderEventSource portletTitlePlaceholderEventSource = new PortletTitlePlaceholderEventSource();
portletTitlePlaceholderEventSource.setPortletWindowRegistry(portletWindowRegistry);
final PortletHelpPlaceholderEventSource portletHelpPlaceholderEventSource = new PortletHelpPlaceholderEventSource();
portletHelpPlaceholderEventSource.setPortletWindowRegistry(portletWindowRegistry);
final Map<String, CharacterEventSource> chunkingElements = new LinkedHashMap<String, CharacterEventSource>();
chunkingElements.put("portlet", contentPlaceholderEventSource);
chunkingElements.put("portlet-header", headerPlaceholderEventSource);
staxSerializingComponent.setChunkingElements(chunkingElements);
final Map<String, CharacterEventSource> chunkingPatterns = new LinkedHashMap<String, CharacterEventSource>();
chunkingPatterns.put("\\{up-portlet-title\\(([^\\)]+)\\)\\}", portletTitlePlaceholderEventSource);
chunkingPatterns.put("\\{up-portlet-help\\(([^\\)]+)\\)\\}", portletHelpPlaceholderEventSource);
staxSerializingComponent.setChunkingPatterns(chunkingPatterns);
final PipelineEventReader<CharacterEventReader, CharacterEvent> eventReader = staxSerializingComponent.getEventReader(request, response);
//Expected events structure, leaving the data out to make it at least a little simpler
final List<? extends CharacterEvent> expectedEvents = this.getExpectedEvents();
final Iterator<CharacterEvent> eventItr = eventReader.iterator();
final Iterator<? extends CharacterEvent> expectedEventsItr = expectedEvents.iterator();
int eventCount = 0;
while (expectedEventsItr.hasNext()) {
eventCount++;
assertTrue("The number of events returned by the eventReader less than the expected event count of: " + expectedEvents.size() + " was: " + eventCount, eventItr.hasNext());
final CharacterEvent expectedEvent = expectedEventsItr.next();
final CharacterEvent event = eventItr.next();
assertEquals("Events at index " + eventCount + " do not match\n" + expectedEvent + "\n" + event, expectedEvent, event);
}
assertFalse("The number of events returned by the eventReader is more than the expected event count of: " + expectedEvents.size(), eventItr.hasNext());
}
use of org.apereo.portal.character.stream.events.CharacterEvent in project uPortal by Jasig.
the class FilteringCharacterEventReader method internalNext.
protected final CharacterEvent internalNext(boolean peek) {
CharacterEvent event = null;
if (peekedEvent != null) {
event = peekedEvent;
peekedEvent = null;
return event;
}
do {
event = super.next();
event = this.filterEvent(event, peek);
} while (event == null);
return event;
}
Aggregations