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.Element;
11:
12: /**
13: * Layout processing action for changnig the set of restrictions for a fragment
14: * node.
15: *
16: * @author Mark Boyd
17: */
18: public class LPAEditRestriction implements ILayoutProcessingAction {
19: private IPerson person = null;
20: private Element ilfNode = null;
21: private boolean moveAllowed = false;
22: private boolean deleteAllowed = false;
23: private boolean editAllowed = false;
24: private boolean addChildAllowed = false;
25:
26: LPAEditRestriction(IPerson p, Element ilfNode, boolean moveAllowed,
27: boolean deleteAllowed, boolean editAllowed,
28: boolean addChildAllowed) {
29: this .person = p;
30: this .ilfNode = ilfNode;
31: this .moveAllowed = moveAllowed;
32: this .deleteAllowed = deleteAllowed;
33: this .editAllowed = editAllowed;
34: this .addChildAllowed = addChildAllowed;
35: }
36:
37: /**
38: * Pushes the indicated restriction attribute changes into both the ILF and
39: * PLF versions of the layouts since this will only be done when editing a
40: * fragment.
41: */
42: public void perform() throws PortalException {
43: Element plfNode = HandlerUtils.getPLFNode(ilfNode, person,
44: false, false);
45:
46: if (plfNode == null)
47: return;
48:
49: changeRestriction(Constants.ATT_MOVE_ALLOWED, plfNode,
50: moveAllowed);
51: changeRestriction(Constants.ATT_MOVE_ALLOWED, ilfNode,
52: moveAllowed);
53: changeRestriction(Constants.ATT_DELETE_ALLOWED, plfNode,
54: deleteAllowed);
55: changeRestriction(Constants.ATT_DELETE_ALLOWED, ilfNode,
56: deleteAllowed);
57: changeRestriction(Constants.ATT_EDIT_ALLOWED, plfNode,
58: editAllowed);
59: changeRestriction(Constants.ATT_EDIT_ALLOWED, ilfNode,
60: editAllowed);
61:
62: if (plfNode.getAttribute(Constants.ATT_CHANNEL_ID).equals("")) {
63: // if channel id is empty then this is not a channel.
64: // childAllowed is always true for channel ad-hoc parameters.
65: changeRestriction(Constants.ATT_ADD_CHILD_ALLOWED, plfNode,
66: addChildAllowed);
67: changeRestriction(Constants.ATT_ADD_CHILD_ALLOWED, ilfNode,
68: addChildAllowed);
69: }
70: }
71:
72: private void changeRestriction(String name, Element element,
73: boolean value) {
74: // The default value for these attributes,
75: // if not included on an element, is true so we remove the attribute if
76: // we see a parm value of true and add the attribute with a value of
77: // false if a parm value is false. This also saves on the number of
78: // rows in the up_layout_param table and hence on read and write time.
79:
80: if (value == false)
81: element.setAttributeNS(Constants.NS_URI, name, "false");
82: else
83: element.removeAttribute(name);
84: }
85: }
|