Search in sources :

Example 21 with IUserLayoutNodeDescription

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();
        //Have to test against the fname safe version of the externalId since the folderName 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;
            }
        }
    }
    //If an explicit nodeId match isn't found but at least one matching externalId was found 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;
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager)

Example 22 with IUserLayoutNodeDescription

use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.

the class UpdatePreferencesServlet method getTabIdFromName.

protected String getTabIdFromName(IUserLayout userLayout, String tabName) {
    @SuppressWarnings("unchecked") Enumeration<String> childrenOfRoot = userLayout.getChildIds(userLayout.getRootId());
    while (childrenOfRoot.hasMoreElements()) {
        //loop over folders that might be the favorites folder
        String nodeId = childrenOfRoot.nextElement();
        try {
            IUserLayoutNodeDescription nodeDescription = userLayout.getNodeDescription(nodeId);
            IUserLayoutNodeDescription.LayoutNodeType nodeType = nodeDescription.getType();
            if (IUserLayoutNodeDescription.LayoutNodeType.FOLDER.equals(nodeType) && nodeDescription instanceof IUserLayoutFolderDescription) {
                IUserLayoutFolderDescription folderDescription = (IUserLayoutFolderDescription) nodeDescription;
                if (tabName.equalsIgnoreCase(folderDescription.getName())) {
                    return folderDescription.getId();
                }
            }
        } catch (Exception e) {
            logger.error("Error getting the nodeID of the tab name " + tabName, e);
        }
    }
    logger.warn("Tab " + tabName + " was searched for but not found");
    //didn't find tab
    return null;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription) XPathExpressionException(javax.xml.xpath.XPathExpressionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PortalException(org.apereo.portal.PortalException) IOException(java.io.IOException)

Example 23 with IUserLayoutNodeDescription

use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.

the class FavoritesUtils method getFavoriteTabNodeId.

public static String getFavoriteTabNodeId(IUserLayout userLayout) {
    @SuppressWarnings("unchecked") Enumeration<String> childrenOfRoot = userLayout.getChildIds(userLayout.getRootId());
    while (childrenOfRoot.hasMoreElements()) {
        //loop over folders that might be the favorites folder
        String nodeId = childrenOfRoot.nextElement();
        try {
            IUserLayoutNodeDescription nodeDescription = userLayout.getNodeDescription(nodeId);
            IUserLayoutNodeDescription.LayoutNodeType nodeType = nodeDescription.getType();
            if (FOLDER.equals(nodeType) && nodeDescription instanceof IUserLayoutFolderDescription) {
                IUserLayoutFolderDescription folderDescription = (IUserLayoutFolderDescription) nodeDescription;
                if (FAVORITES_TYPE.equalsIgnoreCase(folderDescription.getFolderType())) {
                    return folderDescription.getId();
                }
            }
        } catch (Exception e) {
            logger.error("Ignoring on error a node while examining for favorites: node ID is [{}]", nodeId, e);
        }
    }
    logger.warn("Favorite tab was searched for but not found");
    //didn't find favorite tab
    return null;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription)

Example 24 with IUserLayoutNodeDescription

use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.

the class FavoritesUtils method getFavoriteCollections.

/**
     * Get the favorite collections of portlets (i.e. suitable folders ("tabs") in the user layout.)
     * Suitable layout nodes are of type folder with @type attribute favorite_collection.
     *
     * @param userLayout
     * @return non-null List of IUserLayoutDescriptions describing the tabs
     */
public static List<IUserLayoutNodeDescription> getFavoriteCollections(IUserLayout userLayout) {
    if (null == userLayout) {
        throw new IllegalArgumentException("Cannot get favorites collections from a null userLayout");
    }
    logger.trace("Extracting favorites collections from layout [{}].", userLayout);
    Enumeration<String> nodeIds = userLayout.getChildIds(userLayout.getRootId());
    List<IUserLayoutNodeDescription> results = new LinkedList<IUserLayoutNodeDescription>();
    while (nodeIds.hasMoreElements()) {
        String nodeId = nodeIds.nextElement();
        try {
            IUserLayoutNodeDescription nodeDescription = userLayout.getNodeDescription(nodeId);
            String parentId = userLayout.getParentId(nodeId);
            String nodeName = nodeDescription.getName();
            IUserLayoutNodeDescription.LayoutNodeType nodeType = nodeDescription.getType();
            if (FOLDER.equals(nodeType) && nodeDescription instanceof IUserLayoutFolderDescription) {
                IUserLayoutFolderDescription folderDescription = (IUserLayoutFolderDescription) nodeDescription;
                String folderType = folderDescription.getFolderType();
                if (FAVORITE_COLLECTION_TYPE.equals(folderType)) {
                    results.add(nodeDescription);
                    logger.trace("Selected node with id [{}] named [{}] with " + "folderType [{}] and type [{}] as a collection of favorites.", nodeId, nodeName, folderType, nodeType);
                } else {
                    logger.trace("Rejected node with id [{}] named [{}] with " + "folderType [{}] and type [{}] as not a collection of favorites.", nodeId, nodeName, folderType, nodeType);
                }
            } else {
                logger.trace("Rejected non-folder node with id [{}] named [{}] " + "with parentId [{}] and type [{}] as not a collection of favorites.", nodeId, nodeName, parentId, nodeType);
            }
        // if something goes wrong in processing a node, exclude it
        } catch (Exception e) {
            logger.error("Error determining whether to include layout node [{}]" + " as a collection of favorites.  Excluding.", nodeId, e);
        }
    }
    logger.debug("Extracted favorites collections [{}] from [{}]", results, userLayout);
    return results;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) LinkedList(java.util.LinkedList) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription)

Example 25 with IUserLayoutNodeDescription

use of org.apereo.portal.layout.node.IUserLayoutNodeDescription in project uPortal by Jasig.

the class DistributedLayoutManager method canMoveLeft.

private boolean canMoveLeft(String nodeId, String targetNextSibId) throws PortalException {
    IUserLayoutNodeDescription node = getNode(nodeId);
    Enumeration sibIds = getVisibleChildIds(getParentId(nodeId));
    List sibs = Collections.list(sibIds);
    for (int idx = sibs.indexOf(nodeId) - 1; idx >= 0; idx--) {
        String prevSibId = (String) sibs.get(idx);
        IUserLayoutNodeDescription prev = getNode(prevSibId);
        if (!isFragmentOwner && !MovementRules.canHopLeft(node, prev))
            return false;
        if (targetNextSibId != null && prev.getId().equals(targetNextSibId))
            return true;
    }
    // oops never found the sib
    return false;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Enumeration(java.util.Enumeration) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList)

Aggregations

IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)30 PortalException (org.apereo.portal.PortalException)14 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)14 IUserInstance (org.apereo.portal.user.IUserInstance)12 IUserLayoutFolderDescription (org.apereo.portal.layout.node.IUserLayoutFolderDescription)11 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)8 IUserLayoutChannelDescription (org.apereo.portal.layout.node.IUserLayoutChannelDescription)8 Element (org.w3c.dom.Element)7 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ModelAndView (org.springframework.web.servlet.ModelAndView)6 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)5 Document (org.w3c.dom.Document)5 Node (org.w3c.dom.Node)5 ArrayList (java.util.ArrayList)4 Enumeration (java.util.Enumeration)4 HashMap (java.util.HashMap)4 Locale (java.util.Locale)4 UserLayoutChannelDescription (org.apereo.portal.layout.node.UserLayoutChannelDescription)4 List (java.util.List)3