Search in sources :

Example 16 with PortalException

use of org.apereo.portal.PortalException in project uPortal by Jasig.

the class DistributedLayoutManager method getAllSubscribedChannels.

@Override
public Set<String> getAllSubscribedChannels() {
    final Document uld = this.getUserLayoutDOM();
    if (uld == null) {
        throw new PortalException("UserLayout has not been initialized for " + owner.getAttribute(IPerson.USERNAME));
    }
    final NodeList channelElements = uld.getElementsByTagName(CHANNEL);
    final Set<String> allSubscribedChannels = new LinkedHashSet<String>(channelElements.getLength());
    for (int nodeIndex = 0; nodeIndex < channelElements.getLength(); nodeIndex++) {
        final Element channelElement = (Element) channelElements.item(nodeIndex);
        final String subscribeId = channelElement.getAttribute("ID");
        allSubscribedChannels.add(subscribeId);
    }
    return allSubscribedChannels;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) PortalException(org.apereo.portal.PortalException) Document(org.w3c.dom.Document)

Example 17 with PortalException

use of org.apereo.portal.PortalException in project uPortal by Jasig.

the class DistributedLayoutManager method getParentId.

public String getParentId(String nodeId) throws PortalException {
    Document uld = this.getUserLayoutDOM();
    Element nelement = uld.getElementById(nodeId);
    if (nelement != null) {
        Node parent = nelement.getParentNode();
        if (parent != null) {
            if (parent.getNodeType() != Node.ELEMENT_NODE) {
                throw new PortalException("Node with id=\"" + nodeId + "\" is attached to something other then an element node.");
            }
            Element e = (Element) parent;
            return e.getAttribute("ID");
        }
        return null;
    }
    throw new PortalException("Node with id=\"" + nodeId + "\" doesn't exist. Occurred in layout for " + owner.getAttribute(IPerson.USERNAME) + ".");
}
Also used : Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) PortalException(org.apereo.portal.PortalException) Document(org.w3c.dom.Document)

Example 18 with PortalException

use of org.apereo.portal.PortalException in project uPortal by Jasig.

the class DistributedLayoutManager method getRootFolderId.

/* Returns the ID attribute of the root folder of the layout. This folder
     * is defined to be the single child of the top most "layout" Element.
     *
     * @see org.apereo.portal.layout.IUserLayoutManager#getRootFolderId()
     * @see org.apereo.portal.layout.dlm.RootLocator
     */
public String getRootFolderId() {
    if (rootNodeId == null) {
        Document layout = getUserLayoutDOM();
        Element rootNode = this.xpathOperations.evaluate("//layout/folder", layout, XPathConstants.NODE);
        if (rootNode == null || !rootNode.getAttribute(Constants.ATT_TYPE).equals(Constants.ROOT_FOLDER_ID)) {
            LOG.error("Unable to locate root node in layout of " + owner.getAttribute(IPerson.USERNAME) + ". Resetting corrupted layout.");
            resetLayout((String) null);
            rootNode = this.xpathOperations.evaluate("//layout/folder", layout, XPathConstants.NODE);
            if (rootNode == null || !rootNode.getAttribute(Constants.ATT_TYPE).equals(Constants.ROOT_FOLDER_ID)) {
                throw new PortalException("Corrupted layout detected for " + owner.getAttribute(IPerson.USERNAME) + " and resetting layout failed.");
            }
        }
        rootNodeId = rootNode.getAttribute("ID");
    }
    return rootNodeId;
}
Also used : Element(org.w3c.dom.Element) PortalException(org.apereo.portal.PortalException) Document(org.w3c.dom.Document)

Example 19 with PortalException

use of org.apereo.portal.PortalException in project uPortal by Jasig.

the class HandlerUtils method createILFCopy.

/** Creates a copy of an ilf node in the plf and sets up necessary storage attributes. */
private static Element createILFCopy(Element compViewNode, Element compViewParent, boolean includeChildNodes, Document plf, Element plfParent, IPerson person) throws PortalException {
    Element plfNode = (Element) plf.importNode(compViewNode, includeChildNodes);
    // make sure that we don't include ILF restriction params in the PLF if
    // this ILF node contained any.
    plfNode.removeAttributeNS(Constants.NS_URI, Constants.LCL_ADD_CHILD_ALLOWED);
    plfNode.removeAttributeNS(Constants.NS_URI, Constants.LCL_DELETE_ALLOWED);
    plfNode.removeAttributeNS(Constants.NS_URI, Constants.LCL_EDIT_ALLOWED);
    plfNode.removeAttributeNS(Constants.NS_URI, Constants.LCL_MOVE_ALLOWED);
    String ID = plfNode.getAttribute(Constants.ATT_ID);
    plfNode.setIdAttribute(Constants.ATT_ID, true);
    IUserLayoutStore uls = null;
    uls = UserLayoutStoreLocator.getUserLayoutStore();
    if (plfNode.getAttribute(Constants.ATT_PLF_ID).equals("")) {
        String plfID = null;
        try {
            if (!plfNode.getAttribute(Constants.ATT_CHANNEL_ID).equals(// dealing with a channel
            ""))
                plfID = uls.generateNewChannelSubscribeId(person);
            else
                plfID = uls.generateNewFolderId(person);
        } catch (Exception e) {
            throw new PortalException("Exception encountered while " + "generating new user layout node " + "Id for userId=" + person.getID(), e);
        }
        plfNode.setAttributeNS(Constants.NS_URI, Constants.ATT_PLF_ID, plfID);
        plfNode.setAttributeNS(Constants.NS_URI, Constants.ATT_ORIGIN, ID);
    }
    plfParent.appendChild(plfNode);
    PositionManager.updatePositionSet(compViewParent, plfParent, person);
    return plfNode;
}
Also used : Element(org.w3c.dom.Element) IUserLayoutStore(org.apereo.portal.layout.IUserLayoutStore) PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException)

Example 20 with PortalException

use of org.apereo.portal.PortalException in project uPortal by Jasig.

the class EditManager method getEditSet.

/**
     * Get the edit set if any stored in the passed in node. If not found and if the create flag is
     * true then create a new edit set and add it as a child to the passed in node. Then return it.
     */
private static Element getEditSet(Element node, Document plf, IPerson person, boolean create) throws PortalException {
    Node child = node.getFirstChild();
    while (child != null) {
        if (child.getNodeName().equals(Constants.ELM_EDIT_SET))
            return (Element) child;
        child = child.getNextSibling();
    }
    if (create == false)
        return null;
    String ID = null;
    try {
        ID = getDLS().getNextStructDirectiveId(person);
    } catch (Exception e) {
        throw new PortalException("Exception encountered while " + "generating new edit set node " + "Id for userId=" + person.getID(), e);
    }
    Element editSet = plf.createElement(Constants.ELM_EDIT_SET);
    editSet.setAttribute(Constants.ATT_TYPE, Constants.ELM_EDIT_SET);
    editSet.setAttribute(Constants.ATT_ID, ID);
    node.appendChild(editSet);
    return editSet;
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) PortalException(org.apereo.portal.PortalException) PortalException(org.apereo.portal.PortalException)

Aggregations

PortalException (org.apereo.portal.PortalException)47 Element (org.w3c.dom.Element)19 IUserLayoutManager (org.apereo.portal.layout.IUserLayoutManager)16 IUserInstance (org.apereo.portal.user.IUserInstance)14 Document (org.w3c.dom.Document)14 UserPreferencesManager (org.apereo.portal.UserPreferencesManager)13 IUserLayoutNodeDescription (org.apereo.portal.layout.node.IUserLayoutNodeDescription)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ModelAndView (org.springframework.web.servlet.ModelAndView)13 IPerson (org.apereo.portal.security.IPerson)9 Node (org.w3c.dom.Node)9 Locale (java.util.Locale)7 IUserLayoutFolderDescription (org.apereo.portal.layout.node.IUserLayoutFolderDescription)7 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)7 HashMap (java.util.HashMap)6 IUserLayoutChannelDescription (org.apereo.portal.layout.node.IUserLayoutChannelDescription)6 UserLayoutFolderDescription (org.apereo.portal.layout.node.UserLayoutFolderDescription)6 XPathExpressionException (javax.xml.xpath.XPathExpressionException)5 IOException (java.io.IOException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4