use of org.apereo.portal.portlet.om.IPortletEntity 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.IPortletEntity 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.IPortletEntity in project uPortal by Jasig.
the class RequestRenderingPipelineUtilsImpl method getPortletDefinitionFromServletRequest.
@Override
public IPortletDefinition getPortletDefinitionFromServletRequest(HttpServletRequest request) {
final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
if (portalRequestInfo != null && portalRequestInfo.getTargetedPortletWindowId() != null) {
IPortletWindowId targetedPortletWindowId = portalRequestInfo.getTargetedPortletWindowId();
IPortletWindow portletWindow = this.portletWindowRegistry.getPortletWindow(request, targetedPortletWindowId);
if (portletWindow != null && portletWindow.getPortletEntity() != null) {
final IPortletEntity portletEntity = portletWindow.getPortletEntity();
IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
return portletDefinition;
}
}
return null;
}
use of org.apereo.portal.portlet.om.IPortletEntity in project uPortal by Jasig.
the class PortletWindowRegistryImpl method getOrCreateDefaultPortletWindowByLayoutNodeId.
@Override
public IPortletWindow getOrCreateDefaultPortletWindowByLayoutNodeId(HttpServletRequest request, String subscribeId) {
Validate.notNull(request, "HttpServletRequest cannot be null");
Validate.notNull(subscribeId, "subscribeId cannot be null");
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IPortletEntity portletEntity = this.portletEntityRegistry.getOrCreatePortletEntity(request, userInstance, subscribeId);
if (portletEntity == null) {
logger.debug("No portlet entity found for id {}, no IPortletWindow will be returned.", subscribeId);
return null;
}
logger.trace("Found portlet entity {} for id {}", portletEntity, subscribeId);
final IPortletWindow portletWindow = this.getOrCreateDefaultPortletWindow(request, portletEntity.getPortletEntityId());
logger.trace("Found portlet window {} for layout node {}", portletWindow, subscribeId);
return portletWindow;
}
use of org.apereo.portal.portlet.om.IPortletEntity in project uPortal by Jasig.
the class PortletWindowRegistryImpl method getOrCreateStatelessPortletWindow.
@Override
public IPortletWindow getOrCreateStatelessPortletWindow(HttpServletRequest request, IPortletWindowId basePortletWindowId) {
//Need the basePortletWindowId to be an instance of PortletWindowIdImpl so that we can extract the entity ID
if (!(basePortletWindowId instanceof PortletWindowIdImpl)) {
final String basePortletWindowIdStr = basePortletWindowId.getStringId();
basePortletWindowId = this.getPortletWindowId(request, basePortletWindowIdStr);
}
//Get the entity ID for the portlet window
final IPortletEntityId portletEntityId = ((PortletWindowIdImpl) basePortletWindowId).getPortletEntityId();
//Create the stateless ID
final PortletWindowIdImpl statelessPortletWindowId = this.createPortletWindowId(STATELESS_PORTLET_WINDOW_ID, portletEntityId);
//See if there is already a request cached stateless window
IPortletWindow statelessPortletWindow = this.getPortletWindow(request, statelessPortletWindowId);
if (statelessPortletWindow != null) {
return statelessPortletWindow;
}
//Lookup the base portlet window to clone the stateless from
final IPortletWindow basePortletWindow = this.getPortletWindow(request, basePortletWindowId);
final PortletWindowCache<PortletWindowData> statelessPortletWindowDataMap = this.getStatelessPortletWindowDataMap(request, true);
//If no base to clone from lookup the entity and pluto definition data
if (basePortletWindow == null) {
final IPortletEntity portletEntity = this.portletEntityRegistry.getPortletEntity(request, portletEntityId);
if (portletEntity == null) {
throw new IllegalArgumentException("No IPortletEntity could be found for " + portletEntity + " while creating stateless portlet window for " + basePortletWindowId);
}
final IPortletDefinition portletDefinition = portletEntity.getPortletDefinition();
final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
final PortletDefinition portletDescriptor = this.portletDefinitionRegistry.getParentPortletDescriptor(portletDefinitionId);
final PortletWindowData portletWindowData = new PortletWindowData(statelessPortletWindowId, portletEntityId);
statelessPortletWindowDataMap.storeWindow(portletWindowData);
statelessPortletWindow = new StatelessPortletWindowImpl(portletWindowData, portletEntity, portletDescriptor);
} else //Clone the existing base window
{
final PortletWindowData portletWindowData = new PortletWindowData(statelessPortletWindowId, portletEntityId);
portletWindowData.setExpirationCache(basePortletWindow.getExpirationCache());
portletWindowData.setPortletMode(basePortletWindow.getPortletMode());
portletWindowData.setWindowState(basePortletWindow.getWindowState());
portletWindowData.setPublicRenderParameters(basePortletWindow.getPublicRenderParameters());
portletWindowData.setRenderParameters(basePortletWindow.getRenderParameters());
statelessPortletWindowDataMap.storeWindow(portletWindowData);
final IPortletEntity portletEntity = basePortletWindow.getPortletEntity();
final PortletDefinition portletDescriptor = basePortletWindow.getPlutoPortletWindow().getPortletDefinition();
statelessPortletWindow = new StatelessPortletWindowImpl(portletWindowData, portletEntity, portletDescriptor);
}
//Cache the stateless window in the request
final PortletWindowCache<IPortletWindow> portletWindowMap = this.getPortletWindowMap(request);
portletWindowMap.storeWindow(statelessPortletWindow);
return statelessPortletWindow;
}
Aggregations