Search in sources :

Example 1 with IPortletUrlBuilder

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

the class LayoutRESTController method setAltMaxURL.

private void setAltMaxURL(HttpServletRequest request, NamedNodeMap attributes, IPortletDefinition def, LayoutPortlet portlet) {
    final String alternativeMaximizedLink = def.getAlternativeMaximizedLink();
    if (alternativeMaximizedLink != null) {
        portlet.setUrl(alternativeMaximizedLink);
        portlet.setAltMaxUrl(true);
    } else {
        // get the maximized URL for this portlet
        final IPortalUrlBuilder portalUrlBuilder = urlProvider.getPortalUrlBuilderByLayoutNode(request, attributes.getNamedItem("ID").getNodeValue(), UrlType.RENDER);
        final IPortletWindowId targetPortletWindowId = portalUrlBuilder.getTargetPortletWindowId();
        if (targetPortletWindowId != null) {
            final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(targetPortletWindowId);
            portletUrlBuilder.setWindowState(WindowState.MAXIMIZED);
        }
        portlet.setUrl(portalUrlBuilder.getUrlString());
        portlet.setAltMaxUrl(false);
    }
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 2 with IPortletUrlBuilder

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

the class PortletAdministrationHelper method getFragmentAdminURL.

/**
 * Get the link to the fragment admin portlet.
 *
 * @param request the current http request.
 * @return the portlet link
 */
public String getFragmentAdminURL(HttpServletRequest request) {
    IPortalUrlBuilder builder = urlProvider.getPortalUrlBuilderByPortletFName(request, PORTLET_FNAME_FRAGMENT_ADMIN_PORTLET, UrlType.RENDER);
    IPortletUrlBuilder portletUrlBuilder = builder.getTargetedPortletUrlBuilder();
    portletUrlBuilder.setPortletMode(PortletMode.VIEW);
    portletUrlBuilder.setWindowState(WindowState.MAXIMIZED);
    return builder.getUrlString();
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder)

Example 3 with IPortletUrlBuilder

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

the class FailSafePortalUrlBuilder method getPortletUrlBuilder.

/* (non-Javadoc)
     * @see org.apereo.portal.url.IPortalUrlBuilder#getPortletUrlBuilder(org.apereo.portal.portlet.om.IPortletWindowId)
     */
@Override
public IPortletUrlBuilder getPortletUrlBuilder(IPortletWindowId portletWindowId) {
    IPortletUrlBuilder portletUrlBuilder;
    synchronized (this.portletUrlBuilders) {
        portletUrlBuilder = this.portletUrlBuilders.get(portletWindowId);
        if (portletUrlBuilder == null) {
            portletUrlBuilder = new FailSafePortletUrlBuilder(portletWindowId, this);
            this.portletUrlBuilders.put(portletWindowId, portletUrlBuilder);
        }
    }
    return portletUrlBuilder;
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder)

Example 4 with IPortletUrlBuilder

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

the class XsltPortalUrlProvider method getPortletUrlBuilder.

/**
 * Get the portlet URL builder for the specified fname or layoutId (fname takes precedence)
 *
 * @param request
 * @param portalUrlBuilder
 * @param fname - can be empty string
 * @param layoutId - can by empty string
 * @param state - can be empty string
 * @param mode - can be empty string
 * @param copyCurrentRenderParameters
 * @param resourceId - can be empty string
 * @return IPortletUrlBuilder
 * @since 4.1
 */
public IPortletUrlBuilder getPortletUrlBuilder(HttpServletRequest request, IPortalUrlBuilder portalUrlBuilder, String fname, String layoutId, String state, String mode, String copyCurrentRenderParameters, String resourceId) {
    final IPortletUrlBuilder portletUrlBuilder;
    if (StringUtils.isNotEmpty(fname)) {
        final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, fname);
        final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
        portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(portletWindowId);
    } else if (StringUtils.isNotEmpty(layoutId)) {
        final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(request, layoutId);
        final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
        portletUrlBuilder = portalUrlBuilder.getPortletUrlBuilder(portletWindowId);
    } else {
        final IPortletWindowId targetPortletWindowId = portalUrlBuilder.getTargetPortletWindowId();
        if (targetPortletWindowId == null) {
            if (this.logger.isDebugEnabled()) {
                this.logger.warn("Can only target the default portlet if the root portal-url targets a portlet.", new Throwable());
            } else {
                this.logger.warn("Can only target the default portlet if the root portal-url targets a portlet. Enable debug for stack trace.");
            }
            return new FailSafePortletUrlBuilder(null, portalUrlBuilder);
        }
        portletUrlBuilder = portalUrlBuilder.getTargetedPortletUrlBuilder();
    }
    portletUrlBuilder.setCopyCurrentRenderParameters(Boolean.parseBoolean(copyCurrentRenderParameters));
    if (StringUtils.isNotEmpty(state)) {
        portletUrlBuilder.setWindowState(PortletUtils.getWindowState(state));
    }
    if (StringUtils.isNotEmpty(mode)) {
        portletUrlBuilder.setPortletMode(PortletUtils.getPortletMode(mode));
    }
    if (StringUtils.isNotEmpty(resourceId) && portletUrlBuilder.getPortalUrlBuilder().getUrlType() == UrlType.RESOURCE) {
        portletUrlBuilder.setResourceId(resourceId);
    }
    return portletUrlBuilder;
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 5 with IPortletUrlBuilder

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

the class PortletRedirectionController method getUrlString.

protected String getUrlString(IRedirectionUrl url, HttpServletRequest request, List<String> extraPath) {
    if (url instanceof ExternalRedirectionUrl) {
        ExternalRedirectionUrl externalUrl = (ExternalRedirectionUrl) url;
        StringBuffer urlStr = new StringBuffer();
        urlStr.append(externalUrl.getUrl());
        try {
            // add any additional parameters
            String separator = "?";
            for (Map.Entry<String, String[]> param : externalUrl.getAdditionalParameters().entrySet()) {
                for (String value : param.getValue()) {
                    urlStr.append(separator);
                    urlStr.append(param.getKey());
                    urlStr.append("=");
                    urlStr.append(URLEncoder.encode(value, "UTF-8"));
                    separator = "&";
                }
            }
            // add any dynamic parameters
            for (Map.Entry<String, String> param : externalUrl.getDynamicParameters().entrySet()) {
                String[] values = request.getParameterValues(param.getKey());
                if (values != null) {
                    for (String value : values) {
                        urlStr.append(separator);
                        urlStr.append(param.getValue());
                        urlStr.append("=");
                        urlStr.append(URLEncoder.encode(value, "UTF-8"));
                        separator = "&";
                    }
                }
            }
            if (!extraPath.isEmpty()) {
                List<String> paramNames = externalUrl.getPathParameters();
                ListIterator<String> itt = paramNames.listIterator();
                while (itt.hasNext() && !extraPath.isEmpty()) {
                    String param = itt.next();
                    String value;
                    if (itt.hasNext()) {
                        value = extraPath.remove(0);
                    } else {
                        value = StringUtils.join(extraPath, "/");
                    }
                    urlStr.append(separator);
                    urlStr.append(param);
                    urlStr.append("=");
                    urlStr.append(URLEncoder.encode(value, "UTF-8"));
                    separator = "&";
                }
            }
            return urlStr.toString();
        } catch (UnsupportedEncodingException ex) {
            log.error("Unable to encode URL parameter for external service redirect", ex);
            return null;
        }
    } else {
        PortletRedirectionUrl portletUrl = (PortletRedirectionUrl) url;
        // create the base URL for the portlet
        final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, portletUrl.getFname());
        final IPortalUrlBuilder portalUrlBuilder = this.portalUrlProvider.getPortalUrlBuilderByPortletWindow(request, portletWindow.getPortletWindowId(), portletUrl.getType());
        final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getTargetedPortletUrlBuilder();
        portletUrlBuilder.setPortletMode(portletUrl.getMode());
        portletUrlBuilder.setWindowState(WindowState.MAXIMIZED);
        // parameter to the portlet URL
        for (Map.Entry<String, String[]> param : portletUrl.getAdditionalParameters().entrySet()) {
            portletUrlBuilder.addParameter(param.getKey(), param.getValue());
        }
        // the value submitted to this service was non-null
        for (Map.Entry<String, String> param : portletUrl.getDynamicParameters().entrySet()) {
            String[] values = request.getParameterValues(param.getKey());
            if (values != null) {
                portletUrlBuilder.addParameter(param.getValue(), values);
            }
        }
        if (!extraPath.isEmpty()) {
            List<String> paramNames = portletUrl.getPathParameters();
            ListIterator<String> itt = paramNames.listIterator();
            while (itt.hasNext() && !extraPath.isEmpty()) {
                String param = itt.next();
                String value;
                if (itt.hasNext()) {
                    value = extraPath.remove(0);
                } else {
                    value = StringUtils.join(extraPath, "/");
                }
                if (StringUtils.isEmpty(value)) {
                    break;
                } else
                    portletUrlBuilder.addParameter(param, value);
            }
        }
        return portalUrlBuilder.getUrlString();
    }
}
Also used : IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) Map(java.util.Map)

Aggregations

IPortletUrlBuilder (org.apereo.portal.url.IPortletUrlBuilder)17 IPortalUrlBuilder (org.apereo.portal.url.IPortalUrlBuilder)11 IPortletWindow (org.apereo.portal.portlet.om.IPortletWindow)9 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 UrlType (org.apereo.portal.url.UrlType)4 PortletUrlParameter (org.apereo.portal.search.PortletUrlParameter)3 IPortalActionUrlBuilder (org.apereo.portal.url.IPortalActionUrlBuilder)3 WindowState (javax.portlet.WindowState)2 MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)2 PortletUrl (org.apereo.portal.search.PortletUrl)2 PortletUrlType (org.apereo.portal.search.PortletUrlType)2 Test (org.junit.Test)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Locale (java.util.Locale)1 Map (java.util.Map)1