001: /**
002: * RSS framework and reader
003: * Copyright (C) 2004 Christian Robert
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */package org.jperdian.rss2.dom;
019:
020: import java.io.Serializable;
021: import java.net.URL;
022: import java.util.ArrayList;
023: import java.util.Date;
024: import java.util.HashSet;
025: import java.util.List;
026: import java.util.Set;
027:
028: import org.jperdian.rss2.RssChannelUpdateListener;
029: import org.jperdian.rss2.RssClient;
030: import org.jperdian.rss2.RssException;
031:
032: /**
033: * Implementatino of a <tt>channel</tt> element as described in the RSS
034: * specification
035: *
036: * @author Christian Robert
037: */
038:
039: public class RssChannel implements Serializable {
040:
041: private transient RssClient myClient = null;
042: private boolean stateDataLoaded = false;
043: private boolean stateDataLoadFailed = false;
044: private long myLastUpdate = -1;
045:
046: private String myTitle = "";
047: private URL myLink = null;
048: private String myDescription = "";
049: private String myLanguage = "";
050: private String myCopyright = "";
051: private String myManagingEditor = "";
052: private String myWebmaster = "";
053: private Date myPubDate = null;
054: private Date myLastBuildDate = null;
055: private List myCategoryList = new ArrayList(1);
056: private String myGenerator = "";
057: private URL myDocs = null;
058: private RssCloud myCloud = null;
059: private int myTtl = RssConstants.DEFAULT_TTL;
060: private RssImage myImage = null;
061: private String myRating = "";
062: private Set mySkipHours = new HashSet();
063: private Set mySkipDays = new HashSet();
064: private List myItemList = new ArrayList();
065: private RssTextInput myTextInput = null;
066: private List myUpdateListenerList = new ArrayList();
067:
068: public RssChannel(RssClient client) {
069: this .setClient(client);
070: }
071:
072: public String toString() {
073: StringBuffer result = new StringBuffer();
074: result.append(this .getTitle()).append(" @ ").append(
075: this .getLink());
076: result.append("\n").append(this .getDescription());
077: return result.toString();
078: }
079:
080: /**
081: * Updates the data in the current channel
082: */
083: public void update() throws RssException {
084: this .getClient().loadData(this );
085: }
086:
087: // --------------------------------------------------------------------------
088: // -- Property access methods ---------------------------------------------
089: // --------------------------------------------------------------------------
090:
091: public void addCategory(String category) {
092: this .getCategoryList().add(category);
093: }
094:
095: public List getCategoryList() {
096: return this .myCategoryList;
097: }
098:
099: public void setCategoryList(List categoryList) {
100: this .myCategoryList = categoryList;
101: }
102:
103: public RssCloud getCloud() {
104: return this .myCloud;
105: }
106:
107: public void setCloud(RssCloud cloud) {
108: this .myCloud = cloud;
109: }
110:
111: public String getCopyright() {
112: return this .myCopyright;
113: }
114:
115: public void setCopyright(String copyright) {
116: this .myCopyright = copyright;
117: }
118:
119: public String getDescription() {
120: return this .myDescription;
121: }
122:
123: public void setDescription(String description) {
124: this .myDescription = description;
125: }
126:
127: public URL getDocs() {
128: return this .myDocs;
129: }
130:
131: public void setDocs(URL docs) {
132: this .myDocs = docs;
133: }
134:
135: public String getGenerator() {
136: return this .myGenerator;
137: }
138:
139: public void setGenerator(String generator) {
140: this .myGenerator = generator;
141: }
142:
143: public RssImage getImage() {
144: return this .myImage;
145: }
146:
147: public void setImage(RssImage image) {
148: this .myImage = image;
149: }
150:
151: public void addItem(RssItem item) {
152: this .getItemList().add(item);
153: }
154:
155: public List getItemList() {
156: return this .myItemList;
157: }
158:
159: public void setItemList(List itemList) {
160: this .myItemList = itemList;
161: }
162:
163: public String getLanguage() {
164: return this .myLanguage;
165: }
166:
167: public void setLanguage(String language) {
168: this .myLanguage = language;
169: }
170:
171: public Date getLastBuildDate() {
172: return this .myLastBuildDate;
173: }
174:
175: public void setLastBuildDate(Date lastBuildDate) {
176: this .myLastBuildDate = lastBuildDate;
177: }
178:
179: public URL getLink() {
180: return this .myLink;
181: }
182:
183: public void setLink(URL link) {
184: this .myLink = link;
185: }
186:
187: public String getManagingEditor() {
188: return this .myManagingEditor;
189: }
190:
191: public void setManagingEditor(String managingEditor) {
192: this .myManagingEditor = managingEditor;
193: }
194:
195: public Date getPubDate() {
196: return this .myPubDate;
197: }
198:
199: public void setPubDate(Date pubDate) {
200: this .myPubDate = pubDate;
201: }
202:
203: public String getRating() {
204: return this .myRating;
205: }
206:
207: public void setRating(String rating) {
208: this .myRating = rating;
209: }
210:
211: public void addSkipDay(String day) {
212: this .getSkipDays().add(day);
213: }
214:
215: public Set getSkipDays() {
216: return this .mySkipDays;
217: }
218:
219: public void setSkipDays(Set skipDays) {
220: this .mySkipDays = skipDays;
221: }
222:
223: public void addSkipHour(int hour) {
224: this .getSkipHours().add(new Integer(hour));
225: }
226:
227: public Set getSkipHours() {
228: return this .mySkipHours;
229: }
230:
231: public void setSkipHours(Set skipHours) {
232: this .mySkipHours = skipHours;
233: }
234:
235: public String getTitle() {
236: return this .myTitle;
237: }
238:
239: public void setTitle(String title) {
240: this .myTitle = title;
241: }
242:
243: public int getTtl() {
244: return this .myTtl;
245: }
246:
247: public void setTtl(int ttl) {
248: this .myTtl = ttl;
249: }
250:
251: public String getWebmaster() {
252: return this .myWebmaster;
253: }
254:
255: public void setWebmaster(String webmaster) {
256: this .myWebmaster = webmaster;
257: }
258:
259: public RssTextInput getTextInput() {
260: return this .myTextInput;
261: }
262:
263: public void setTextInput(RssTextInput textInput) {
264: this .myTextInput = textInput;
265: }
266:
267: /**
268: * Sets whether the data in the current channel has already been loaded
269: */
270: public void setDataLoaded(boolean state) {
271: this .stateDataLoaded = state;
272: }
273:
274: /**
275: * Checks whether the data in the current channel has already been loaded
276: */
277: public boolean isDataLoaded() {
278: return this .stateDataLoaded;
279: }
280:
281: /**
282: * Sets whether the loading process failed for the current channel
283: */
284: public void setDataLoadFailed(boolean state) {
285: this .stateDataLoadFailed = state;
286: }
287:
288: /**
289: * Checks whether the loading process failed for the current channel
290: */
291: public boolean isDataLoadFailed() {
292: return this .stateDataLoadFailed;
293: }
294:
295: /**
296: * Sets the receiver from which this channel has been received
297: */
298: public void setClient(RssClient client) {
299: this .myClient = client;
300: }
301:
302: /**
303: * Gets the receiver from which this channel has been received
304: */
305: public RssClient getClient() {
306: return this .myClient;
307: }
308:
309: /**
310: * Sets the time when the channel was updated at last
311: */
312: public void setLastUpdate(long time) {
313: this .myLastUpdate = time;
314: }
315:
316: /**
317: * Gets the time when the channel was updated at last
318: */
319: public long getLastUpdate() {
320: return this .myLastUpdate;
321: }
322:
323: /**
324: * Gets the <code>List</code> in which all the registred
325: * <code>RssChannelUpdateListener</code> objects are stored
326: */
327: protected List getUpdateListenerList() {
328: return this .myUpdateListenerList;
329: }
330:
331: /**
332: * Notifies all listeners, that the current channel has been update
333: */
334: protected void fireChannelUpdate() {
335: for (int i = 0; i < this .getUpdateListenerList().size(); i++) {
336: ((RssChannelUpdateListener) this .getUpdateListenerList()
337: .get(i)).channelUpdated(this );
338: }
339: }
340:
341: /**
342: * Adds the listener
343: */
344: public void addUpdateListener(RssChannelUpdateListener listener) {
345: this .getUpdateListenerList().add(listener);
346: }
347:
348: /**
349: * Removes the listener
350: */
351: public void removeUpdateListener(RssChannelUpdateListener listener) {
352: this.getUpdateListenerList().remove(listener);
353: }
354:
355: }
|