Search in sources :

Example 6 with IUserLayoutFolderDescription

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

the class DistributedLayoutManager method updateNode.

/**
     * Handles pushing changes made to the passed-in node into the user's layout. If the node is an
     * ILF node then the change is recorded via directives in the PLF if such changes are allowed by
     * the owning fragment. If the node is a user owned node then the changes are applied directly
     * to the corresponding node in the PLF.
     */
public synchronized boolean updateNode(IUserLayoutNodeDescription node) throws PortalException {
    if (canUpdateNode(node)) {
        String nodeId = node.getId();
        IUserLayoutNodeDescription oldNode = getNode(nodeId);
        if (oldNode instanceof IUserLayoutChannelDescription) {
            IUserLayoutChannelDescription oldChanDesc = (IUserLayoutChannelDescription) oldNode;
            if (!(node instanceof IUserLayoutChannelDescription)) {
                throw new PortalException("Change channel to folder is " + "not allowed by updateNode() method! Occurred " + "in layout for " + owner.getAttribute(IPerson.USERNAME) + ".");
            }
            IUserLayoutChannelDescription newChanDesc = (IUserLayoutChannelDescription) node;
            updateChannelNode(nodeId, newChanDesc, oldChanDesc);
        } else {
            // must be a folder
            IUserLayoutFolderDescription oldFolderDesc = (IUserLayoutFolderDescription) oldNode;
            if (oldFolderDesc.getId().equals(getRootFolderId()))
                throw new PortalException("Update of root node is not currently allowed!");
            if (node instanceof IUserLayoutFolderDescription) {
                IUserLayoutFolderDescription newFolderDesc = (IUserLayoutFolderDescription) node;
                updateFolderNode(nodeId, newFolderDesc, oldFolderDesc);
            }
        }
        this.updateCacheKey();
        return true;
    }
    return false;
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) PortalException(org.apereo.portal.PortalException) IUserLayoutChannelDescription(org.apereo.portal.layout.node.IUserLayoutChannelDescription) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription)

Example 7 with IUserLayoutFolderDescription

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

the class DistributedLayoutManager method getChildIds.

private Enumeration<String> getChildIds(String nodeId, boolean visibleOnly) throws PortalException {
    Vector<String> v = new Vector<String>();
    IUserLayoutNodeDescription node = getNode(nodeId);
    if (node instanceof IUserLayoutFolderDescription) {
        Document uld = this.getUserLayoutDOM();
        Element felement = uld.getElementById(nodeId);
        for (Node n = felement.getFirstChild(); n != null; n = n.getNextSibling()) {
            if (n.getNodeType() == Node.ELEMENT_NODE && (visibleOnly == false || (visibleOnly == true && ((Element) n).getAttribute(Constants.ATT_HIDDEN).equals("false")))) {
                Element e = (Element) n;
                if (e.getAttribute("ID") != null) {
                    v.add(e.getAttribute("ID"));
                }
            }
        }
    }
    return v.elements();
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) Vector(java.util.Vector) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription)

Example 8 with IUserLayoutFolderDescription

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

the class SimpleLayout method getChildIds.

@Override
public Enumeration getChildIds(String nodeId) throws PortalException {
    Vector v = new Vector();
    IUserLayoutNodeDescription node = getNodeDescription(nodeId);
    if (node instanceof IUserLayoutFolderDescription) {
        Element element = layout.getElementById(nodeId);
        for (Node n = element.getFirstChild(); n != null; n = n.getNextSibling()) {
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                Element e = (Element) n;
                if (e.getAttribute("ID") != null) {
                    v.add(e.getAttribute("ID"));
                }
            }
        }
    }
    return v.elements();
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Vector(java.util.Vector) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription)

Example 9 with IUserLayoutFolderDescription

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

the class UpdatePreferencesServlet method changeColumns.

/**
     * Change the number of columns on a specified tab. In the event that the user is decreasing the
     * number of columns, extra columns will be stripped from the right-hand side. Any channels in
     * these columns will be moved to the bottom of the last preserved column.
     *
     * @param widths array of column widths
     * @param deleted array of deleted column IDs
     * @param acceptor not sure what this is
     * @param request HttpRequest
     * @param response HttpResponse
     * @throws IOException
     * @throws PortalException
     */
@RequestMapping(method = RequestMethod.POST, params = "action=changeColumns")
public ModelAndView changeColumns(HttpServletRequest request, HttpServletResponse response, @RequestParam("tabId") String tabId, @RequestParam("widths[]") String[] widths, @RequestParam(value = "deleted[]", required = false) String[] deleted, @RequestParam(value = "acceptor", required = false) String acceptor) throws IOException, PortalException {
    IUserInstance ui = userInstanceManager.getUserInstance(request);
    IPerson per = getPerson(ui, response);
    UserPreferencesManager upm = (UserPreferencesManager) ui.getPreferencesManager();
    IUserLayoutManager ulm = upm.getUserLayoutManager();
    int newColumnCount = widths.length;
    // build a list of the current columns for this tab
    Enumeration<String> columns = ulm.getChildIds(tabId);
    List<String> columnList = new ArrayList<String>();
    while (columns.hasMoreElements()) {
        columnList.add(columns.nextElement());
    }
    int oldColumnCount = columnList.size();
    Map<String, Object> model = new HashMap<String, Object>();
    // if the new layout has more columns
    if (newColumnCount > oldColumnCount) {
        List<String> newColumnIds = new ArrayList<String>();
        for (int i = columnList.size(); i < newColumnCount; i++) {
            // create new column element
            IUserLayoutFolderDescription newColumn = new UserLayoutFolderDescription();
            newColumn.setName("Column");
            newColumn.setId("tbd");
            newColumn.setFolderType(IUserLayoutFolderDescription.REGULAR_TYPE);
            newColumn.setHidden(false);
            newColumn.setUnremovable(false);
            newColumn.setImmutable(false);
            // add the column to our layout
            IUserLayoutNodeDescription node = ulm.addNode(newColumn, tabId, null);
            newColumnIds.add(node.getId());
            model.put("newColumnIds", newColumnIds);
            columnList.add(node.getId());
        }
    } else // if the new layout has fewer columns
    if (deleted != null && deleted.length > 0) {
        if (columnList.size() != widths.length + deleted.length) {
        // TODO: error?
        }
        for (String columnId : deleted) {
            // move all channels in the current column to the last valid column
            Enumeration channels = ulm.getChildIds(columnId);
            while (channels.hasMoreElements()) {
                ulm.addNode(ulm.getNode((String) channels.nextElement()), acceptor, null);
            }
            // delete the column from the user's layout
            ulm.deleteNode(columnId);
            columnList.remove(columnId);
        }
    }
    int count = 0;
    for (String columnId : columnList) {
        this.stylesheetUserPreferencesService.setLayoutAttribute(request, PreferencesScope.STRUCTURE, columnId, "width", widths[count] + "%");
        try {
            // This sets the column attribute in memory but doesn't persist it.  Comment says saves changes "prior to persisting"
            Element folder = ulm.getUserLayoutDOM().getElementById(columnId);
            UserPrefsHandler.setUserPreference(folder, "width", per);
        } catch (Exception e) {
            logger.error("Error saving new column widths", e);
        }
        count++;
    }
    try {
        ulm.saveUserLayout();
    } catch (PortalException e) {
        logger.warn("Error saving layout", e);
    }
    return new ModelAndView("jsonView", model);
}
Also used : IUserLayoutNodeDescription(org.apereo.portal.layout.node.IUserLayoutNodeDescription) Enumeration(java.util.Enumeration) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription) UserLayoutFolderDescription(org.apereo.portal.layout.node.UserLayoutFolderDescription) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) XPathExpressionException(javax.xml.xpath.XPathExpressionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PortalException(org.apereo.portal.PortalException) IOException(java.io.IOException) IUserInstance(org.apereo.portal.user.IUserInstance) IPerson(org.apereo.portal.security.IPerson) PortalException(org.apereo.portal.PortalException) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager) IUserLayoutFolderDescription(org.apereo.portal.layout.node.IUserLayoutFolderDescription) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with IUserLayoutFolderDescription

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

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