001: package org.jasig.portal.layout.dlm;
002:
003: import org.jasig.portal.PortalException;
004: import org.jasig.portal.layout.node.IUserLayoutChannelDescription;
005: import org.jasig.portal.layout.node.UserLayoutChannelDescription;
006: import org.jasig.portal.layout.node.UserLayoutNodeDescription;
007: import org.w3c.dom.Document;
008: import org.w3c.dom.Element;
009:
010: /**
011: * DLM specific Channel description to protect DLM artifacts of channels.
012: *
013: * @author mboyd@sungardct.com
014: */
015: public class ChannelDescription extends UserLayoutChannelDescription {
016: private String plfId = null;
017: private String origin = null;
018: private FragmentChannelInfo fragmentChannelInfo = null;
019:
020: public FragmentChannelInfo getFragmentChannelInfo() {
021: return fragmentChannelInfo;
022: }
023:
024: public void resetParameter(String parameterName)
025: throws PortalException {
026: /*
027: * If this channel is not from a fragment then let the parent handle
028: * resetting to potentially drop back to the publish time parameter
029: * value if not ad-hoc. If from a fragment then we drop back to the
030: * value held by the fragment or if ad-hoc remove it completely.
031: */
032: if (this .fragmentChannelInfo != null) {
033: String value = fragmentChannelInfo
034: .getParameterValue(parameterName);
035: if (value == null) // user, ad-hoc parm so delete
036: {
037: super .remove(parameterName);
038: } else if (fragmentChannelInfo
039: .canOverrideParameter(parameterName))
040: super .setParameterValue(parameterName, value);
041: } else
042: super .resetParameter(parameterName);
043: }
044:
045: public void setFragmentChannelInfo(
046: FragmentChannelInfo fragmentChannelInfo) {
047: this .fragmentChannelInfo = fragmentChannelInfo;
048: }
049:
050: public String getOrigin() {
051: return origin;
052: }
053:
054: public void setOrigin(String origin) {
055: if (origin != null && origin.equals(""))
056: origin = null;
057: this .origin = origin;
058: }
059:
060: public String getPlfId() {
061: return plfId;
062: }
063:
064: public void setPlfId(String plfId) {
065: if (plfId != null && plfId.equals(""))
066: plfId = null;
067: this .plfId = plfId;
068: }
069:
070: /**
071: * For DLM parameters starting with the dlm namespace are reserved for use
072: * by DLM and hence can't be overridden. The channel published definition
073: * may restrict updating. And finally, a fragment may restrict updating.
074: */
075: public boolean getParameterOverrideValue(String parameterName) {
076: if (parameterName.startsWith(Constants.NS)
077: || !super .getParameterOverrideValue(parameterName)
078: || (fragmentChannelInfo != null && !fragmentChannelInfo
079: .canOverrideParameter(parameterName)))
080: return false;
081: return true;
082: }
083:
084: /**
085: * Shadowing version of the same method in UserLayoutNodeDescription to
086: * produce DLM specific instances for channels.
087: *
088: * @param xmlNode a user layout DTD folder/channel <code>Element</code> value
089: * @return an <code>UserLayoutNodeDescription</code> value
090: * @exception PortalException if the xml passed is somehow invalid.
091: */
092: public static UserLayoutNodeDescription createUserLayoutNodeDescription(
093: Element xmlNode) throws PortalException {
094: // is this a channel ?
095: String nodeName = xmlNode.getNodeName();
096: if (nodeName.equals("channel"))
097: return new ChannelDescription(xmlNode);
098: else
099: return UserLayoutNodeDescription
100: .createUserLayoutNodeDescription(xmlNode);
101: }
102:
103: /**
104: * Overridden constructor of super class.
105: */
106: public ChannelDescription() {
107: super ();
108: }
109:
110: /**
111: * Overridden constructor of super class.
112: *
113: * @param xmlNode the Element to be represented
114: * @throws PortalException
115: */
116: public ChannelDescription(Element xmlNode) throws PortalException {
117: super (xmlNode);
118: // dlm-specific attributes
119: this .setPlfId(xmlNode.getAttributeNS(Constants.NS_URI,
120: Constants.LCL_PLF_ID));
121: this .setOrigin(xmlNode.getAttributeNS(Constants.NS_URI,
122: Constants.LCL_ORIGIN));
123: }
124:
125: /**
126: * Overridden constructor of super class.
127: *
128: * @param d an IUserLayoutChannelDescription
129: */
130: public ChannelDescription(IUserLayoutChannelDescription d) {
131: super (d);
132:
133: if (d instanceof ChannelDescription) {
134: ChannelDescription cd = (ChannelDescription) d;
135: this .setPlfId(cd.getPlfId());
136: this .setOrigin(cd.getOrigin());
137: }
138: }
139:
140: public Element getXML(Document root) {
141: Element node = super .getXML(root);
142:
143: // now add in DLM specific attributes if found
144: if (getPlfId() != null)
145: node.setAttributeNS(Constants.NS_URI, Constants.ATT_PLF_ID,
146: getPlfId());
147:
148: if (getOrigin() != null)
149: node.setAttributeNS(Constants.NS_URI, Constants.ATT_ORIGIN,
150: getOrigin());
151: return node;
152: }
153: }
|