Search in sources :

Example 6 with IPortletWindowId

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

the class SearchPortletController method handleSearchResult.

/**
 * Handles all the SearchResults events coming back from portlets
 */
@EventMapping(SearchConstants.SEARCH_RESULTS_QNAME_STRING)
public void handleSearchResult(EventRequest request) {
    // UP-3887 Design flaw.  Both the searchLauncher portlet instance and the search portlet
    // instance receive
    // searchRequest and searchResult events because they are in the same portlet code base (to
    // share
    // autosuggest_handler.jsp and because we have to calculate the search portlet url for the
    // ajax call)
    // and share the portlet.xml which defines the event handling behavior.
    // If this instance is the searchLauncher, ignore the searchResult. The search was submitted
    // to the search
    // portlet instance.
    final String searchLaunchFname = request.getPreferences().getValue(SEARCH_LAUNCH_FNAME, null);
    if (searchLaunchFname != null) {
        // message");
        return;
    }
    final Event event = request.getEvent();
    final SearchResults portletSearchResults = (SearchResults) event.getValue();
    // get the existing portal search result from the session and append
    // the results for this event
    final String queryId = portletSearchResults.getQueryId();
    final PortalSearchResults results = this.getPortalSearchResults(request, queryId);
    if (results == null) {
        this.logger.warn("No PortalSearchResults found for queryId {}, ignoring search results from {}", queryId, getSearchResultsSource(portletSearchResults));
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("For queryId {}, adding {} search results from {}", queryId, portletSearchResults.getSearchResult().size(), getSearchResultsSource(portletSearchResults));
    }
    final String windowId = portletSearchResults.getWindowId();
    final HttpServletRequest httpServletRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    final IPortletWindowId portletWindowId = this.portletWindowRegistry.getPortletWindowId(httpServletRequest, windowId);
    // Add the other portlet's results to the main search results object
    this.addSearchResults(portletSearchResults, results, httpServletRequest, portletWindowId);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Event(javax.portlet.Event) SearchResults(org.apereo.portal.search.SearchResults) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) EventMapping(org.springframework.web.portlet.bind.annotation.EventMapping)

Example 7 with IPortletWindowId

use of org.apereo.portal.portlet.om.IPortletWindowId 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 8 with IPortletWindowId

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

the class UrlSyntaxProviderImpl method generateUrl.

@Override
public String generateUrl(HttpServletRequest request, IPortalUrlBuilder portalUrlBuilder) {
    Validate.notNull(request, "HttpServletRequest was null");
    Validate.notNull(portalUrlBuilder, "IPortalPortletUrl was null");
    // Convert the callback request to the portal request
    request = this.portalRequestUtils.getOriginalPortalRequest(request);
    final IUrlNodeSyntaxHelper urlNodeSyntaxHelper = this.urlNodeSyntaxHelperRegistry.getCurrentUrlNodeSyntaxHelper(request);
    // Get the encoding and create a new URL string builder
    final String encoding = this.getEncoding(request);
    // Add the portal's context path
    final String contextPath = this.getCleanedContextPath(request);
    final UrlStringBuilder url = new UrlStringBuilder(encoding, contextPath.length() > 0 ? contextPath : null);
    final Map<IPortletWindowId, IPortletUrlBuilder> portletUrlBuilders = portalUrlBuilder.getPortletUrlBuilders();
    // Build folder path based on targeted portlet or targeted folder
    final IPortletWindowId targetedPortletWindowId = portalUrlBuilder.getTargetPortletWindowId();
    final UrlType urlType = portalUrlBuilder.getUrlType();
    final UrlState urlState;
    final String resourceId;
    if (targetedPortletWindowId != null) {
        final IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, targetedPortletWindowId);
        final IPortletEntity portletEntity = portletWindow.getPortletEntity();
        // Add folder information if available: /f/tabId
        final String channelSubscribeId = portletEntity.getLayoutNodeId();
        final List<String> folderNames = urlNodeSyntaxHelper.getFolderNamesForLayoutNode(request, channelSubscribeId);
        if (!folderNames.isEmpty()) {
            url.addPath(FOLDER_PATH_PREFIX);
            for (final String folderName : folderNames) {
                url.addPath(folderName);
            }
        }
        final IPortletUrlBuilder targetedPortletUrlBuilder = portletUrlBuilders.get(targetedPortletWindowId);
        // Determine the resourceId for resource requests
        if (urlType == UrlType.RESOURCE && targetedPortletUrlBuilder != null) {
            resourceId = targetedPortletUrlBuilder.getResourceId();
        } else {
            resourceId = null;
        }
        // Resource requests will never have a requested window state
        urlState = this.determineUrlState(portletWindow, targetedPortletUrlBuilder);
        final String targetedPortletString = urlNodeSyntaxHelper.getFolderNameForPortlet(request, targetedPortletWindowId);
        // path
        if ((urlType == UrlType.RENDER && urlState != UrlState.NORMAL) || urlType == UrlType.ACTION || urlType == UrlType.RESOURCE) {
            url.addPath(PORTLET_PATH_PREFIX);
            url.addPath(targetedPortletString);
        } else // For normal render requests (generally multiple portlets on a page) add the targeted
        // portlet as a parameter
        {
            url.addParameter(PARAM_TARGET_PORTLET, targetedPortletString);
        }
        /*
             * CSRF Prevention
             *
             * Add the Spring-managed CSRF token to requests that need them.  This list _should_
             * include Action URLs only, but several Resource URLs are currently being used with
             * POST requests in Apereo portlets.  We need to include Resource URLs as well, since
             * (just now) we don't have the time to correct all those usages.  We should work to
             * correct those cases, and remove handling of Resource URLs when we can.
             */
        if (UrlType.ACTION.equals(urlType) || UrlType.RESOURCE.equals(urlType)) {
            final CsrfToken token = (CsrfToken) request.getAttribute(CSRF_PARAMETER_NAME);
            if (token != null) {
                url.setParameter(token.getParameterName(), token.getToken());
            }
        }
    } else {
        final String targetFolderId = portalUrlBuilder.getTargetFolderId();
        final List<String> folderNames = urlNodeSyntaxHelper.getFolderNamesForLayoutNode(request, targetFolderId);
        if (folderNames != null && !folderNames.isEmpty()) {
            url.addPath(FOLDER_PATH_PREFIX);
            for (final String folderName : folderNames) {
                url.addPath(folderName);
            }
        }
        urlState = UrlState.NORMAL;
        resourceId = null;
    }
    // Add the state of the URL
    url.addPath(urlState.toLowercaseString());
    // File part specifying the type of URL, resource URLs include the resourceId
    if (urlType == UrlType.RESOURCE && resourceId != null) {
        url.addPath(resourceId + "." + urlType.toLowercaseString() + REQUEST_TYPE_SUFFIX);
    } else {
        url.addPath(urlType.toLowercaseString() + REQUEST_TYPE_SUFFIX);
    }
    // Add all portal parameters
    final Map<String, String[]> portalParameters = portalUrlBuilder.getParameters();
    url.addParametersArray(PORTAL_PARAM_PREFIX, portalParameters);
    // Is this URL stateless
    final boolean statelessUrl = statelessUrlStates.contains(urlState);
    // Add parameters for every portlet URL
    for (final IPortletUrlBuilder portletUrlBuilder : portletUrlBuilders.values()) {
        this.addPortletUrlData(request, url, urlType, portletUrlBuilder, targetedPortletWindowId, statelessUrl);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Generated '" + url + "' from '" + portalUrlBuilder);
    }
    return url.toString();
}
Also used : CsrfToken(org.springframework.security.web.csrf.CsrfToken) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletEntity(org.apereo.portal.portlet.om.IPortletEntity) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 9 with IPortletWindowId

use of org.apereo.portal.portlet.om.IPortletWindowId 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)

Example 10 with IPortletWindowId

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

the class PortletWindowAttributeSource method getCacheKey.

@Override
public final CacheKey getCacheKey(HttpServletRequest request, HttpServletResponse response) {
    final Set<IPortletWindow> portletWindows = this.portletWindowRegistry.getAllLayoutPortletWindows(request);
    final CacheKeyBuilder cacheKeyBuilder = CacheKey.builder(this.name);
    for (final IPortletWindow portletWindow : portletWindows) {
        if (portletWindow != null) {
            final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
            final WindowState windowState = portletWindow.getWindowState();
            final PortletMode portletMode = portletWindow.getPortletMode();
            cacheKeyBuilder.addAll(portletWindowId, windowState.toString(), portletMode.toString());
        } else {
            this.logger.warn("portletWindowRegistry#getAllLayoutPortletWindows() returned a null portletWindow");
        }
    }
    return cacheKeyBuilder.build();
}
Also used : WindowState(javax.portlet.WindowState) CacheKeyBuilder(org.apereo.portal.utils.cache.CacheKey.CacheKeyBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) PortletMode(javax.portlet.PortletMode)

Aggregations

IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)85 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)31 Test (org.junit.Test)19 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)19 MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)15 WindowState (javax.portlet.WindowState)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 IPortletEntity (org.apereo.portal.portlet.om.IPortletEntity)9 PortletMode (javax.portlet.PortletMode)8 IPortalRequestInfo (org.apereo.portal.url.IPortalRequestInfo)8 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)7 IPortletRenderExecutionWorker (org.apereo.portal.portlet.rendering.worker.IPortletRenderExecutionWorker)7 IPortletUrlBuilder (org.apereo.portal.url.IPortletUrlBuilder)7 LinkedHashMap (java.util.LinkedHashMap)6 IPerson (org.apereo.portal.security.IPerson)6 IPortalUrlBuilder (org.apereo.portal.url.IPortalUrlBuilder)6 IOException (java.io.IOException)5 List (java.util.List)5 IUserInstance (org.apereo.portal.user.IUserInstance)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5