01: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.layout.dlm;
07:
08: import org.jasig.portal.PortalException;
09: import org.jasig.portal.security.IPerson;
10: import org.w3c.dom.Document;
11: import org.w3c.dom.Element;
12:
13: /**
14: * Layout processing action for removing a channel parameter from the user's layout.
15: *
16: * @author Mark Boyd
17: */
18: public class LPARemoveParameter implements ILayoutProcessingAction {
19: private String nodeId = null;
20: private String name = null;
21: private IPerson person = null;
22: private Element ilfNode = null;
23:
24: LPARemoveParameter(String nodeId, String name, IPerson p,
25: Element ilfNode) {
26: this .nodeId = nodeId;
27: this .name = name;
28: this .person = p;
29: this .ilfNode = ilfNode;
30: }
31:
32: /**
33: * Remove the parameter from a channel in both the ILF and PLF using the
34: * appropriate mechanisms for incorporated nodes versus owned nodes.
35: */
36: public void perform() throws PortalException {
37: // push the change into the PLF
38: if (nodeId.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) {
39: // we are dealing with an incorporated node
40: ParameterEditManager.removeParmEditDirective(nodeId, name,
41: person);
42: } else {
43: // node owned by user so add parameter child directly
44: Document plf = RDBMDistributedLayoutStore.getPLF(person);
45: Element plfNode = plf.getElementById(nodeId);
46: removeParameterChild(plfNode, name);
47: }
48: // push the change into the ILF
49: removeParameterChild(ilfNode, name);
50: }
51:
52: /**
53: * @param node the parent node in which to create the parameter.
54: * @param name the name of the parameter to be created.
55: * @param value the value of the parameter to be created.
56: */
57: static void removeParameterChild(Element node, String name) {
58: if (node != null) {
59: for (Element parm = (Element) node.getFirstChild(); parm != null; parm = (Element) parm
60: .getNextSibling()) {
61: if (parm.getAttribute(Constants.ATT_NAME).equals(name)) {
62: node.removeChild(parm);
63: return;
64: }
65: }
66: }
67: }
68: }
|