001: /**
002: * $Id: SettingsBean.java,v 1.2 2006/04/17 20:08:41 jtb Exp $
003: * Copyright 2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.rssportlet;
014:
015: import java.util.Locale;
016: import java.util.LinkedList;
017: import java.util.Collections;
018:
019: /**
020: * This class is a bean to hold the settings for the RSS portlet.
021: *
022: * This bean is prepared (populated) by an <code>SettingsHandler</class>
023: * object, when it is set into the handler.
024: *
025: * In addition to normal getters and setters,
026: * this class contains a set of <code>is*Set()</code> methods. These are used
027: * to determine if the value for the field has been set into this bean. This
028: * information is used to determine if the value has changed, and should
029: * therefore be persisted.
030: */
031: public class SettingsBean {
032: // use LinkedList, because we want to ensure a few optional List
033: // operations are there
034: private LinkedList feeds;
035: private String selectedFeed = null;
036: private String windowTarget = null;
037: private Integer maxAge = null;
038: private Integer cacheTimeout = null;
039: private Integer maxDescriptionLength = null;
040: private Boolean newWindow = null;
041: private Boolean disableMaxAge = null;
042: private Integer maxEntries = null;
043: private Locale locale = null;
044:
045: /** Get the selected feed. */
046: public String getSelectedFeed() {
047: return selectedFeed;
048: }
049:
050: /** Set the selected feed. */
051: public void setSelectedFeed(String feed) {
052: this .selectedFeed = feed;
053: }
054:
055: /**
056: * Get the cache timeout.
057: *
058: * The cache timeout should be a positive number of seconds defining the
059: * length in time that feed entries may be cached. It may also be equal to
060: * zero indicating that the feed entries should never be cached. If the
061: * value is negative, the feed entries may be cached forever.
062: */
063: public int getCacheTimeout() {
064: return cacheTimeout.intValue();
065: }
066:
067: /** Set the cache timeout. */
068: public void setCacheTimeout(int timeout) {
069: this .cacheTimeout = new Integer(timeout);
070: }
071:
072: /**
073: * Get the maximum description length.
074: *
075: * This determines the number of characters that will be displayed for a
076: * feed's description. This is to prevent the portal display from being
077: * adversely affected in the case where the feed entries contain
078: * a very long description.
079: */
080: public int getMaxDescriptionLength() {
081: return maxDescriptionLength.intValue();
082: }
083:
084: /** Set the maximum description length. */
085: public void setMaxDescriptionLength(int length) {
086: this .maxDescriptionLength = new Integer(length);
087: }
088:
089: /** Should feed links be opened in a new window? */
090: public boolean isNewWindow() {
091: return newWindow.booleanValue();
092: }
093:
094: /** Has the new window value been set into this bean? */
095: public boolean isNewWindowSet() {
096: return newWindow != null;
097: }
098:
099: /** Set if feed links should be opened in a new window. */
100: public void setNewWindow(boolean nw) {
101: this .newWindow = new Boolean(nw);
102: }
103:
104: /** Get the window target for feed links.
105: *
106: * This has no respective setter, and is based on the return value
107: * of <code>isNewWindow()</code>. If said method returns true,
108: * this method returns the string "_blank", else it returns "_top".
109: */
110: public String getWindowTarget() {
111: String target = null;
112: if (isNewWindow()) {
113: target = "_blank";
114: } else {
115: target = "_top";
116: }
117:
118: return target;
119: }
120:
121: /**
122: * Get the start feed.
123: *
124: * The start feed is the initial feed which is displayed when the user
125: * logs in to the portal.
126: */
127: public String getStartFeed() {
128: if (getFeeds().isEmpty()) {
129: return null;
130: }
131: return (String) getFeeds().get(0);
132: }
133:
134: /**
135: * Set the start feed.
136: *
137: * This method removes the feed from the feeds list, if it exists there
138: * currently, and adds it at the beginning of the list.
139: */
140: public void setStartFeed(String feed) {
141: getFeeds().remove(feed);
142: getFeeds().add(0, feed);
143: }
144:
145: /** Get all configured feeds. */
146: public LinkedList getFeeds() {
147: return feeds;
148: }
149:
150: /** Set all configured feeds. */
151: public void setFeeds(LinkedList feeds) {
152: if (feeds == null) {
153: // make sure the getter never returns null;
154: feeds = new LinkedList();
155: }
156: this .feeds = feeds;
157: }
158:
159: /**
160: * Get the size of the feeds set.
161: *
162: * As opposed to calling <code>getFeeds().size()</code>, this is provided
163: * for bean access within the display logic, as the Java
164: * <code>Collection.size()</code> method is not bean-conforming.
165: *
166: * This methos simply returns <code>getFeeds().size()</code>.
167: */
168: public int getFeedsSize() {
169: return getFeeds().size();
170: }
171:
172: /**
173: * Get the maximum feed entry age for display.
174: *
175: * The display logic should not display any feed entries
176: * that were published more than this number of hours
177: * previous to now.
178: */
179: public int getMaxAge() {
180: return maxAge.intValue();
181: }
182:
183: /** Set the maximum feed entry age. */
184: public void setMaxAge(int age) {
185: this .maxAge = new Integer(age);
186: }
187:
188: /**
189: * Is the maximum feed entry age value set into this bean?
190: */
191: public boolean isMaxAgeSet() {
192: return maxAge != null;
193: }
194:
195: /**
196: * Is the maximum age restriction disabled?
197: *
198: * If so, the display logic will ignore the maximum age setting
199: * and display entries up to the number of maximum entries allowed.
200: */
201: public boolean isDisableMaxAge() {
202: return disableMaxAge.booleanValue();
203: }
204:
205: /** Set if the maximum age restriction is enabled. */
206: public void setDisableMaxAge(boolean disableMaxAge) {
207: this .disableMaxAge = new Boolean(disableMaxAge);
208: }
209:
210: /** Is the maximum age restriction disabled flag set into this bean? */
211: public boolean isDisableMaxAgeSet() {
212: return disableMaxAge != null;
213: }
214:
215: /** Get the maximum entries that will be displayed. */
216: public int getMaxEntries() {
217: return maxEntries.intValue();
218: }
219:
220: /** Set the maximum entries that will be displayed. */
221: public void setMaxEntries(int maxEntries) {
222: this .maxEntries = new Integer(maxEntries);
223: }
224:
225: /** Is the maximum entries value set into this bean? */
226: public boolean isMaxEntriesSet() {
227: return maxEntries != null;
228: }
229:
230: public Locale getLocale() {
231: return locale;
232: }
233:
234: public void setLocale(Locale locale) {
235: this.locale = locale;
236: }
237: }
|