001: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.layout.dlm;
007:
008: import org.apache.commons.logging.Log;
009: import org.apache.commons.logging.LogFactory;
010: import org.jasig.portal.PortalException;
011: import org.jasig.portal.security.IPerson;
012: import org.w3c.dom.Document;
013: import org.w3c.dom.Element;
014:
015: /**
016: * Applies user prefs changes to the user's plf prior to persisting.
017: *
018: * @version $Revision: 36335 $ $Date: 2005-12-09 10:47:42 -0700 (Fri, 09 Dec 2005) $
019: * @since uPortal 2.5
020: */
021: public class TabColumnPrefsHandler {
022: public static final String RCS_ID = "@(#) $Header$";
023: private static Log LOG = LogFactory
024: .getLog(TabColumnPrefsHandler.class);
025:
026: /**
027: This method is called from the TabColumnPrefsState class after a node
028: has already been moved from its old parent to its new in the ILF. We can
029: get at the new parent via the compViewNode moved but need a separate
030: handle of the parent from whence it came. The goal of this method is to
031: make the appropriate change in the PLF to persist this action take by
032: the user. For ILF nodes this generally means adding an entry to the
033: position set for the new parent and removing any entry if it existed in
034: the position set in the old parent. For nodes that are owned by the
035: user (PLF owned nodes) the nodes are moved outright and now position
036: set is needed unless the new parent contains ILF nodes as well
037: requiring preservation of the user's ordering of the nodes for when the
038: ILF and PLF are merged again later on.
039: */
040: public static void moveElement(Element compViewNode,
041: Element oldCompViewParent, IPerson person)
042: throws PortalException {
043: if (LOG.isInfoEnabled())
044: LOG.info("moving "
045: + compViewNode.getAttribute(Constants.ATT_ID));
046: Element compViewParent = (Element) compViewNode.getParentNode();
047:
048: if (oldCompViewParent != compViewParent) {
049: if (LOG.isInfoEnabled())
050: LOG
051: .info("reparenting from "
052: + oldCompViewParent
053: .getAttribute(Constants.ATT_ID)
054: + " to "
055: + compViewParent
056: .getAttribute(Constants.ATT_ID));
057: // update previous parent if found in PLF
058: Element plfParent = HandlerUtils.getPLFNode(
059: oldCompViewParent, person, // only needed if creating
060: false, // only look, don't create
061: false); // also not needed
062: if (plfParent != null) {
063: PositionManager.updatePositionSet(oldCompViewParent,
064: plfParent, person);
065: if (LOG.isInfoEnabled())
066: LOG.info("updating old parent's position set");
067: }
068: }
069: // now take care of the destination
070: Element plfParent = HandlerUtils.getPLFNode(compViewParent,
071: person, true, // create parent if not found
072: false); // don't create children
073: if (compViewNode.getAttribute(Constants.ATT_ID).startsWith(
074: Constants.FRAGMENT_ID_USER_PREFIX)) {
075: // ilf node being inserted
076: if (LOG.isInfoEnabled())
077: LOG
078: .info("ilf node being moved, only update new parent pos set");
079: PositionManager.updatePositionSet(compViewParent,
080: plfParent, person);
081: } else {
082: // plf node
083: if (LOG.isInfoEnabled())
084: LOG
085: .info("plf node being moved, updating old parent's position set");
086: Document plf = (Document) person
087: .getAttribute(Constants.PLF);
088: HandlerUtils.createOrMovePLFOwnedNode(compViewNode,
089: compViewParent, false, // should always be found
090: false, // irrelevant, not creating
091: plf, plfParent, person);
092: }
093: }
094:
095: /**
096: Handles user requests to delete UI elements. For ILF owned nodes it
097: delegates to the DeleteManager to add a delete directive. For PLF
098: owned nodes it deletes the node outright.
099: */
100: public static void deleteNode(Element compViewNode,
101: Element compViewParent, IPerson person)
102: throws PortalException {
103: String ID = compViewNode.getAttribute(Constants.ATT_ID);
104:
105: if (ID.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) // ilf node
106: DeleteManager.addDeleteDirective(compViewNode, ID, person);
107: else {
108: // plf node
109: Document plf = (Document) person
110: .getAttribute(Constants.PLF);
111: Element node = plf.getElementById(ID);
112:
113: if (node == null)
114: return;
115: Element parent = (Element) node.getParentNode();
116: if (parent == null)
117: return;
118: parent.removeChild(node);
119: }
120: }
121:
122: }
|