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);
}
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);
}
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();
}
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());
}
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();
}
Aggregations