KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jperdian > rss2 > dom > RssChannel


1 /**
2  * RSS framework and reader
3  * Copyright (C) 2004 Christian Robert
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package org.jperdian.rss2.dom;
21
22 import java.io.Serializable JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Date JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Set JavaDoc;
29
30 import org.jperdian.rss2.RssChannelUpdateListener;
31 import org.jperdian.rss2.RssClient;
32 import org.jperdian.rss2.RssException;
33
34 /**
35  * Implementatino of a <tt>channel</tt> element as described in the RSS
36  * specification
37  *
38  * @author Christian Robert
39  */

40
41 public class RssChannel implements Serializable JavaDoc {
42   
43   private transient RssClient myClient = null;
44   private boolean stateDataLoaded = false;
45   private boolean stateDataLoadFailed = false;
46   private long myLastUpdate = -1;
47   
48   private String JavaDoc myTitle = "";
49   private URL JavaDoc myLink = null;
50   private String JavaDoc myDescription = "";
51   private String JavaDoc myLanguage = "";
52   private String JavaDoc myCopyright = "";
53   private String JavaDoc myManagingEditor = "";
54   private String JavaDoc myWebmaster = "";
55   private Date JavaDoc myPubDate = null;
56   private Date JavaDoc myLastBuildDate = null;
57   private List JavaDoc myCategoryList = new ArrayList JavaDoc(1);
58   private String JavaDoc myGenerator = "";
59   private URL JavaDoc myDocs = null;
60   private RssCloud myCloud = null;
61   private int myTtl = RssConstants.DEFAULT_TTL;
62   private RssImage myImage = null;
63   private String JavaDoc myRating = "";
64   private Set JavaDoc mySkipHours = new HashSet JavaDoc();
65   private Set JavaDoc mySkipDays = new HashSet JavaDoc();
66   private List JavaDoc myItemList = new ArrayList JavaDoc();
67   private RssTextInput myTextInput = null;
68   private List JavaDoc myUpdateListenerList = new ArrayList JavaDoc();
69
70   public RssChannel(RssClient client) {
71     this.setClient(client);
72   }
73   
74   public String JavaDoc toString() {
75     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
76     result.append(this.getTitle()).append(" @ ").append(this.getLink());
77     result.append("\n").append(this.getDescription());
78     return result.toString();
79   }
80   
81   /**
82    * Updates the data in the current channel
83    */

84   public void update() throws RssException {
85     this.getClient().loadData(this);
86   }
87   
88   
89   // --------------------------------------------------------------------------
90
// -- Property access methods ---------------------------------------------
91
// --------------------------------------------------------------------------
92

93   public void addCategory(String JavaDoc category) {
94     this.getCategoryList().add(category);
95   }
96
97   public List JavaDoc getCategoryList() {
98     return this.myCategoryList;
99   }
100
101   public void setCategoryList(List JavaDoc categoryList) {
102     this.myCategoryList = categoryList;
103   }
104
105   public RssCloud getCloud() {
106     return this.myCloud;
107   }
108
109   public void setCloud(RssCloud cloud) {
110     this.myCloud = cloud;
111   }
112
113   public String JavaDoc getCopyright() {
114     return this.myCopyright;
115   }
116
117   public void setCopyright(String JavaDoc copyright) {
118     this.myCopyright = copyright;
119   }
120
121   public String JavaDoc getDescription() {
122     return this.myDescription;
123   }
124
125   public void setDescription(String JavaDoc description) {
126     this.myDescription = description;
127   }
128
129   public URL JavaDoc getDocs() {
130     return this.myDocs;
131   }
132
133   public void setDocs(URL JavaDoc docs) {
134     this.myDocs = docs;
135   }
136
137   public String JavaDoc getGenerator() {
138     return this.myGenerator;
139   }
140
141   public void setGenerator(String JavaDoc generator) {
142     this.myGenerator = generator;
143   }
144
145   public RssImage getImage() {
146     return this.myImage;
147   }
148   
149   public void setImage(RssImage image) {
150     this.myImage = image;
151   }
152
153   public void addItem(RssItem item) {
154     this.getItemList().add(item);
155   }
156
157   public List JavaDoc getItemList() {
158     return this.myItemList;
159   }
160
161   public void setItemList(List JavaDoc itemList) {
162     this.myItemList = itemList;
163   }
164
165   public String JavaDoc getLanguage() {
166     return this.myLanguage;
167   }
168
169   public void setLanguage(String JavaDoc language) {
170     this.myLanguage = language;
171   }
172
173   public Date JavaDoc getLastBuildDate() {
174     return this.myLastBuildDate;
175   }
176
177   public void setLastBuildDate(Date JavaDoc lastBuildDate) {
178     this.myLastBuildDate = lastBuildDate;
179   }
180
181   public URL JavaDoc getLink() {
182     return this.myLink;
183   }
184
185   public void setLink(URL JavaDoc link) {
186     this.myLink = link;
187   }
188
189   public String JavaDoc getManagingEditor() {
190     return this.myManagingEditor;
191   }
192
193   public void setManagingEditor(String JavaDoc managingEditor) {
194     this.myManagingEditor = managingEditor;
195   }
196
197   public Date JavaDoc getPubDate() {
198     return this.myPubDate;
199   }
200
201   public void setPubDate(Date JavaDoc pubDate) {
202     this.myPubDate = pubDate;
203   }
204
205   public String JavaDoc getRating() {
206     return this.myRating;
207   }
208
209   public void setRating(String JavaDoc rating) {
210     this.myRating = rating;
211   }
212
213   public void addSkipDay(String JavaDoc day) {
214     this.getSkipDays().add(day);
215   }
216
217   public Set JavaDoc getSkipDays() {
218     return this.mySkipDays;
219   }
220
221   public void setSkipDays(Set JavaDoc skipDays) {
222     this.mySkipDays = skipDays;
223   }
224
225   public void addSkipHour(int hour) {
226     this.getSkipHours().add(new Integer JavaDoc(hour));
227   }
228   
229   public Set JavaDoc getSkipHours() {
230     return this.mySkipHours;
231   }
232
233   public void setSkipHours(Set JavaDoc skipHours) {
234     this.mySkipHours = skipHours;
235   }
236
237   public String JavaDoc getTitle() {
238     return this.myTitle;
239   }
240
241   public void setTitle(String JavaDoc title) {
242     this.myTitle = title;
243   }
244
245   public int getTtl() {
246     return this.myTtl;
247   }
248
249   public void setTtl(int ttl) {
250     this.myTtl = ttl;
251   }
252
253   public String JavaDoc getWebmaster() {
254     return this.myWebmaster;
255   }
256
257   public void setWebmaster(String JavaDoc webmaster) {
258     this.myWebmaster = webmaster;
259   }
260   
261   public RssTextInput getTextInput() {
262     return this.myTextInput;
263   }
264
265   public void setTextInput(RssTextInput textInput) {
266     this.myTextInput = textInput;
267   }
268   
269   /**
270    * Sets whether the data in the current channel has already been loaded
271    */

272   public void setDataLoaded(boolean state) {
273     this.stateDataLoaded = state;
274   }
275   
276   /**
277    * Checks whether the data in the current channel has already been loaded
278    */

279   public boolean isDataLoaded() {
280     return this.stateDataLoaded;
281   }
282   
283   /**
284    * Sets whether the loading process failed for the current channel
285    */

286   public void setDataLoadFailed(boolean state) {
287     this.stateDataLoadFailed = state;
288   }
289   
290   /**
291    * Checks whether the loading process failed for the current channel
292    */

293   public boolean isDataLoadFailed() {
294     return this.stateDataLoadFailed;
295   }
296   
297   /**
298    * Sets the receiver from which this channel has been received
299    */

300   public void setClient(RssClient client) {
301     this.myClient = client;
302   }
303   
304   /**
305    * Gets the receiver from which this channel has been received
306    */

307   public RssClient getClient() {
308     return this.myClient;
309   }
310
311   /**
312    * Sets the time when the channel was updated at last
313    */

314   public void setLastUpdate(long time) {
315     this.myLastUpdate = time;
316   }
317   
318   /**
319    * Gets the time when the channel was updated at last
320    */

321   public long getLastUpdate() {
322     return this.myLastUpdate;
323   }
324
325   /**
326    * Gets the <code>List</code> in which all the registred
327    * <code>RssChannelUpdateListener</code> objects are stored
328    */

329   protected List JavaDoc getUpdateListenerList() {
330     return this.myUpdateListenerList;
331   }
332   
333   /**
334    * Notifies all listeners, that the current channel has been update
335    */

336   protected void fireChannelUpdate() {
337     for(int i=0; i < this.getUpdateListenerList().size(); i++) {
338       ((RssChannelUpdateListener)this.getUpdateListenerList().get(i)).channelUpdated(this);
339     }
340   }
341   
342   /**
343    * Adds the listener
344    */

345   public void addUpdateListener(RssChannelUpdateListener listener) {
346     this.getUpdateListenerList().add(listener);
347   }
348   
349   /**
350    * Removes the listener
351    */

352   public void removeUpdateListener(RssChannelUpdateListener listener) {
353     this.getUpdateListenerList().remove(listener);
354   }
355   
356 }
Popular Tags