Search in sources :

Example 21 with IPortalRequestInfo

use of org.apereo.portal.url.IPortalRequestInfo in project uPortal by Jasig.

the class PortalEventFactoryImpl method publishPortletResourceExecutionEvent.

@Override
public void publishPortletResourceExecutionEvent(HttpServletRequest request, Object source, IPortletWindowId portletWindowId, long executionTime, boolean usedBrowserCache, boolean usedPortalCache) {
    final PortalEvent.PortalEventBuilder eventBuilder = this.createPortalEventBuilder(source, request);
    final PortletExecutionEvent.PortletExecutionEventBuilder portletEventBuilder = this.createPortletExecutionEventBuilder(eventBuilder, portletWindowId, executionTime, false);
    // Get the resource Id
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    final String resourceId = getResourceId(portletWindowId, portalRequestInfo);
    final PortletResourceExecutionEvent portletResourceExecutionEvent = new PortletResourceExecutionEvent(portletEventBuilder, resourceId, usedBrowserCache, usedPortalCache);
    this.applicationEventPublisher.publishEvent(portletResourceExecutionEvent);
}
Also used : IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo)

Example 22 with IPortalRequestInfo

use of org.apereo.portal.url.IPortalRequestInfo in project uPortal by Jasig.

the class PortalController method actionRequest.

/**
 * HTTP POST required for security.
 */
@RequestMapping(headers = { "org.apereo.portal.url.UrlType=ACTION" }, method = RequestMethod.POST)
public void actionRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    final IPortletRequestInfo portletRequestInfo = portalRequestInfo.getTargetedPortletRequestInfo();
    final IPortalUrlBuilder actionRedirectUrl;
    if (portletRequestInfo != null) {
        final IPortletWindowId targetWindowId = portletRequestInfo.getPortletWindowId();
        actionRedirectUrl = this.portalUrlProvider.getPortalUrlBuilderByPortletWindow(request, targetWindowId, UrlType.RENDER);
    } else {
        final String targetedLayoutNodeId = portalRequestInfo.getTargetedLayoutNodeId();
        if (targetedLayoutNodeId != null) {
            actionRedirectUrl = this.portalUrlProvider.getPortalUrlBuilderByLayoutNode(request, targetedLayoutNodeId, UrlType.RENDER);
        } else {
            actionRedirectUrl = this.portalUrlProvider.getDefaultUrl(request);
        }
    }
    // Stuff the action-redirect URL builder into the request so other code can use it during
    // request processing
    this.portalUrlProvider.convertToPortalActionUrlBuilder(request, actionRedirectUrl);
    if (portletRequestInfo != null) {
        final IPortletWindowId targetWindowId = portletRequestInfo.getPortletWindowId();
        try {
            this.portletExecutionManager.doPortletAction(targetWindowId, request, response);
        } catch (RuntimeException e) {
            this.logger.error("Exception thrown while executing portlet action for: " + portletRequestInfo, e);
            // TODO this should be a constant right?
            actionRedirectUrl.setParameter("portletActionError", targetWindowId.toString());
        }
    }
    sendRedirect(actionRedirectUrl, response);
}
Also used : IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) IPortletRequestInfo(org.apereo.portal.url.IPortletRequestInfo) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with IPortalRequestInfo

use of org.apereo.portal.url.IPortalRequestInfo in project uPortal by Jasig.

the class PortletWindowRegistryImpl method getPortletWindow.

@Override
public Tuple<IPortletWindow, StartElement> getPortletWindow(HttpServletRequest request, StartElement element) {
    // Check if the layout node explicitly specifies the window id
    final Attribute windowIdAttribute = element.getAttributeByName(PORTLET_WINDOW_ID_ATTR_NAME);
    if (windowIdAttribute != null) {
        final String windowIdStr = windowIdAttribute.getValue();
        final IPortletWindowId portletWindowId = this.getPortletWindowId(request, windowIdStr);
        final IPortletWindow portletWindow = this.getPortletWindow(request, portletWindowId);
        return new Tuple<>(portletWindow, element);
    }
    // No explicit window id, look it up based on the layout node id
    final Attribute nodeIdAttribute = element.getAttributeByName(IUserLayoutManager.ID_ATTR_NAME);
    final String layoutNodeId = nodeIdAttribute.getValue();
    IPortletWindow portletWindow = this.getOrCreateDefaultPortletWindowByLayoutNodeId(request, layoutNodeId);
    if (portletWindow == null) {
        // No window for the layout node, return null
        return null;
    }
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    if (portalRequestInfo.getUrlState() == UrlState.DETACHED) {
        /*
             * We want to handle DETACHED portlet windows differently/explicitly,
             * but we need to be aware there may be other portlets on the page
             * besides the targeted one.  These would be portlets in regions
             * (Respondr theme) -- such as DynamicRespondrSkin.
             *
             * We need to confirm, therefore, that this is actually the portlet
             * in DETACHED.  If it is, we'll send back a 'stateless' PortletWindow.
             */
        if (portalRequestInfo.getTargetedPortletWindowId().toString().contains("_" + layoutNodeId + "_")) {
            final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
            portletWindow = this.getOrCreateStatelessPortletWindow(request, portletWindowId);
        }
    }
    element = this.addPortletWindowId(element, portletWindow.getPortletWindowId());
    return new Tuple<>(portletWindow, element);
}
Also used : IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) Attribute(javax.xml.stream.events.Attribute) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) Tuple(org.apereo.portal.utils.Tuple)

Example 24 with IPortalRequestInfo

use of org.apereo.portal.url.IPortalRequestInfo in project uPortal by Jasig.

the class UserLayoutParameterProcessor method processParameters.

@Override
@SuppressWarnings("FallThrough")
public boolean processParameters(HttpServletRequest request, HttpServletResponse response) {
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
    final String tabId = portalRequestInfo.getTargetedLayoutNodeId();
    if (tabId != null) {
        this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "focusedTabID", tabId);
    }
    // on a portlet, it will get overwritten with the new value below.
    if (userLayoutManager instanceof TransientUserLayoutManagerWrapper) {
        final TransientUserLayoutManagerWrapper transientUserLayoutManagerWrapper = (TransientUserLayoutManagerWrapper) userLayoutManager;
        transientUserLayoutManagerWrapper.setFocusedId(null);
    }
    final UrlState urlState = portalRequestInfo.getUrlState();
    switch(urlState) {
        case DETACHED:
            this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "detached", Boolean.TRUE.toString());
        case MAX:
            {
                final IPortletRequestInfo portletRequestInfo = portalRequestInfo.getTargetedPortletRequestInfo();
                if (portletRequestInfo != null) {
                    final IPortletWindowId targetWindowId = portletRequestInfo.getPortletWindowId();
                    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, targetWindowId);
                    final IPortletEntity portletEntity = portletWindow.getPortletEntity();
                    final String channelSubscribeId = portletEntity.getLayoutNodeId();
                    this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "userLayoutRoot", channelSubscribeId);
                    if (userLayoutManager instanceof TransientUserLayoutManagerWrapper) {
                        // get wrapper implementation for focusing
                        final TransientUserLayoutManagerWrapper transientUserLayoutManagerWrapper = (TransientUserLayoutManagerWrapper) userLayoutManager;
                        // .. and now set it as the focused id
                        transientUserLayoutManagerWrapper.setFocusedId(channelSubscribeId);
                    }
                    // If portletRequestInfo was null just fall through to NORMAL state
                    break;
                }
            }
        case NORMAL:
        default:
            {
                this.stylesheetUserPreferencesService.setStylesheetParameter(request, PreferencesScope.STRUCTURE, "userLayoutRoot", IUserLayout.ROOT_NODE_NAME);
                break;
            }
    }
    return true;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) TransientUserLayoutManagerWrapper(org.apereo.portal.layout.TransientUserLayoutManagerWrapper) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) IPortletRequestInfo(org.apereo.portal.url.IPortletRequestInfo) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) UrlState(org.apereo.portal.url.UrlState)

Example 25 with IPortalRequestInfo

use of org.apereo.portal.url.IPortalRequestInfo in project uPortal by Jasig.

the class DynamicRenderingPipeline method renderState.

@Override
public void renderState(HttpServletRequest req, HttpServletResponse res) throws 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);
}
Also used : CharacterEventReader(org.apereo.portal.character.stream.CharacterEventReader) CharacterEvent(org.apereo.portal.character.stream.events.CharacterEvent) IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) CharacterDataEvent(org.apereo.portal.character.stream.events.CharacterDataEvent) PrintWriter(java.io.PrintWriter)

Aggregations

IPortalRequestInfo (org.apereo.portal.url.IPortalRequestInfo)25 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)12 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)8 IPortletRequestInfo (org.apereo.portal.url.IPortletRequestInfo)6 UrlState (org.apereo.portal.url.UrlState)6 Locale (java.util.Locale)3 PortletRequestContextImpl (org.apereo.portal.portlet.container.PortletRequestContextImpl)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 PrintWriter (java.io.PrintWriter)2 WindowState (javax.portlet.WindowState)2 CharacterEventReader (org.apereo.portal.character.stream.CharacterEventReader)2 CharacterDataEvent (org.apereo.portal.character.stream.events.CharacterDataEvent)2 CharacterEvent (org.apereo.portal.character.stream.events.CharacterEvent)2 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)2 PortletRenderResult (org.apereo.portal.portlet.rendering.PortletRenderResult)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1