Search in sources :

Example 6 with IPortletUrlBuilder

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

the class PortletDelegationDispatcherImpl method doAction.

@Override
public DelegationActionResponse doAction(ActionRequest actionRequest, ActionResponse actionResponse, DelegationRequest delegationRequest) throws IOException {
    final HttpServletRequest request = this.portalRequestUtils.getPortletHttpRequest(actionRequest);
    final HttpServletResponse response = this.portalRequestUtils.getOriginalPortalResponse(actionRequest);
    // Sanity check that the dispatch is being called by the same user it was created for
    final IPerson person = this.personManager.getPerson(request);
    if (this.userId != person.getID()) {
        throw new IllegalStateException("This dispatcher was created for userId " + this.userId + " but is being executed for userId " + person.getID());
    }
    this.setupDelegateRequestInfo(request, delegationRequest);
    final IPortletWindowId portletWindowId = this.portletWindow.getPortletWindowId();
    try {
        // TODO canRender permission checks!
        this.portletRenderer.doAction(portletWindowId, request, response);
    } catch (RuntimeException e) {
        this.logger.error("Failed to execute action on delegate", e);
        throw e;
    }
    // Get the portal URL builders for this request and check if a redirect was sent
    final IPortalActionUrlBuilder portalActionUrlBuilder = this.portalUrlProvider.getPortalActionUrlBuilder(request);
    final String redirectLocation = portalActionUrlBuilder.getRedirectLocation();
    if (redirectLocation != null) {
        final String renderUrlParamName = portalActionUrlBuilder.getRenderUrlParamName();
        // clear out the redirect from the delegate, leave it up to the parent if the redirect
        // should happen
        portalActionUrlBuilder.setRedirectLocation(null, null);
        return new DelegationActionResponse(this.getDelegateState(), redirectLocation, renderUrlParamName);
    }
    // No redirect so get the portlet's url builder and copy the state-changing data into the
    // delegate response
    final IPortletUrlBuilder portletUrlBuilder = portalActionUrlBuilder.getPortletUrlBuilder(portletWindowId);
    final WindowState windowState = portletUrlBuilder.getWindowState();
    final PortletMode portletMode = portletUrlBuilder.getPortletMode();
    final Map<String, String[]> parameters = portletUrlBuilder.getParameters();
    return new DelegationActionResponse(this.getDelegateState(), portletMode, windowState, parameters);
}
Also used : WindowState(javax.portlet.WindowState) IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) HttpServletResponse(javax.servlet.http.HttpServletResponse) IPortalActionUrlBuilder(org.apereo.portal.url.IPortalActionUrlBuilder) DelegationActionResponse(org.apereo.portal.api.portlet.DelegationActionResponse) PortletMode(javax.portlet.PortletMode) HttpServletRequest(javax.servlet.http.HttpServletRequest) IPerson(org.apereo.portal.security.IPerson) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 7 with IPortletUrlBuilder

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

the class RenderingPipelineIntegrationTest method testRenderingPipeline.

@Test
public void testRenderingPipeline() throws Exception {
    final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
    final Document doc = builder.newDocument();
    final DocumentFragment headFragment = doc.createDocumentFragment();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final IPortalUrlBuilder portalUrlBuilder = mock(IPortalUrlBuilder.class);
    final IPortletUrlBuilder portletUrlBuilder = mock(IPortletUrlBuilder.class);
    when(portalUrlBuilder.getUrlString()).thenReturn("URL_PLACEHOLDER");
    when(portletUrlBuilder.getPortalUrlBuilder()).thenReturn(portalUrlBuilder);
    when(portalUrlBuilder.getTargetedPortletUrlBuilder()).thenReturn(portletUrlBuilder);
    when(portalUrlBuilder.getPortletUrlBuilder(any(IPortletWindowId.class))).thenReturn(portletUrlBuilder);
    when(this.resourcesElementsProvider.getResourcesXmlFragment(any(HttpServletRequest.class), eq("/media/skins/respondr/defaultSkin/skin.xml"))).thenReturn(headFragment.getChildNodes());
    when(this.portalUrlProvider.getDefaultUrl(any(HttpServletRequest.class))).thenReturn(portalUrlBuilder);
    when(this.portalUrlProvider.getPortalUrlBuilderByLayoutNode(any(HttpServletRequest.class), any(String.class), any(UrlType.class))).thenReturn(portalUrlBuilder);
    when(this.portalUrlProvider.getPortalUrlBuilderByPortletFName(any(HttpServletRequest.class), any(String.class), any(UrlType.class))).thenReturn(portalUrlBuilder);
    final IPortletWindow portletWindow = mock(IPortletWindow.class);
    when(portletWindowRegistry.getPortletWindow(any(HttpServletRequest.class), any(StartElement.class))).thenReturn(new Tuple<IPortletWindow, StartElement>(portletWindow, null));
    when(portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(any(HttpServletRequest.class), any(String.class))).thenReturn(portletWindow);
    when(portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(any(HttpServletRequest.class), anyString())).thenReturn(portletWindow);
    when(portletWindow.getPortletWindowId()).thenReturn(new MockPortletWindowId("1"));
    final PipelineEventReader<?, ?> eventReader = this.component.getEventReader(request, response);
    for (final Object event : eventReader) {
        logger.debug(toString(event));
    }
    final String mediaType = eventReader.getOutputProperty(OutputKeys.MEDIA_TYPE);
    assertEquals("text/html", mediaType);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Document(org.w3c.dom.Document) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) StartElement(javax.xml.stream.events.StartElement) DocumentBuilder(javax.xml.parsers.DocumentBuilder) UrlType(org.apereo.portal.url.UrlType) DocumentFragment(org.w3c.dom.DocumentFragment) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) Test(org.junit.Test)

Example 8 with IPortletUrlBuilder

use of org.apereo.portal.url.IPortletUrlBuilder 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 9 with IPortletUrlBuilder

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

the class XsltPortalUrlProviderTest method testMultiPortletUrlById.

@Test
public void testMultiPortletUrlById() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final IPortletWindowId portletWindowId = new MockPortletWindowId("w1");
    final IPortletWindow portletWindow2 = mock(IPortletWindow.class);
    final IPortletWindowId portletWindowId2 = new MockPortletWindowId("w2");
    final IPortletUrlBuilder portletUrlBuilder2 = mock(IPortletUrlBuilder.class);
    when(portalUrlProvider.getPortalUrlBuilderByLayoutNode(request, "foo", UrlType.RENDER)).thenReturn(portalUrlBuilder);
    when(portalUrlBuilder.getPortletUrlBuilder(portletWindowId)).thenReturn(portletUrlBuilder);
    when(portalUrlBuilder.getUrlString()).thenReturn("/uPortal/home/normal/render.uP?layoutUrl");
    when(portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(request, "foo")).thenReturn(portletWindow);
    when(portletWindow.getPortletWindowId()).thenReturn(portletWindowId);
    when(portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, "my-portlet")).thenReturn(portletWindow2);
    when(portletWindow2.getPortletWindowId()).thenReturn(portletWindowId2);
    when(portalUrlBuilder.getPortletUrlBuilder(portletWindowId2)).thenReturn(portletUrlBuilder2);
    final Transformer transformer = xslTemplate.newTransformer();
    transformer.setParameter(XsltPortalUrlProvider.XSLT_PORTAL_URL_PROVIDER, xsltPortalUrlProvider);
    transformer.setParameter("CURRENT_REQUEST", request);
    // xsl template mode to use
    transformer.setParameter("TEST", "multiPortletUrlById");
    // set up configuration in the transformer impl
    final StringWriter resultWriter = new StringWriter();
    transformer.transform(xmlSource, new StreamResult(resultWriter));
    verify(portalUrlBuilder).addParameter("pageNum", "42");
    verify(portalUrlBuilder).getPortletUrlBuilder(portletWindowId);
    verify(portalUrlBuilder).getPortletUrlBuilder(portletWindowId2);
    verify(portalUrlBuilder).getUrlString();
    verifyNoMoreInteractions(portalUrlBuilder);
    verify(portletUrlBuilder).addParameter("tmp", "blah");
    verify(portletUrlBuilder).setCopyCurrentRenderParameters(false);
    verifyNoMoreInteractions(portletUrlBuilder);
    verify(portletUrlBuilder2).setWindowState(new WindowState("minimized"));
    verify(portletUrlBuilder2).addParameter("event", "param");
    verify(portletUrlBuilder2).setCopyCurrentRenderParameters(false);
    verifyNoMoreInteractions(portletUrlBuilder2);
    final String result = resultWriter.getBuffer().toString();
    logger.debug(result);
    XMLUnit.setIgnoreWhitespace(true);
    Diff d = new Diff(expected, result);
    assertTrue("Transformation result differs from what's expected" + d, d.similar());
}
Also used : WindowState(javax.portlet.WindowState) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) IPortletUrlBuilder(org.apereo.portal.url.IPortletUrlBuilder) Diff(org.custommonkey.xmlunit.Diff) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockPortletWindowId(org.apereo.portal.mock.portlet.om.MockPortletWindowId) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) IPortletWindow(org.apereo.portal.portlet.om.IPortletWindow) Test(org.junit.Test)

Example 10 with IPortletUrlBuilder

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

the class SearchPortletController method getResultUrl.

/**
 * Determine the url for the search result
 */
protected String getResultUrl(HttpServletRequest httpServletRequest, SearchResult result, IPortletWindowId portletWindowId) {
    final String externalUrl = result.getExternalUrl();
    if (externalUrl != null) {
        return externalUrl;
    }
    UrlType urlType = UrlType.RENDER;
    final PortletUrl portletUrl = result.getPortletUrl();
    if (portletUrl != null) {
        final PortletUrlType type = portletUrl.getType();
        if (type != null) {
            switch(type) {
                case ACTION:
                    {
                        urlType = UrlType.ACTION;
                        break;
                    }
                default:
                case RENDER:
                    {
                        urlType = UrlType.RENDER;
                        break;
                    }
                case RESOURCE:
                    {
                        urlType = UrlType.RESOURCE;
                        break;
                    }
            }
        }
    }
    final IPortalUrlBuilder portalUrlBuilder = this.portalUrlProvider.getPortalUrlBuilderByPortletWindow(httpServletRequest, portletWindowId, urlType);
    final IPortletUrlBuilder portletUrlBuilder = portalUrlBuilder.getTargetedPortletUrlBuilder();
    if (portletUrl != null) {
        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) PortletUrl(org.apereo.portal.search.PortletUrl) PortletUrlType(org.apereo.portal.search.PortletUrlType) IPortalUrlBuilder(org.apereo.portal.url.IPortalUrlBuilder) UrlType(org.apereo.portal.url.UrlType) PortletUrlType(org.apereo.portal.search.PortletUrlType)

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