001: /* Copyright 2002 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.layout.alm;
007:
008: import java.util.Enumeration;
009: import java.util.Hashtable;
010: import java.util.Vector;
011:
012: import org.jasig.portal.layout.restrictions.IUserLayoutRestriction;
013: import org.jasig.portal.utils.CommonUtils;
014: import org.w3c.dom.Document;
015: import org.w3c.dom.Element;
016:
017: /**
018: * A proxy class representing additional properties of the Aggregated Layout nodes.
019: * Thanks to the java's inability to support multiple inheritance, we can make a mess out of an elegant class structure.
020: *
021: * Prior to uPortal 2.5, this class existed in the package org.jasig.portal.layout.
022: * It was moved to its present package to reflect that it is part of Aggregated
023: * Layouts.
024: *
025: * @author Peter Kharchenko {@link <a href="mailto:pkharchenko@interactivebusiness.com"">pkharchenko@interactivebusiness.com"</a>}
026: * @version 1.0 $Revision: 36690 $ $Date: 2006-08-25 14:03:25 -0700 (Fri, 25 Aug 2006) $
027: */
028: public class ALNodeProperties {
029:
030: protected String fragmentId = null;
031: protected String fragmentNodeId = null;
032: protected Hashtable restrictions = null;
033: protected String group = "";
034:
035: public ALNodeProperties() {
036: }
037:
038: public ALNodeProperties(IALNodeProperties p) {
039: this ();
040: this .fragmentId = p.getFragmentId();
041: this .fragmentNodeId = p.getFragmentNodeId();
042: this .restrictions = p.getRestrictions();
043: this .group = p.getGroup();
044: }
045:
046: /**
047: * Set fragment id
048: *
049: * @param fragmentId a <code>String</code> value
050: */
051: public void setFragmentId(String fragmentId) {
052: this .fragmentId = fragmentId;
053: }
054:
055: /**
056: * Get fragment id
057: *
058: * @return a <code>String</code> value
059: */
060: public String getFragmentId() {
061: return fragmentId;
062: }
063:
064: /**
065: * Set fragment node id
066: *
067: * @param fragmentNodeId a <code>String</code> value
068: */
069: public void setFragmentNodeId(String fragmentNodeId) {
070: this .fragmentNodeId = fragmentNodeId;
071: }
072:
073: /**
074: * Get fragment node id
075: *
076: * @return a <code>String</code> value
077: */
078: public String getFragmentNodeId() {
079: return fragmentNodeId;
080: }
081:
082: /**
083: * Sets the group identificator for this node.
084: * @param group a <code>String</code> group identificator value
085: */
086: public void setGroup(String group) {
087: this .group = group;
088: }
089:
090: /**
091: * Gets the priority value for this node.
092: */
093: public String getGroup() {
094: return group;
095: }
096:
097: /**
098: * Sets the hashtable of restrictions bound to this node
099: * @param restrictions a <code>Hashtable</code> of restriction expressions
100: */
101: public void setRestrictions(Hashtable restrictions) {
102: this .restrictions = restrictions;
103: }
104:
105: /**
106: * Gets the hashtable of restrictions bound to this node
107: * @return a set of restriction expressions
108: */
109: public Hashtable getRestrictions() {
110: return restrictions;
111: }
112:
113: /**
114: * Adds the restriction for this node.
115: * @param restriction a <code>IUserLayoutRestriction</code> a restriction
116: */
117: public void addRestriction(IUserLayoutRestriction restriction) {
118: if (restrictions == null)
119: restrictions = new Hashtable();
120: restrictions.put(restriction.getUniqueKey(), restriction);
121: }
122:
123: /**
124: * Gets a restriction by the type.
125: * @param restrictionName a <code>String</code> name of the restriction
126: * @return a IUserLayoutRestriction
127: */
128: public IUserLayoutRestriction getRestriction(String restrictionName) {
129: if (restrictions != null)
130: return (IUserLayoutRestriction) restrictions
131: .get(restrictionName);
132: return null;
133: }
134:
135: /**
136: * Gets a restrictions list by a restriction path.
137: * @param restrictionPath a <code>String</code> restriction path
138: * @return a IUserLayoutRestriction
139: */
140: public Vector getRestrictionsByPath(String restrictionPath) {
141: Vector list = new Vector();
142: if (restrictions != null) {
143: for (Enumeration enum1 = restrictions.elements(); enum1
144: .hasMoreElements();) {
145: IUserLayoutRestriction restriction = (IUserLayoutRestriction) enum1
146: .nextElement();
147: if (CommonUtils.nvl(restrictionPath).equals(
148: CommonUtils.nvl(restriction
149: .getRestrictionPath())))
150: list.add(restriction);
151: }
152: }
153: return list;
154: }
155:
156: protected void addRestrictionChildren(Element node, Document root) {
157: if (restrictions != null)
158: for (Enumeration enum1 = restrictions.elements(); enum1
159: .hasMoreElements();) {
160: Element pElement = root.createElement("restriction");
161: IUserLayoutRestriction restriction = (IUserLayoutRestriction) enum1
162: .nextElement();
163: pElement.setAttribute("path", restriction
164: .getRestrictionPath());
165: pElement.setAttribute("value", restriction
166: .getRestrictionExpression());
167: pElement.setAttribute("type", restriction.getName());
168: node.appendChild(pElement);
169: }
170: }
171: }
|