Search in sources :

Example 21 with IPortletWindow

use of org.apereo.portal.portlet.om.IPortletWindow in project uPortal by Jasig.

the class PortletRequestParameterProcessor method processParameters.

/* (non-Javadoc)
     * @see org.apereo.portal.url.processing.IRequestParameterProcessor#processParameters(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
public boolean processParameters(HttpServletRequest request, HttpServletResponse response) {
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    final IPortletWindowId targetedPortletWindowId = portalRequestInfo.getTargetedPortletWindowId();
    for (final IPortletRequestInfo portletRequestInfo : portalRequestInfo.getPortletRequestInfoMap().values()) {
        final IPortletWindowId portletWindowId = portletRequestInfo.getPortletWindowId();
        final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, targetedPortletWindowId);
        final UrlType urlType = portalRequestInfo.getUrlType();
        switch(urlType) {
            case RENDER:
                {
                    final Map<String, List<String>> portletParameters = portletRequestInfo.getPortletParameters();
                    portletWindow.setRenderParameters(ParameterMap.convertListMap(portletParameters));
                // fall through, render uses state/mode info
                }
            case ACTION:
                {
                    final WindowState windowState = portletRequestInfo.getWindowState();
                    if (windowState != null) {
                        portletWindow.setWindowState(windowState);
                    }
                    final PortletMode portletMode = portletRequestInfo.getPortletMode();
                    if (portletMode != null) {
                        portletWindow.setPortletMode(portletMode);
                    }
                    break;
                }
            default:
        }
        // Override the window state of the targeted portlet window based on the url state
        if (portletWindowId.equals(targetedPortletWindowId)) {
            final UrlState urlState = portalRequestInfo.getUrlState();
            switch(urlState) {
                case MAX:
                    {
                        portletWindow.setWindowState(WindowState.MAXIMIZED);
                        break;
                    }
                case DETACHED:
                    {
                        portletWindow.setWindowState(IPortletRenderer.DETACHED);
                        break;
                    }
                case EXCLUSIVE:
                    {
                        portletWindow.setWindowState(IPortletRenderer.EXCLUSIVE);
                        break;
                    }
                default:
            }
        }
        this.portletWindowRegistry.storePortletWindow(request, portletWindow);
    }
    return true;
}
Also used : WindowState(javax.portlet.WindowState) IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) IPortletRequestInfo(org.apereo.portal.url.IPortletRequestInfo) UrlType(org.apereo.portal.url.UrlType) ParameterMap(org.apereo.portal.url.ParameterMap) Map(java.util.Map) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) PortletMode(javax.portlet.PortletMode) UrlState(org.apereo.portal.url.UrlState)

Example 22 with IPortletWindow

use of org.apereo.portal.portlet.om.IPortletWindow in project uPortal by Jasig.

the class PortletUtils method getStringFromPortletUrl.

/**
 * A static EL function that is defined in portletUrl.tld Takes a portletUrl object and coverts
 * it into an actual Url Example is in search, returns a marketplace entry Url
 *
 * @param portletUrl
 * @param request
 * @return the Url represented by portletUrl
 */
public static String getStringFromPortletUrl(PortletUrl portletUrl, HttpServletRequest request) {
    if (portletUrl == null) {
        return null;
    }
    // Default urlType
    UrlType urlType = UrlType.RENDER;
    final PortletUrlType type = portletUrl.getType();
    switch(type) {
        case ACTION:
            urlType = UrlType.ACTION;
            break;
        case RESOURCE:
            urlType = UrlType.RESOURCE;
            break;
        default:
            urlType = UrlType.RENDER;
            break;
    }
    IPortletWindow marketplaceWindow = portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, MarketplacePortletDefinition.MARKETPLACE_FNAME);
    IPortalUrlBuilder portalUrlBuilder = portalUrlProvider.getPortalUrlBuilderByPortletWindow(request, marketplaceWindow.getPortletWindowId(), urlType);
    IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getTargetedPortletUrlBuilder();
    final String portletMode = portletUrl.getPortletMode();
    if (portletMode != null) {
        portletUrlBuilder.setPortletMode(PortletUtils.getPortletMode(portletMode));
    }
    final String windowState = portletUrl.getWindowState();
    if (windowState != null) {
        portletUrlBuilder.setWindowState(PortletUtils.getWindowState(windowState));
    }
    for (final PortletUrlParameter param : portletUrl.getParam()) {
        final String name = param.getName();
        final List<String> values = param.getValue();
        portletUrlBuilder.addParameter(name, values.toArray(new String[values.size()]));
    }
    return portalUrlBuilder.getUrlString();
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) PortletUrlParameter(org.apereo.portal.search.PortletUrlParameter) PortletUrlType(org.apereo.portal.search.PortletUrlType) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) PortletUrlType(org.apereo.portal.search.PortletUrlType) UrlType(org.apereo.portal.url.UrlType) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Example 23 with IPortletWindow

use of org.apereo.portal.portlet.om.IPortletWindow in project uPortal by Jasig.

the class PortletCacheControlServiceImpl method getPortletResourceState.

@Override
public CacheState<CachedPortletResourceData<Long>, Long> getPortletResourceState(HttpServletRequest request, IPortletWindowId portletWindowId) {
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, portletWindowId);
    if (portletWindow == null) {
        logger.warn("portletWindowRegistry returned null for {}, returning default cacheControl and no cached portlet data", portletWindowId);
        return new CacheState<CachedPortletResourceData<Long>, Long>();
    }
    // Generate the public resource cache key
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    final Locale locale = RequestContextUtils.getLocale(request);
    final PublicPortletCacheKey publicCacheKey = PublicPortletCacheKey.createPublicPortletResourceCacheKey(portletWindow, portalRequestInfo, locale);
    return this.<CachedPortletResourceData<Long>, Long>getPortletState(request, portletWindow, publicCacheKey, this.publicScopePortletResourceOutputCache, this.privateScopePortletResourceOutputCache, true);
}
Also used : Locale(java.util.Locale) IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Example 24 with IPortletWindow

use of org.apereo.portal.portlet.om.IPortletWindow in project uPortal by Jasig.

the class PortletCacheControlServiceImpl method getPortletRenderHeaderState.

@Override
public CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult> getPortletRenderHeaderState(HttpServletRequest request, IPortletWindowId portletWindowId) {
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, portletWindowId);
    if (portletWindow == null) {
        logger.warn("portletWindowRegistry returned null for {}, returning default cacheControl and no cached portlet data", portletWindowId);
        return new CacheState<CachedPortletData<PortletRenderResult>, PortletRenderResult>();
    }
    // Generate the public render-header cache key
    final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
    final Locale locale = RequestContextUtils.getLocale(request);
    final PublicPortletCacheKey publicCacheKey = PublicPortletCacheKey.createPublicPortletRenderHeaderCacheKey(portletWindow, portalRequestInfo, locale);
    return this.<CachedPortletData<PortletRenderResult>, PortletRenderResult>getPortletState(request, portletWindow, publicCacheKey, this.publicScopePortletRenderHeaderOutputCache, this.privateScopePortletRenderHeaderOutputCache, false);
}
Also used : Locale(java.util.Locale) IPortalRequestInfo(org.apereo.portal.url.IPortalRequestInfo) PortletRenderResult(org.apereo.portal.portlet.rendering.PortletRenderResult) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow)

Example 25 with IPortletWindow

use of org.apereo.portal.portlet.om.IPortletWindow in project uPortal by Jasig.

the class PortletCacheControlServiceImpl method cachePortletOutput.

private <D extends CachedPortletResultHolder<T>, T extends Serializable> void cachePortletOutput(IPortletWindowId portletWindowId, HttpServletRequest httpRequest, CacheState<D, T> cacheState, D cachedPortletData, Ehcache publicOutputCache, Ehcache privateOutputCache) {
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(httpRequest, portletWindowId);
    final CacheControl cacheControl = cacheState.getCacheControl();
    if (cacheControl.isPublicScope()) {
        final PublicPortletCacheKey publicCacheKey = cacheState.getPublicPortletCacheKey();
        this.cacheElement(publicOutputCache, publicCacheKey, cachedPortletData, cacheControl);
        logger.debug("Cached public data under key {} for {}", publicCacheKey, portletWindow);
    } else {
        PrivatePortletCacheKey privateCacheKey = cacheState.getPrivatePortletCacheKey();
        // portlet's response is now privately scoped
        if (privateCacheKey == null) {
            final HttpSession session = httpRequest.getSession();
            final String sessionId = session.getId();
            final IPortletEntityId entityId = portletWindow.getPortletEntityId();
            final PublicPortletCacheKey publicCacheKey = cacheState.getPublicPortletCacheKey();
            privateCacheKey = new PrivatePortletCacheKey(sessionId, portletWindowId, entityId, publicCacheKey);
        }
        this.cacheElement(privateOutputCache, privateCacheKey, cachedPortletData, cacheControl);
        logger.debug("Cached private data under key {} for {}", privateCacheKey, portletWindow);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) CacheControl(javax.portlet.CacheControl) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletEntityId(org.apereo.portal.portlet.om.IPortletEntityId)

Aggregations

IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)88 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)32 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)32 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)23 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 IPortalRequestInfo (org.apereo.portal.url.IPortalRequestInfo)12 IUserInstance (org.apereo.portal.user.IUserInstance)12 List (java.util.List)10 IPortletEntityId (org.apereo.portal.portlet.om.IPortletEntityId)10 IPortletUrlBuilder (org.apereo.portal.url.IPortletUrlBuilder)9 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 IOException (java.io.IOException)8 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)7 WindowState (javax.portlet.WindowState)6 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)6 IPortalUrlBuilder (org.apereo.portal.url.IPortalUrlBuilder)6 LinkedHashMap (java.util.LinkedHashMap)5 Locale (java.util.Locale)5 PortletException (javax.portlet.PortletException)5 PortletMode (javax.portlet.PortletMode)5