KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > syndication > feed > rss > Channel


1 /*
2  * Copyright 2004 Sun Microsystems, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package com.sun.syndication.feed.rss;
18
19 import com.sun.syndication.feed.WireFeed;
20 import com.sun.syndication.feed.module.Module;
21 import com.sun.syndication.feed.module.impl.ModuleUtils;
22
23 import java.util.*;
24
25 /**
26  * Bean for RSS feeds.
27  * <p>
28  * It handles all RSS versions (0.9, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0)
29  * without loosing information.
30  * <p>
31  * @author Alejandro Abdelnur
32  *
33  */

34 public class Channel extends WireFeed {
35     public static final String JavaDoc SUNDAY = "sunday";
36     public static final String JavaDoc MONDAY = "monday";
37     public static final String JavaDoc TUESDAY = "tuesday";
38     public static final String JavaDoc WEDNESDAY = "wednesday";
39     public static final String JavaDoc THURSDAY = "thursday";
40     public static final String JavaDoc FRIDAY = "friday";
41     public static final String JavaDoc SATURDAY = "saturday";
42
43     private static final Set DAYS = new HashSet();
44
45     static {
46         DAYS.add(SUNDAY );
47         DAYS.add(MONDAY );
48         DAYS.add(TUESDAY );
49         DAYS.add(WEDNESDAY);
50         DAYS.add(THURSDAY );
51         DAYS.add(FRIDAY );
52         DAYS.add(SATURDAY );
53     }
54
55     private String JavaDoc _title;
56     private String JavaDoc _description;
57     private String JavaDoc _link;
58     private String JavaDoc _uri;
59     private Image _image;
60     private List _items;
61     private TextInput _textInput;
62     private String JavaDoc _language;
63     private String JavaDoc _rating;
64     private String JavaDoc _copyright;
65     private Date _pubDate;
66     private Date _lastBuildDate;
67     private String JavaDoc _docs;
68     private String JavaDoc _managingEditor;
69     private String JavaDoc _webMaster;
70     private List _skipHours;
71     private List _skipDays;
72     private Cloud _cloud;
73     private List _categories;
74     private String JavaDoc _generator;
75     private int _ttl = -1;
76     private List _modules;
77
78     /**
79      * Default constructor, for bean cloning purposes only.
80      *
81      */

82     public Channel() {
83     }
84
85     /**
86      * Channel Constructor. All properties, except the type, are set to <b>null</b>.
87      * <p>
88      * @param type the type of the RSS feed.
89      *
90      */

91     public Channel(String JavaDoc type) {
92         super(type);
93     }
94
95     /**
96      * Returns the channel title.
97      * <p>
98      * @return the channel title, <b>null</b> if none.
99      *
100      */

101     public String JavaDoc getTitle() {
102         return _title;
103     }
104
105     /**
106      * Sets the channel title.
107      * <p>
108      * @param title the channel title to set, <b>null</b> if none.
109      *
110      */

111     public void setTitle(String JavaDoc title) {
112         _title = title;
113     }
114
115     /**
116      * Returns the channel description.
117      * <p>
118      * @return the channel description, <b>null</b> if none.
119      *
120      */

121     public String JavaDoc getDescription() {
122         return _description;
123     }
124
125     /**
126      * Sets the channel description.
127      * <p>
128      * @param description the channel description to set, <b>null</b> if none.
129      *
130      */

131     public void setDescription(String JavaDoc description) {
132         _description = description;
133     }
134
135     /**
136      * Returns the channel link.
137      * <p>
138      * @return the channel link, <b>null</b> if none.
139      *
140      */

141     public String JavaDoc getLink() {
142         return _link;
143     }
144
145     /**
146      * Sets the channel link.
147      * <p>
148      * @param link the channel link to set, <b>null</b> if none.
149      *
150      */

151     public void setLink(String JavaDoc link) {
152         _link = link;
153     }
154
155     /**
156      * Returns the channel uri.
157      * <p>
158      * @return the channel uri, <b>null</b> if none.
159      */

160     public String JavaDoc getUri() {
161         return _uri;
162     }
163
164     /**
165      * Sets the channel uri.
166      * <p>
167      * @param uri the channel uri, <b>null</b> if none.
168      */

169     public void setUri(String JavaDoc uri) {
170         _uri = uri;
171     }
172
173     /**
174      * Returns the channel image.
175      * <p>
176      * @return the channel image, <b>null</b> if none.
177      *
178      */

179     public Image getImage() {
180         return _image;
181     }
182
183     /**
184      * Sets the channel image.
185      * <p>
186      * @param image the channel image to set, <b>null</b> if none.
187      *
188      */

189     public void setImage(Image image) {
190         _image = image;
191     }
192
193     /**
194      * Returns the channel items.
195      * <p>
196      * @return a list of Item elements with the channel items,
197      * an empty list if none.
198      *
199      */

200     public List getItems() {
201         return (_items==null) ? (_items=new ArrayList()) : _items;
202     }
203
204     /**
205      * Sets the channel items.
206      * <p>
207      * @param items the list of Item elements with the channel items to set,
208      * an empty list or <b>null</b> if none.
209      *
210      */

211     public void setItems(List items) {
212         _items = items;
213     }
214
215     /**
216      * Returns the channel text input.
217      * <p>
218      * @return the channel text input, <b>null</b> if none.
219      *
220      */

221     public TextInput getTextInput() {
222         return _textInput;
223     }
224
225     /**
226      * Sets the channel text input.
227      * <p>
228      * @param textInput the channel text input to set, <b>null</b> if none.
229      *
230      */

231     public void setTextInput(TextInput textInput) {
232         _textInput = textInput;
233     }
234
235     /**
236      * Returns the channel language.
237      * <p>
238      * @return the channel language, <b>null</b> if none.
239      *
240      */

241     public String JavaDoc getLanguage() {
242         return _language;
243     }
244
245     /**
246      * Sets the channel language.
247      * <p>
248      * @param language the channel language to set, <b>null</b> if none.
249      *
250      */

251     public void setLanguage(String JavaDoc language) {
252         _language = language;
253     }
254
255     /**
256      * Returns the channel rating.
257      * <p>
258      * @return the channel rating, <b>null</b> if none.
259      *
260      */

261     public String JavaDoc getRating() {
262         return _rating;
263     }
264
265     /**
266      * Sets the channel rating.
267      * <p>
268      * @param rating the channel rating to set, <b>null</b> if none.
269      *
270      */

271     public void setRating(String JavaDoc rating) {
272         _rating = rating;
273     }
274
275     /**
276      * Returns the channel copyright.
277      * <p>
278      * @return the channel copyright, <b>null</b> if none.
279      *
280      */

281     public String JavaDoc getCopyright() {
282         return _copyright;
283     }
284
285     /**
286      * Sets the channel copyright.
287      * <p>
288      * @param copyright the channel copyright to set, <b>null</b> if none.
289      *
290      */

291     public void setCopyright(String JavaDoc copyright) {
292         _copyright = copyright;
293     }
294
295     /**
296      * Returns the channel publishing date.
297      * <p>
298      * @return the channel publishing date, <b>null</b> if none.
299      *
300      */

301     public Date getPubDate() {
302         return _pubDate;
303     }
304
305     /**
306      * Sets the channel publishing date.
307      * <p>
308      * @param pubDate the channel publishing date to set, <b>null</b> if none.
309      *
310      */

311     public void setPubDate(Date pubDate) {
312         _pubDate = pubDate;
313     }
314
315     /**
316      * Returns the channel last build date.
317      * <p>
318      * @return the channel last build date, <b>null</b> if none.
319      *
320      */

321     public Date getLastBuildDate() {
322         return _lastBuildDate;
323     }
324
325     /**
326      * Sets the channel last build date.
327      * <p>
328      * @param lastBuildDate the channel last build date to set, <b>null</b> if none.
329      *
330      */

331     public void setLastBuildDate(Date lastBuildDate) {
332         _lastBuildDate = lastBuildDate;
333     }
334
335     /**
336      * Returns the channel docs.
337      * <p>
338      * @return the channel docs, <b>null</b> if none.
339      *
340      */

341     public String JavaDoc getDocs() {
342         return _docs;
343     }
344
345     /**
346      * Sets the channel docs.
347      * <p>
348      * @param docs the channel docs to set, <b>null</b> if none.
349      *
350      */

351     public void setDocs(String JavaDoc docs) {
352         _docs = docs;
353     }
354
355     /**
356      * Returns the channel managing editor.
357      * <p>
358      * @return the channel managing editor, <b>null</b> if none.
359      *
360      */

361     public String JavaDoc getManagingEditor() {
362         return _managingEditor;
363     }
364
365     /**
366      * Sets the channel managing editor.
367      * <p>
368      * @param managingEditor the channel managing editor to set, <b>null</b> if none.
369      *
370      */

371     public void setManagingEditor(String JavaDoc managingEditor) {
372         _managingEditor = managingEditor;
373     }
374
375     /**
376      * Returns the channel web master.
377      * <p>
378      * @return the channel web master, <b>null</b> if none.
379      *
380      */

381     public String JavaDoc getWebMaster() {
382         return _webMaster;
383     }
384
385     /**
386      * Sets the channel web master.
387      * <p>
388      * @param webMaster the channel web master to set, <b>null</b> if none.
389      *
390      */

391     public void setWebMaster(String JavaDoc webMaster) {
392         _webMaster = webMaster;
393     }
394
395     /**
396      * Returns the channel skip hours.
397      * <p>
398      * @return a list of Integer elements with the channel skip hours,
399      * an empty list if none.
400      *
401      */

402     public List getSkipHours() {
403         return (_skipHours!=null) ? _skipHours : new ArrayList();
404     }
405
406     /**
407      * Sets the channel skip hours.
408      * <p>
409      * @param skipHours the list of Integer elements with the channel skip hours to set,
410      * an empty list or <b>null</b> if none.
411      *
412      */

413     public void setSkipHours(List skipHours) {
414         if (skipHours!=null) {
415             for (int i=0;i<skipHours.size();i++) {
416                 Integer JavaDoc iHour = (Integer JavaDoc) skipHours.get(i);
417                 if (iHour!=null) {
418                     int hour = iHour.intValue();
419                     if (hour<0 || hour>24) {
420                         throw new IllegalArgumentException JavaDoc("Invalid hour ["+hour+"]");
421                     }
422                 }
423                 else {
424                     throw new IllegalArgumentException JavaDoc("Invalid hour [null]");
425                 }
426             }
427         }
428         _skipHours = skipHours;
429     }
430
431     /**
432      * Returns the channel skip days.
433      * <p>
434      * @return a list of Day elements with the channel skip days,
435      * an empty list if none.
436      *
437      */

438     public List getSkipDays() {
439         return (_skipDays!=null) ? _skipDays : new ArrayList();
440     }
441
442     /**
443      * Sets the channel skip days.
444      * <p>
445      * @param skipDays the list of Day elements with the channel skip days to set,
446      * an empty list or <b>null</b> if none.
447      *
448      */

449     public void setSkipDays(List skipDays) {
450         if (skipDays!=null) {
451             for (int i=0;i<skipDays.size();i++) {
452                 String JavaDoc day = (String JavaDoc) skipDays.get(i);
453                 if (day!=null) {
454                     day = day.toLowerCase();
455                     if (!DAYS.contains(day)) {
456                         throw new IllegalArgumentException JavaDoc("Invalid day ["+day+"]");
457                     }
458                     skipDays.set(i,day);
459                 }
460                 else {
461                     throw new IllegalArgumentException JavaDoc("Invalid day [null]");
462                 }
463             }
464         }
465         _skipDays = skipDays;
466     }
467
468     /**
469      * Returns the channel cloud.
470      * <p>
471      * @return the channel cloud, <b>null</b> if none.
472      *
473      */

474     public Cloud getCloud() {
475         return _cloud;
476     }
477
478     /**
479      * Sets the channel cloud.
480      * <p>
481      * @param cloud the channel cloud to set, <b>null</b> if none.
482      *
483      */

484     public void setCloud(Cloud cloud) {
485         _cloud = cloud;
486     }
487
488     /**
489      * Returns the channel categories.
490      * <p>
491      * @return a list of Category elements with the channel categories,
492      * an empty list if none.
493      *
494      */

495     public List getCategories() {
496         return (_categories==null) ? (_categories=new ArrayList()) : _categories;
497     }
498
499     /**
500      * Sets the channel categories.
501      * <p>
502      * @param categories the list of Category elements with the channel categories to set,
503      * an empty list or <b>null</b> if none.
504      *
505      */

506     public void setCategories(List categories) {
507         _categories = categories;
508     }
509
510     /**
511      * Returns the channel generator.
512      * <p>
513      * @return the channel generator, <b>null</b> if none.
514      *
515      */

516     public String JavaDoc getGenerator() {
517         return _generator;
518     }
519
520     /**
521      * Sets the channel generator.
522      * <p>
523      * @param generator the channel generator to set, <b>null</b> if none.
524      *
525      */

526     public void setGenerator(String JavaDoc generator) {
527         _generator = generator;
528     }
529
530     /**
531      * Returns the channel time to live.
532      * <p>
533      * @return the channel time to live, <b>null</b> if none.
534      *
535      */

536     public int getTtl() {
537         return _ttl;
538     }
539
540     /**
541      * Sets the channel time to live.
542      * <p>
543      * @param ttl the channel time to live to set, <b>null</b> if none.
544      *
545      */

546     public void setTtl(int ttl) {
547         _ttl = ttl;
548     }
549
550     /**
551      * Returns the channel modules.
552      * <p>
553      * @return a list of ModuleImpl elements with the channel modules,
554      * an empty list if none.
555      *
556      */

557     public List getModules() {
558         return (_modules==null) ? (_modules=new ArrayList()) : _modules;
559     }
560
561     /**
562      * Sets the channel modules.
563      * <p>
564      * @param modules the list of ModuleImpl elements with the channel modules to set,
565      * an empty list or <b>null</b> if none.
566      *
567      */

568     public void setModules(List modules) {
569         _modules = modules;
570     }
571
572     /**
573      * Returns the module identified by a given URI.
574      * <p>
575      * @param uri the URI of the ModuleImpl.
576      * @return The module with the given URI, <b>null</b> if none.
577      */

578     public Module getModule(String JavaDoc uri) {
579         return ModuleUtils.getModule(_modules,uri);
580     }
581
582
583 }
584
Popular Tags