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 adding a channel parameter to the user's layout.
15: *
16: * @author Mark Boyd
17: */
18: public class LPAAddParameter implements ILayoutProcessingAction {
19: private String nodeId = null;
20: private String name = null;
21: private IPerson person = null;
22: private Element ilfNode = null;
23: private String value = null;
24:
25: LPAAddParameter(String nodeId, String name, String value,
26: IPerson p, Element ilfNode) {
27: this .nodeId = nodeId;
28: this .name = name;
29: this .person = p;
30: this .ilfNode = ilfNode;
31: this .value = value;
32: }
33:
34: /**
35: * Add a parameter for a channel in both the ILF and PLF using the
36: * appropriate mechanisms for incorporated nodes versus owned nodes.
37: */
38: public void perform() throws PortalException {
39: // push the change into the PLF
40: if (nodeId.startsWith(Constants.FRAGMENT_ID_USER_PREFIX)) {
41: // we are dealing with an incorporated node
42: ParameterEditManager.addParmEditDirective(ilfNode, nodeId,
43: name, value, person);
44: } else {
45: // node owned by user so add parameter child directly
46: Document plf = RDBMDistributedLayoutStore.getPLF(person);
47: Element plfNode = plf.getElementById(nodeId);
48: addParameterChild(plfNode, name, value);
49: }
50: // push the change into the ILF
51: addParameterChild(ilfNode, name, value);
52: }
53:
54: /**
55: * Performs parameter child element creation in the passed in Element.
56: *
57: * @param node the parent node in which to create the parameter.
58: * @param name the name of the parameter to be created.
59: * @param value the value of the parameter to be created.
60: */
61: static void addParameterChild(Element node, String name,
62: String value) {
63: if (node != null) {
64: Document doc = node.getOwnerDocument();
65: Element parm = doc.createElement(Constants.ELM_PARAMETER);
66: parm.setAttribute(Constants.ATT_NAME, name);
67: parm.setAttribute(Constants.ATT_VALUE, value);
68: /*
69: * Set the override attribute to 'yes'. This isn't persisted since
70: * this is determined upon loading the layout based upon the
71: * channel definition. But for code that references this in-memory
72: * value like ChannelStaticData it needs to be set.
73: */
74: parm.setAttribute(Constants.ATT_OVERRIDE,
75: Constants.CAN_OVERRIDE);
76: node.appendChild(parm);
77: }
78: }
79: }
|