001: /* Copyright 2001, 2002, 2005 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;
007:
008: import java.util.ArrayList;
009: import java.util.List;
010:
011: import org.apache.commons.logging.Log;
012: import org.apache.commons.logging.LogFactory;
013: import org.jasig.portal.RDBMServices;
014:
015: /**
016: * LayoutStructure represents a channel or folder in a layout.
017: * @version $Revision: 35797 $ $Date: 2005-05-16 10:27:27 -0700 (Mon, 16 May 2005) $
018: * @since uPortal 2.5 - before 2.5 this class existed as a public inner class of RDBMUserLayoutStore.
019: */
020: public final class LayoutStructure {
021:
022: private static final Log LOG = LogFactory
023: .getLog(LayoutStructure.class);
024:
025: /**
026: * The ID of this LayoutStructure.
027: */
028: private final int structId;
029:
030: /**
031: * The ID of the LayoutStructure that is the next sibling of this LayoutStructure.
032: */
033: private final int nextId;
034:
035: /**
036: * The ID of the LayoutStructure that is the child of this LayoutStructure.
037: */
038: private final int childId;
039:
040: /**
041: * The ID of any channel that this LayoutStructure instance is representing.
042: * Zero if this LayoutStructure instance does not represent a channel.
043: */
044: private final int chanId;
045:
046: /**
047: * When this LayoutStructure represents a folder, the name of that folder.
048: * Null otherwise.
049: */
050: private String name;
051:
052: /**
053: * When this LayoutStructure represents a folder, the type of that folder.
054: * Null otherwise.
055: */
056: private String type;
057:
058: /**
059: * True if this LayoutStructure is hidden, false otherwise.
060: */
061: private boolean hidden;
062:
063: /**
064: * True if this LayoutStructure cannot be removed, false otherwise.
065: */
066: private boolean unremovable;
067:
068: /**
069: * True if this LayoutStructure cannot be changed, false otherwise.
070: */
071: private boolean immutable;
072:
073: /**
074: * A List of StructureParameter instances representing parameters
075: * to this LayoutStructure.
076: *
077: * Prior to uPortal 2.5, this field was null when there were no parameters. Now
078: * this field is never null and no parameters are repreesented by an empty list.
079: */
080: private final List parameters = new ArrayList();
081:
082: private String locale;
083:
084: /**
085: * Instantiate a new LayoutStructure with the given configuration.
086: * @param structId the id of this LayoutStructure
087: * @param nextId the id of the next sibling of this LayoutStructure
088: * @param childId the id of the first child of this LayoutStructure
089: * @param chanId the id of the channel represented by this LayoutStructure, or zero if we do not represent a channel
090: * @param hidden "T" or "Y" if this LayoutStructure is hidden
091: * @param unremovable "T" or "Y" if this LayoutStructure is unremovable
092: * @param immutable "T" or "Y" if this LayoutStructure is unchangeable
093: */
094: public LayoutStructure(int structId, int nextId, int childId,
095: int chanId, String hidden, String unremovable,
096: String immutable) {
097: this .nextId = nextId;
098: this .childId = childId;
099: this .chanId = chanId;
100: this .structId = structId;
101: this .hidden = RDBMServices.dbFlag(hidden);
102: this .immutable = RDBMServices.dbFlag(immutable);
103: this .unremovable = RDBMServices.dbFlag(unremovable);
104:
105: if (LOG.isTraceEnabled()) {
106: LOG.trace("Instantiated new " + this );
107: }
108: }
109:
110: /**
111: * Instantiate a new LayoutStructure with the given configuration.
112: * @param structId the id of this LayoutStructure
113: * @param nextId the id of the next sibling of this LayoutStructure
114: * @param childId the id of the first child of this LayoutStructure
115: * @param chanId the id of the channel represented by this LayoutStructure, or zero if we do not represent a channel
116: * @param hidden "T" or "Y" if this LayoutStructure is hidden
117: * @param unremovable "T" or "Y" if this LayoutStructure is unremovable
118: * @param immutable "T" or "Y" if this LayoutStructure is unchangeable
119: * @param locale the locale of this LayoutStructure
120: */
121: public LayoutStructure(int structId, int nextId, int childId,
122: int chanId, String hidden, String unremovable,
123: String immutable, String locale) {
124: this .nextId = nextId;
125: this .childId = childId;
126: this .chanId = chanId;
127: this .structId = structId;
128: this .hidden = RDBMServices.dbFlag(hidden);
129: this .immutable = RDBMServices.dbFlag(immutable);
130: this .unremovable = RDBMServices.dbFlag(unremovable);
131: this .locale = locale; // for i18n by Shoji
132:
133: if (LOG.isTraceEnabled()) {
134: LOG.trace("Instantiated new " + this );
135: }
136: }
137:
138: /**
139: * Add information about the folder represented by this LayoutStructure.
140: * @param folderName the name of the folder
141: * @param folderType the type of the folder
142: */
143: public void addFolderData(String folderName, String folderType) {
144: this .name = folderName;
145: this .type = folderType;
146: }
147:
148: /**
149: * Returns true if this LayoutStructure represents a channel, false otherwise.
150: * Otherwise is the case where this LayoutStructure represents a folder.
151: * @return true if a channel, false if a folder.
152: */
153: public boolean isChannel() {
154: return this .chanId != 0;
155: }
156:
157: /**
158: * Add a parameter to this LayoutStructure.
159: * @param paramName the name of the parameter
160: * @param paramValue the value of the parameter
161: */
162: public void addParameter(String paramName, String paramValue) {
163: this .parameters.add(new StructureParameter(paramName,
164: paramValue));
165: }
166:
167: /**
168: * Get the id of the next LayoutStructure or zero if there is no next LayoutStructure.
169: * @return 0 or the id of the next layout structure.
170: */
171: public int getNextId() {
172: return this .nextId;
173: }
174:
175: /**
176: * Get the id of the child of this LayoutStructure, or zero if we do not have
177: * a child.
178: * @return 0 or the id of our child.
179: */
180: public int getChildId() {
181: return this .childId;
182: }
183:
184: /**
185: * Get the id of the channel represented by this LayoutStructure instance,
186: * or zero if we do not represent a channel.
187: * @return 0 or the id of the channel
188: */
189: public int getChanId() {
190: return this .chanId;
191: }
192:
193: /**
194: * Get the id of this LayoutStructure.
195: *
196: * @return the id of this LayoutStructure.
197: */
198: public int getStructId() {
199: return this .structId;
200: }
201:
202: /**
203: * Return true if this LayoutStructure is hidden, false otherwise.
204: *
205: * @return true if this LayoutStructure is hidden, false otherwise.
206: */
207: public boolean isHidden() {
208: return this .hidden;
209: }
210:
211: /**
212: * Returns true if this LayoutStructure is immutable, false otherwise.
213: *
214: * @return false if this LayoutStructure can be changed, true otherwise.
215: */
216: public boolean isImmutable() {
217: return this .immutable;
218: }
219:
220: /**
221: * Get the locale of this LayoutStructure.
222: *
223: * @return the locale of this LayoutStructure.
224: */
225: public String getLocale() {
226: return this .locale;
227: }
228:
229: /**
230: * Get the name of the folder that this LayoutStructure represents, or null
231: * if this LayoutStructure does not represent a folder.
232: *
233: * @return the name of this LayoutStructure.
234: */
235: public String getName() {
236: return this .name;
237: }
238:
239: /**
240: * Get a List of StructureParameter instances representing parameters of
241: * this LayoutStructure instance.
242: *
243: * Prior to uPortal 2.5, this method would return null when there were no
244: * parameters. Now we return an empty list when there are no parameters.
245: * This simplifies consumers of this class, who can simply blithely iterate over
246: * the empty list and no longer have to check for null.
247: *
248: * @return a List of StructureParameter instances.
249: */
250: public List getParameters() {
251: return this .parameters;
252: }
253:
254: /**
255: * Get the String representing the type of the folder that this LayoutStructure
256: * represents, or null if this LayoutStructure does not represent a folder.
257: * Different layout management approaches may define differing types of
258: * folders for their own purposes. The core types typically used by all
259: * are: header, footer, and regular. The value returned is the value found
260: * in the up_layout_struct table's type column. For instances of
261: * LayoutStructure that represent a channel this method will return a
262: * value of null.
263: *
264: * @return a String representing the type of this layout structure.
265: */
266: public String getType() {
267: return this .type;
268: }
269:
270: /**
271: * Return true if this structure is unremovable, false otherwise.
272: *
273: * @return false if this structure can be removed, true otherwise.
274: */
275: public boolean isUnremovable() {
276: return this .unremovable;
277: }
278:
279: public String toString() {
280: StringBuffer sb = new StringBuffer();
281: sb.append("LayoutStructure:");
282: sb.append(" structId = ").append(this .structId);
283: sb.append(" nextId = ").append(this .nextId);
284: sb.append(" childId = ").append(this .childId);
285: sb.append(" chanId = ").append(this .chanId);
286: sb.append(" name = [").append(this .name).append("]");
287: sb.append(" hidden = ").append(this .hidden);
288: sb.append(" unremovable = ").append(this .unremovable);
289: sb.append(" immutable = ").append(this .immutable);
290: sb.append(" parameters = [").append(this .parameters);
291: sb.append(" locale = [").append(this .locale).append("]");
292:
293: return sb.toString();
294: }
295: }
|