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: package org.jasig.portal.layout.dlm;
06:
07: import org.w3c.dom.Attr;
08: import org.w3c.dom.Element;
09: import org.w3c.dom.NodeList;
10:
11: /**
12: * This class wraps channel layout elements in cached fragment definitions to
13: * enable the layout manager to make informed descisions on what channel
14: * parameters should be persisted. Parameter elements residing in the user's
15: * layout do not indicate if they came from a user change or from a fragment's
16: * defined value. This class enables the layout manager to such determinations.
17: *
18: * @version $Revision: 36294 $ $Date: 2005-11-10 12:36:31 -0700 (Thu, 10 Nov 2005) $
19: * @author mboyd@sungardsct.com
20: * @since uPortal 2.5
21: */
22: class FragmentChannelInfo extends FragmentNodeInfo {
23: FragmentChannelInfo(Element channel) {
24: super (channel);
25: }
26:
27: /**
28: * Returns the value of an parameter or null if such a parameter is not
29: * defined on the underlying channel element.
30: */
31: public String getParameterValue(String name) {
32: NodeList parms = node.getChildNodes();
33:
34: for (int i = 0; i < parms.getLength(); i++) {
35: Element parm = (Element) parms.item(i);
36: if (parm.getTagName().equals(Constants.ELM_PARAMETER)) {
37: String parmName = parm.getAttribute(Constants.ATT_NAME);
38: if (parmName.equals(name)) {
39: return parm.getAttribute(Constants.ATT_VALUE);
40: }
41: }
42: }
43: // if we get here then neither the fragment nor the channel definition
44: // provided this parameter
45: return null;
46: }
47:
48: /**
49: * Returns true if a parameter can be modified for a channel. This is based
50: * on a single dlm:editAllowed attribute for each channel parameter in
51: * fragments. If not included then edits to that channel parameter are
52: * allowed. If included with a value other than true then edits to that
53: * parameter for that channel are prevented.
54: *
55: * @param name
56: * @return
57: */
58: public boolean canOverrideParameter(String name) {
59: NodeList parms = node.getChildNodes();
60:
61: for (int i = 0; i < parms.getLength(); i++) {
62: Element parm = (Element) parms.item(i);
63: if (parm.getTagName().equals(Constants.ELM_PARAMETER)) {
64: String parmName = parm.getAttribute(Constants.ATT_NAME);
65: if (parmName.equals(name)) {
66: Attr editAllowed = parm.getAttributeNodeNS(
67: Constants.NS_URI,
68: Constants.ATT_EDIT_ALLOWED);
69: if (editAllowed == null
70: || !editAllowed.getNodeValue().equals(
71: "false"))
72: return true;
73: else
74: return false;
75: }
76: }
77: }
78: // if we get here then the fragment doesn't specify this param
79: return true;
80: }
81: }
|