Search in sources :

Example 1 with PortletMode

use of javax.portlet.PortletMode in project liferay-ide by liferay.

the class LiferayPortlet method doDispatch.

@Override
protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
    if (!isProcessRenderRequest(renderRequest)) {
        renderRequest.setAttribute(WebKeys.PORTLET_DECORATE, Boolean.FALSE);
        return;
    }
    WindowState windowState = renderRequest.getWindowState();
    if (windowState.equals(WindowState.MINIMIZED)) {
        return;
    }
    PortletMode portletMode = renderRequest.getPortletMode();
    if (portletMode.equals(PortletMode.VIEW)) {
        doView(renderRequest, renderResponse);
    } else if (portletMode.equals(LiferayPortletMode.ABOUT)) {
        doAbout(renderRequest, renderResponse);
    } else if (portletMode.equals(LiferayPortletMode.CONFIG)) {
        doConfig(renderRequest, renderResponse);
    } else if (portletMode.equals(PortletMode.EDIT)) {
        doEdit(renderRequest, renderResponse);
    } else if (portletMode.equals(LiferayPortletMode.EDIT_DEFAULTS)) {
        doEditDefaults(renderRequest, renderResponse);
    } else if (portletMode.equals(LiferayPortletMode.EDIT_GUEST)) {
        doEditGuest(renderRequest, renderResponse);
    } else if (portletMode.equals(PortletMode.HELP)) {
        doHelp(renderRequest, renderResponse);
    } else if (portletMode.equals(LiferayPortletMode.PREVIEW)) {
        doPreview(renderRequest, renderResponse);
    } else if (portletMode.equals(LiferayPortletMode.PRINT)) {
        doPrint(renderRequest, renderResponse);
    } else {
        throw new PortletException(portletMode.toString());
    }
}
Also used : WindowState(javax.portlet.WindowState) PortletException(javax.portlet.PortletException) PortletMode(javax.portlet.PortletMode)

Example 2 with PortletMode

use of javax.portlet.PortletMode in project uPortal by Jasig.

the class PortalEventFactoryImpl method createPortletExecutionEventBuilder.

protected PortletExecutionEvent.PortletExecutionEventBuilder createPortletExecutionEventBuilder(PortalEvent.PortalEventBuilder portalEventBuilder, IPortletWindowId portletWindowId, long executionTimeNano, boolean renderRequest) {
    final HttpServletRequest portalRequest = portalEventBuilder.getPortalRequest();
    // Get the portlet's fname
    final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(portalRequest, portletWindowId);
    final IPortletEntity portletEntity = portletWindow.getPortletEntity();
    final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
    final String fname = portletDefinition.getFName();
    // Get the parameters used for the portlet execution
    final Map<String, List<String>> parameters = getParameters(portalRequest, portletWindowId, renderRequest);
    // Get the state & mode used for this request
    final WindowState windowState = portletWindow.getWindowState();
    final PortletMode portletMode = portletWindow.getPortletMode();
    return new PortletExecutionEvent.PortletExecutionEventBuilder(portalEventBuilder, portletWindowId, fname, executionTimeNano, parameters, windowState, portletMode);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WindowState(javax.portlet.WindowState) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) PortletMode(javax.portlet.PortletMode) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition)

Example 3 with PortletMode

use of javax.portlet.PortletMode 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 4 with PortletMode

use of javax.portlet.PortletMode in project uPortal by Jasig.

the class UrlSyntaxProviderImpl method parseLegacyPortalUrl.

protected IPortalRequestInfo parseLegacyPortalUrl(HttpServletRequest request, Map<String, String[]> parameterMap) {
    final PortalRequestInfoImpl portalRequestInfo = new PortalRequestInfoImpl();
    final String[] fname = parameterMap.remove(LEGACY_PARAM_PORTLET_FNAME);
    if (fname != null && fname.length > 0) {
        final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, fname[0]);
        if (portletWindow != null) {
            logger.debug("Legacy fname parameter {} resolved to {}", fname[0], portletWindow);
            final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
            portalRequestInfo.setTargetedPortletWindowId(portletWindowId);
            final PortletRequestInfoImpl portletRequestInfo = portalRequestInfo.getPortletRequestInfo(portletWindowId);
            // Check the portlet request type
            final String[] type = parameterMap.remove(LEGACY_PARAM_PORTLET_REQUEST_TYPE);
            if (type != null && type.length > 0 && "ACTION".equals(type[0])) {
                portalRequestInfo.setUrlType(UrlType.ACTION);
            }
            // Set the window state
            final String[] state = parameterMap.remove(LEGACY_PARAM_PORTLET_STATE);
            if (state != null && state.length > 0) {
                final WindowState windowState = PortletUtils.getWindowState(state[0]);
                // none of the other options make sense
                if (portalRequestInfo.getUrlType() == UrlType.ACTION || PATH_WINDOW_STATES.contains(windowState)) {
                    portletRequestInfo.setWindowState(windowState);
                }
            }
            // If no window state was set assume MAXIMIZED
            if (portletRequestInfo.getWindowState() == null) {
                portletRequestInfo.setWindowState(WindowState.MAXIMIZED);
            }
            // Set the portlet mode
            final String[] mode = parameterMap.remove(LEGACY_PARAM_PORTLET_MODE);
            if (mode != null && mode.length > 0) {
                final PortletMode portletMode = PortletUtils.getPortletMode(mode[0]);
                portletRequestInfo.setPortletMode(portletMode);
            }
            // Set the parameters
            final Map<String, List<String>> portletParameters = portletRequestInfo.getPortletParameters();
            for (final Map.Entry<String, String[]> parameterEntry : parameterMap.entrySet()) {
                final String prefixedName = parameterEntry.getKey();
                // If the parameter starts with the portlet param prefix
                if (prefixedName.startsWith(LEGACY_PARAM_PORTLET_PARAM_PREFX)) {
                    final String name = prefixedName.substring(LEGACY_PARAM_PORTLET_PARAM_PREFX.length());
                    portletParameters.put(name, Arrays.asList(parameterEntry.getValue()));
                }
            }
            // Set the url state based on the window state
            final UrlState urlState = this.determineUrlState(portletWindow, portletRequestInfo.getWindowState());
            portalRequestInfo.setUrlState(urlState);
        } else {
            logger.debug("Could not find portlet for legacy fname fname parameter {}", fname[0]);
        }
    }
    // Check root=uP_root
    final String[] root = parameterMap.remove(LEGACY_PARAM_LAYOUT_ROOT);
    if (root != null && root.length > 0) {
        if (LEGACY_PARAM_LAYOUT_ROOT_VALUE.equals(root[0])) {
            // Check uP_sparam=activeTab
            final String[] structParam = parameterMap.remove(LEGACY_PARAM_LAYOUT_STRUCT_PARAM);
            if (structParam != null && structParam.length > 0) {
                if (LEGACY_PARAM_LAYOUT_TAB_ID.equals(structParam[0])) {
                    // Get the active tab id
                    final String[] activeTabId = parameterMap.remove(LEGACY_PARAM_LAYOUT_TAB_ID);
                    if (activeTabId != null && activeTabId.length > 0) {
                        // Get the user's layout and do xpath for tab at index=activeTabId[0]
                        final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
                        final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
                        final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
                        final IUserLayout userLayout = userLayoutManager.getUserLayout();
                        final String nodeId = this.xpathOperations.doWithExpression("/layout/folder/folder[@type='regular' and @hidden='false'][position() = $activeTabId]/@ID", Collections.singletonMap("activeTabId", activeTabId[0]), new Function<XPathExpression, String>() {

                            @Override
                            public String apply(XPathExpression xPathExpression) {
                                return userLayout.findNodeId(xPathExpression);
                            }
                        });
                        // Found nodeId for activeTabId
                        if (nodeId != null) {
                            logger.debug("Found layout node {} for legacy activeTabId parameter {}", nodeId, activeTabId[0]);
                            portalRequestInfo.setTargetedLayoutNodeId(nodeId);
                        } else {
                            logger.debug("No layoout node found for legacy activeTabId parameter {}", activeTabId[0]);
                        }
                    }
                }
            }
        }
    }
    return portalRequestInfo;
}
Also used : WindowState(javax.portlet.WindowState) XPathExpression(javax.xml.xpath.XPathExpression) IUserLayout(org.apereo.portal.layout.IUserLayout) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) PortletMode(javax.portlet.PortletMode) IUserInstance(org.apereo.portal.user.IUserInstance) LinkedList(java.util.LinkedList) List(java.util.List) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 5 with PortletMode

use of javax.portlet.PortletMode in project uPortal by Jasig.

the class UrlSyntaxProviderImpl method addPortletUrlData.

/**
 * Add the provided portlet url builder data to the url string builder
 */
protected void addPortletUrlData(final HttpServletRequest request, final UrlStringBuilder url, final UrlType urlType, final IPortletUrlBuilder portletUrlBuilder, final IPortletWindowId targetedPortletWindowId, final boolean statelessUrl) {
    final IPortletWindowId portletWindowId = portletUrlBuilder.getPortletWindowId();
    final boolean targeted = portletWindowId.equals(targetedPortletWindowId);
    IPortletWindow portletWindow = null;
    // The targeted portlet doesn't need namespaced parameters
    final String prefixedPortletWindowId;
    final String suffixedPortletWindowId;
    // Track whether or not we are adding parameters to the URL for non-targeted or delegate
    // portlets.
    boolean addedNonTargetedPortletParam = false;
    if (targeted) {
        prefixedPortletWindowId = "";
        suffixedPortletWindowId = "";
    } else {
        final String portletWindowIdStr = portletWindowId.toString();
        prefixedPortletWindowId = SEPARATOR + portletWindowIdStr;
        suffixedPortletWindowId = portletWindowIdStr + SEPARATOR;
        // targeted portlets can never be delegates (it is always the top most parent that is
        // targeted)
        portletWindow = this.portletWindowRegistry.getPortletWindow(request, portletWindowId);
        final IPortletWindowId delegationParentId = portletWindow.getDelegationParentId();
        if (delegationParentId != null) {
            url.addParameter(PARAM_DELEGATE_PARENT + prefixedPortletWindowId, delegationParentId.getStringId());
            addedNonTargetedPortletParam = true;
        }
    }
    switch(urlType) {
        case RESOURCE:
            {
                final String cacheability = portletUrlBuilder.getCacheability();
                if (cacheability != null) {
                    url.addParameter(PARAM_CACHEABILITY + prefixedPortletWindowId, cacheability);
                    addedNonTargetedPortletParam = !targeted ? true : addedNonTargetedPortletParam;
                }
                final String resourceId = portletUrlBuilder.getResourceId();
                if (!targeted && resourceId != null) {
                    url.addParameter(PARAM_RESOURCE_ID + prefixedPortletWindowId, resourceId);
                    // We know we are !targeted, but kept the assignement consistent with the
                    // other similar
                    // assignments for clarity.
                    addedNonTargetedPortletParam = !targeted ? true : addedNonTargetedPortletParam;
                }
                break;
            }
        default:
            {
                // Add requested portlet mode
                final PortletMode portletMode = portletUrlBuilder.getPortletMode();
                if (portletMode != null) {
                    url.addParameter(PARAM_PORTLET_MODE + prefixedPortletWindowId, portletMode.toString());
                    addedNonTargetedPortletParam = !targeted ? true : addedNonTargetedPortletParam;
                } else if (targeted && statelessUrl) {
                    portletWindow = portletWindow != null ? portletWindow : this.portletWindowRegistry.getPortletWindow(request, portletWindowId);
                    final PortletMode currentPortletMode = portletWindow.getPortletMode();
                    url.addParameter(PARAM_PORTLET_MODE + prefixedPortletWindowId, currentPortletMode.toString());
                    // We know we are targeted, but kept the assignement consistent with the
                    // other similar
                    // assignments for clarity. Will always be a nop.
                    addedNonTargetedPortletParam = !targeted ? true : addedNonTargetedPortletParam;
                }
                // Add requested window state if it isn't included on the path
                final WindowState windowState = portletUrlBuilder.getWindowState();
                if (windowState != null && (!targeted || !PATH_WINDOW_STATES.contains(windowState))) {
                    url.addParameter(PARAM_WINDOW_STATE + prefixedPortletWindowId, windowState.toString());
                    addedNonTargetedPortletParam = !targeted ? true : addedNonTargetedPortletParam;
                }
                break;
            }
    }
    if (portletUrlBuilder.getCopyCurrentRenderParameters()) {
        url.addParameter(PARAM_COPY_PARAMETERS + suffixedPortletWindowId);
        addedNonTargetedPortletParam = !targeted ? true : addedNonTargetedPortletParam;
    }
    final Map<String, String[]> parameters = portletUrlBuilder.getParameters();
    if (!parameters.isEmpty()) {
        url.addParametersArray(PORTLET_PARAM_PREFIX + suffixedPortletWindowId, parameters);
        addedNonTargetedPortletParam = !targeted ? true : addedNonTargetedPortletParam;
    }
    // URL since there are no parameters actually being passed to the searched portlets.
    if (addedNonTargetedPortletParam) {
        url.addParameter(PARAM_ADDITIONAL_PORTLET, portletWindowId.toString());
    }
}
Also used : WindowState(javax.portlet.WindowState) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) PortletMode(javax.portlet.PortletMode)

Aggregations

PortletMode (javax.portlet.PortletMode)13 WindowState (javax.portlet.WindowState)12 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)8 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)6 List (java.util.List)3 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 DelegateState (org.apereo.portal.api.portlet.DelegateState)2 DelegationRequest (org.apereo.portal.api.portlet.DelegationRequest)2 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)2 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)2 IPerson (org.apereo.portal.security.IPerson)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 PortletException (javax.portlet.PortletException)1 PortletSession (javax.portlet.PortletSession)1