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.Attr;
11: import org.w3c.dom.Document;
12: import org.w3c.dom.Element;
13:
14: /**
15: * Layout processing action for changing a channel parameter in a user's layout.
16: *
17: * @author Mark Boyd
18: */
19: public class LPAChangeParameter implements ILayoutProcessingAction {
20: private String nodeId = null;
21: private String name = null;
22: private IPerson person = null;
23: private Element ilfNode = null;
24: private String value = null;
25:
26: LPAChangeParameter(String nodeId, String name, String value,
27: IPerson p, Element ilfNode) {
28: this .nodeId = nodeId;
29: this .name = name;
30: this .person = p;
31: this .ilfNode = ilfNode;
32: this .value = value;
33: }
34:
35: /**
36: * Change the parameter for a channel in both the ILF and PLF using the
37: * appropriate mechanisms for incorporated nodes versus owned nodes.
38: */
39: public void perform() throws PortalException {
40: // push the change into the PLF
41: if (nodeId.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) {
42: // we are dealing with an incorporated node, adding will replace
43: // an existing one for the same target node id and name
44: ParameterEditManager.addParmEditDirective(ilfNode, nodeId,
45: name, value, person);
46: } else {
47: // node owned by user so change existing parameter child directly
48: Document plf = RDBMDistributedLayoutStore.getPLF(person);
49: Element plfNode = plf.getElementById(nodeId);
50: changeParameterChild(plfNode, name, value);
51: }
52: // push the change into the ILF
53: changeParameterChild(ilfNode, name, value);
54: }
55:
56: /**
57: * Look in the passed-in element for a parameter child element whose value
58: * is to be changed to the passed-in value.
59: *
60: * @param node the parent node in which to create the parameter.
61: * @param name the name of the parameter to be created.
62: * @param value the value of the parameter to be created.
63: */
64: static void changeParameterChild(Element node, String name,
65: String value) {
66: if (node != null) {
67: boolean foundIt = false;
68:
69: for (Element parm = (Element) node.getFirstChild(); parm != null; parm = (Element) parm
70: .getNextSibling()) {
71: Attr att = parm.getAttributeNode(Constants.ATT_NAME);
72: if (att != null && att.getValue().equals(name)) {
73: parm.setAttribute(Constants.ATT_VALUE, value);
74: foundIt = true;
75: break;
76: }
77: }
78: if (!foundIt) // if didn't find it add a new one
79: LPAAddParameter.addParameterChild(node, name, value);
80: }
81: }
82: }
|