Search in sources :

Example 11 with IUserLayoutFolderDescription

use of org.apereo.portal.layout.node.IUserLayoutFolderDescription 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 12 with IUserLayoutFolderDescription

use of org.apereo.portal.layout.node.IUserLayoutFolderDescription 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 13 with IUserLayoutFolderDescription

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

the class DistributedLayoutManager method canAddNode.

protected boolean canAddNode(IUserLayoutNodeDescription node, IUserLayoutNodeDescription parent, String nextSiblingId) throws PortalException {
    // make sure sibling exists and is a child of nodeId
    if (nextSiblingId != null && !nextSiblingId.equals("")) {
        IUserLayoutNodeDescription sibling = getNode(nextSiblingId);
        if (sibling == null) {
            throw new PortalException("Unable to find a sibling node " + "with id=\"" + nextSiblingId + "\".  Occurred " + "in layout for " + owner.getAttribute(IPerson.USERNAME) + ".");
        }
        if (!parent.getId().equals(getParentId(nextSiblingId))) {
            throw new PortalException("Given sibling (\"" + nextSiblingId + "\") is not a child of a given parentId (\"" + parent.getId() + "\"). Occurred " + "in layout for " + owner.getAttribute(IPerson.USERNAME) + ".");
        }
    }
    if (parent == null || !(node.isMoveAllowed() || isFragmentOwner))
        return false;
    if (parent instanceof IUserLayoutFolderDescription && !(((IUserLayoutFolderDescription) parent).isAddChildAllowed()) && !isFragmentOwner)
        return false;
    if (// end of list targeted
    nextSiblingId == null || nextSiblingId.equals(""))
        return true;
    // so lets see if we can place it at the end of the sibling list and
    // hop left until we get into the correct position.
    Enumeration sibIds = getVisibleChildIds(parent.getId());
    List sibs = Collections.list(sibIds);
    if (// last node in list so should be ok
    sibs.size() == 0)
        return true;
    // unprocessed nodes is not altered.
    for (int idx = sibs.size() - 1; idx >= 0; idx--) {
        IUserLayoutNodeDescription prev = getNode((String) sibs.get(idx));
        if (!isFragmentOwner && !MovementRules.canHopLeft(node, prev))
            return false;
        if (prev.getId().equals(nextSiblingId))
            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) PortalException(org.apereo.portal.PortalException) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription)

Aggregations

IUserLayoutFolderDescription (org.apereo.portal.layout.node.IUserLayoutFolderDescription)13 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)11 PortalException (org.apereo.portal.PortalException)7 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)4 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)4 UserLayoutFolderDescription (org.apereo.portal.layout.node.UserLayoutFolderDescription)4 IUserInstance (org.apereo.portal.user.IUserInstance)4 Element (org.w3c.dom.Element)4 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 XPathExpressionException (javax.xml.xpath.XPathExpressionException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 ArrayList (java.util.ArrayList)2 Enumeration (java.util.Enumeration)2 LinkedList (java.util.LinkedList)2 Vector (java.util.Vector)2 IPerson (org.apereo.portal.security.IPerson)2 Node (org.w3c.dom.Node)2 HashMap (java.util.HashMap)1