use of org.apereo.portal.portlet.om.IPortletWindow in project uPortal by Jasig.
the class SingleTabUrlNodeSyntaxHelper method getPortletForFolderName.
@Override
public IPortletWindowId getPortletForFolderName(HttpServletRequest request, String targetedLayoutNodeId, String folderName) {
//Basic parsing of the
final String fname;
String subscribeId = null;
final int seperatorIndex = folderName.indexOf(PORTLET_PATH_ELEMENT_SEPERATOR);
if (seperatorIndex <= 0 || seperatorIndex + 1 == folderName.length()) {
fname = folderName;
} else {
fname = folderName.substring(0, seperatorIndex);
subscribeId = folderName.substring(seperatorIndex + 1);
}
//If a subscribeId was provided validate that it matches up with the fname
if (subscribeId != null) {
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IPortletEntity portletEntity = this.portletEntityRegistry.getOrCreatePortletEntity(request, userInstance, subscribeId);
if (portletEntity == null || !fname.equals(portletEntity.getPortletDefinition().getFName())) {
//If no entity found or the fname doesn't match ignore the provided subscribeId by setting it to null
subscribeId = null;
} else {
//subscribeId matches fname, lookup the window for the entity and return the windowId
final IPortletEntityId portletEntityId = portletEntity.getPortletEntityId();
final IPortletWindow portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindow(request, portletEntityId);
if (portletWindow == null) {
return null;
}
return portletWindow.getPortletWindowId();
}
}
//If a layout node is targeted then look for a matching subscribeId under that targeted node
if (targetedLayoutNodeId != null) {
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
//First look for the layout node only under the specified folder
subscribeId = userLayoutManager.getSubscribeId(targetedLayoutNodeId, fname);
}
//Find a subscribeId based on the fname
final IPortletWindow portletWindow;
if (subscribeId == null) {
portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByFname(request, fname);
} else {
portletWindow = this.portletWindowRegistry.getOrCreateDefaultPortletWindowByLayoutNodeId(request, subscribeId);
}
if (portletWindow == null) {
return null;
}
return portletWindow.getPortletWindowId();
}
use of org.apereo.portal.portlet.om.IPortletWindow 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());
}
}
use of org.apereo.portal.portlet.om.IPortletWindow 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]);
//If this isn't an action request only allow PATH communicated WindowStates as 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;
}
use of org.apereo.portal.portlet.om.IPortletWindow 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);
//If a non-normal render url or an action/resource url stick the portlet info in the 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);
}
} 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();
}
use of org.apereo.portal.portlet.om.IPortletWindow in project uPortal by Jasig.
the class HttpRequestPropertiesManagerTest method testGetRequestProperties.
public void testGetRequestProperties() {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("1.2.3.4");
request.setMethod("POST");
final IPortletWindow portletWindow = EasyMock.createMock(IPortletWindow.class);
final IPortalRequestUtils portalRequestUtils = EasyMock.createMock(IPortalRequestUtils.class);
EasyMock.expect(portalRequestUtils.getOriginalPortalRequest(request)).andReturn(request);
EasyMock.replay(portletWindow, portalRequestUtils);
this.httpRequestPropertiesManager.setPortalRequestUtils(portalRequestUtils);
final MultivaluedMapPopulator<String, String> populator = new MultivaluedMapPopulator<String, String>();
this.httpRequestPropertiesManager.populateRequestProperties(request, portletWindow, populator);
final Map<String, List<String>> properties = populator.getMap();
assertNotNull("properties Map should not be null", properties);
final Map<String, List<String>> expected = ImmutableMap.of("REMOTE_ADDR", Collections.singletonList("1.2.3.4"), "REQUEST_METHOD", Collections.singletonList("POST"), "REMOTE_HOST", Collections.singletonList("localhost"));
assertEquals(expected, properties);
EasyMock.verify(portletWindow, portalRequestUtils);
}
Aggregations