use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class SingleTabUrlNodeSyntaxHelper method getLayoutNodeForFolderNames.
@Override
public String getLayoutNodeForFolderNames(HttpServletRequest request, List<String> folderNames) {
if (folderNames == null || folderNames.isEmpty()) {
logger.warn("Asked to get layout node for an empty or null folderNames ({}).", folderNames);
return null;
}
// Check if the folder name is compound and parse it if it is
String folderName = folderNames.get(0);
String layoutNodeId = null;
final int seperatorIndex = folderName.indexOf(PORTLET_PATH_ELEMENT_SEPERATOR);
if (seperatorIndex > 0 && seperatorIndex < folderName.length() - 1) {
layoutNodeId = folderName.substring(seperatorIndex + 1);
folderName = folderName.substring(0, seperatorIndex);
}
if (folderNames.size() > 1) {
logger.warn("Asked to consider multiple folder names {}, " + "but ignoring all but the first which has been parsed as {}.", folderNames, folderName);
}
// Search the users layout attributes for a layout node with a matching externalId value
String firstMatchingNodeId = null;
final Map<String, String> allNodesAndValuesForAttribute = stylesheetUserPreferencesService.getAllNodesAndValuesForAttribute(request, PreferencesScope.STRUCTURE, EXTERNAL_ID_ATTR);
for (final Entry<String, String> entry : allNodesAndValuesForAttribute.entrySet()) {
final String value = entry.getValue();
// could have already been translated
if (value.equals(folderName) || FunctionalNameType.makeValid(value).equals(folderName)) {
final String nodeId = entry.getKey();
if (nodeId.equals(layoutNodeId)) {
// ExternalId matched as well as the layoutNodeId, clear the firstMatchingNodeId
// since we found the nodeId here
logger.trace("Parsed folder names {} to nodeId {}.", folderNames, nodeId);
return nodeId;
} else if (firstMatchingNodeId == null) {
firstMatchingNodeId = nodeId;
}
}
}
// use that match
if (firstMatchingNodeId != null) {
layoutNodeId = firstMatchingNodeId;
} else // In this case the folderName must not have been an externalId, assume it is a layout node
if (layoutNodeId == null) {
layoutNodeId = folderName;
}
// Verify the parsed layoutNodeId matches a node in the user's layout
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
final IUserLayoutNodeDescription node;
try {
node = userLayoutManager.getNode(layoutNodeId);
} catch (PortalException e) {
logger.warn("Parsed requested folder names {} to layoutNodeId {} " + "but did not match a node in the user layout.", folderNames, layoutNodeId, e);
return null;
}
if (node == null) {
logger.warn("Parsed requested folder names to layoutNodeId {} " + "but did not match a node in the user layout.", folderNames, layoutNodeId);
return null;
}
String nodeId = node.getId();
logger.trace("Resolved node id {} for folder names {}.", nodeId, folderNames);
return nodeId;
}
use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.
the class PortalUrlProviderImpl method getLayoutNodeType.
/**
* Verify the requested node exists in the user's layout. Also if the node exists see if it is a
* portlet node and if it is return the {@link IPortletWindowId} of the corresponding portlet.
*/
protected LayoutNodeType getLayoutNodeType(HttpServletRequest request, String folderNodeId) {
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
final IUserLayoutManager userLayoutManager = preferencesManager.getUserLayoutManager();
final IUserLayoutNodeDescription node = userLayoutManager.getNode(folderNodeId);
if (node == null) {
return null;
}
return node.getType();
}
Aggregations