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.Collection;
009: import java.util.HashMap;
010: import java.util.Map;
011: import java.util.Vector;
012:
013: import org.jasig.portal.PortalException;
014: import org.jasig.portal.layout.node.IUserLayoutNodeDescription;
015: import org.jasig.portal.layout.restrictions.IUserLayoutRestriction;
016: import org.w3c.dom.Element;
017:
018: /**
019: * IALNode summary sentence goes here.
020: * <p>
021: * Company: Instructional Media & Magic
022: *
023: * Prior to uPortal 2.5, this class existed in the package org.jasig.portal.layout.
024: * It was moved to its present package to reflect that it is part of Aggregated
025: * Layouts.
026: *
027: * @author <a href="mailto:mvi@immagic.com">Michael Ivanov</a>
028: * @version $Revision: 36812 $
029: */
030: public abstract class ALNode implements IALNode {
031:
032: private String parentNodeId;
033: private String nextNodeId;
034: private String previousNodeId;
035: private IALNodeDescription nodeDescription;
036: private int priority = 0;
037:
038: private final Map nodeAttributes = new HashMap(0);
039:
040: public ALNode() {
041: }
042:
043: public ALNode(IALNodeDescription nd) {
044: nodeDescription = nd;
045: }
046:
047: public String getId() {
048: return nodeDescription.getId();
049: }
050:
051: public String getFragmentId() {
052: return nodeDescription.getFragmentId();
053: }
054:
055: public String getFragmentNodeId() {
056: return nodeDescription.getFragmentNodeId();
057: }
058:
059: /**
060: * Gets the node type
061: * @return a node type
062: */
063: public abstract int getNodeType();
064:
065: public void setNodeDescription(IALNodeDescription nd) {
066: nodeDescription = nd;
067: }
068:
069: public IUserLayoutNodeDescription getNodeDescription() {
070: return nodeDescription;
071: }
072:
073: public void setParentNodeId(String parentNodeId) {
074: this .parentNodeId = parentNodeId;
075: }
076:
077: public String getParentNodeId() {
078: return parentNodeId;
079: }
080:
081: public void setNextNodeId(String nextNodeId) {
082: this .nextNodeId = nextNodeId;
083: }
084:
085: public String getNextNodeId() {
086: return nextNodeId;
087: }
088:
089: public void setPreviousNodeId(String previousNodeId) {
090: this .previousNodeId = previousNodeId;
091: }
092:
093: public String getPreviousNodeId() {
094: return previousNodeId;
095: }
096:
097: /**
098: * Sets the priority for this node.
099: * @param priority a <code>int</code> priority value
100: */
101: public void setPriority(int priority) {
102: this .priority = priority;
103: }
104:
105: /**
106: * Gets the priority value for this node.
107: */
108: public int getPriority() {
109: return priority;
110: }
111:
112: /**
113: * Gets a restriction by the type.
114: * @param restrictionName a <code>String</code> name of the restriction
115: * @return a IUserLayoutRestriction
116: */
117: public IUserLayoutRestriction getRestriction(String restrictionName) {
118: if (nodeDescription != null)
119: return nodeDescription.getRestriction(restrictionName);
120: return null;
121: }
122:
123: /**
124: * Gets a restrictions list by a restriction path.
125: * @param restrictionPath a <code>String</code> restriction path
126: * @return a IUserLayoutRestriction
127: */
128: public Collection getRestrictionsByPath(String restrictionPath) {
129: if (nodeDescription != null)
130: return nodeDescription
131: .getRestrictionsByPath(restrictionPath);
132: return new Vector();
133: }
134:
135: /**
136: * Add all of common node attributes to the <code>Element</code>.
137: * @param node an <code>Element</code> value
138: */
139: protected void addNodeAttributes(Element node) {
140: nodeDescription.addNodeAttributes(node);
141: node.setAttribute("priority", priority + "");
142: }
143:
144: /**
145: * A factory method to create a <code>IALNodeDescription</code> instance,
146: * based on the information provided in the user layout <code>Element</code>.
147: *
148: * @param xmlNode a user layout DTD folder/channel <code>Element</code> value
149: * @return an <code>IALNodeDescription</code> value
150: * @exception PortalException if the xml passed is somehow invalid.
151: */
152: public static IALNodeDescription createUserLayoutNodeDescription(
153: Element xmlNode) throws PortalException {
154: // is this a folder or a channel ?
155: String nodeName = xmlNode.getNodeName();
156: if (nodeName.equals("channel")) {
157: return new ALChannelDescription(xmlNode);
158: } else if (nodeName.equals("folder")) {
159: return new ALFolderDescription(xmlNode);
160: } else {
161: throw new PortalException(
162: "Given XML element is neither folder nor channel");
163: }
164: }
165:
166: public static ALNode createALNode(
167: IUserLayoutNodeDescription nodeDescription)
168: throws PortalException {
169: if (nodeDescription instanceof IALFolderDescription) {
170: // should be a folder
171: return new ALFolder(new ALFolderDescription(
172: (IALFolderDescription) nodeDescription));
173: } else if (nodeDescription instanceof IALChannelDescription) {
174: return new ALChannel(new ALChannelDescription(
175: (IALChannelDescription) nodeDescription));
176: } else {
177: throw new PortalException(
178: "ALNode::createALNode() : The node description supplied is neither a folder nor a channel! Can't make the ALNode");
179: }
180: }
181:
182: public String toString() {
183: return "{" + parentNodeId + "," + nextNodeId + ","
184: + previousNodeId + "," + nodeDescription + ","
185: + priority + "}";
186: }
187:
188: public Map getAttributes() {
189: return this .nodeAttributes;
190: }
191:
192: public void putAttributes(Map attributes) {
193: this.nodeAttributes.putAll(attributes);
194: }
195:
196: }
|