View Javadoc

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 SUNDAY    = "sunday";
36      public static final String MONDAY    = "monday";
37      public static final String TUESDAY   = "tuesday";
38      public static final String WEDNESDAY = "wednesday";
39      public static final String THURSDAY  = "thursday";
40      public static final String FRIDAY    = "friday";
41      public static final String 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 _title;
56      private String _description;
57      private String _link;
58      private Image _image;
59      private List _items;
60      private TextInput _textInput;
61      private String _language;
62      private String _rating;
63      private String _copyright;
64      private Date _pubDate;
65      private Date _lastBuildDate;
66      private String _docs;
67      private String _managingEditor;
68      private String _webMaster;
69      private List _skipHours;
70      private List _skipDays;
71      private Cloud _cloud;
72      private List _categories;
73      private String _generator;
74      private int _ttl = -1;
75      private List _modules;
76  
77      /***
78       * Default constructor, for bean cloning purposes only.
79       *
80       */
81      public Channel() {
82      }
83  
84      /***
85       * Channel Constructor. All properties, except the type, are set to <b>null</b>.
86       * <p>
87       * @param type the type of the RSS feed.
88       *
89       */
90      public Channel(String type) {
91          super(type);
92      }
93  
94      /***
95       * Returns the channel title.
96       * <p>
97       * @return the channel title, <b>null</b> if none.
98       *
99       */
100     public String getTitle() {
101         return _title;
102     }
103 
104     /***
105      * Sets the channel title.
106      * <p>
107      * @param title the channel title to set, <b>null</b> if none.
108      *
109      */
110     public void setTitle(String title) {
111         _title = title;
112     }
113 
114     /***
115      * Returns the channel description.
116      * <p>
117      * @return the channel description, <b>null</b> if none.
118      *
119      */
120     public String getDescription() {
121         return _description;
122     }
123 
124     /***
125      * Sets the channel description.
126      * <p>
127      * @param description the channel description to set, <b>null</b> if none.
128      *
129      */
130     public void setDescription(String description) {
131         _description = description;
132     }
133 
134     /***
135      * Returns the channel link.
136      * <p>
137      * @return the channel link, <b>null</b> if none.
138      *
139      */
140     public String getLink() {
141         return _link;
142     }
143 
144     /***
145      * Sets the channel link.
146      * <p>
147      * @param link the channel link to set, <b>null</b> if none.
148      *
149      */
150     public void setLink(String link) {
151         _link = link;
152     }
153 
154     /***
155      * Returns the channel image.
156      * <p>
157      * @return the channel image, <b>null</b> if none.
158      *
159      */
160     public Image getImage() {
161         return _image;
162     }
163 
164     /***
165      * Sets the channel image.
166      * <p>
167      * @param image the channel image to set, <b>null</b> if none.
168      *
169      */
170     public void setImage(Image image) {
171         _image = image;
172     }
173 
174     /***
175      * Returns the channel items.
176      * <p>
177      * @return a list of Item elements with the channel items,
178      *         an empty list if none.
179      *
180      */
181     public List getItems() {
182         return (_items==null) ? (_items=new ArrayList()) : _items;
183     }
184 
185     /***
186      * Sets the channel items.
187      * <p>
188      * @param items the list of Item elements with the channel items to set,
189      *        an empty list or <b>null</b> if none.
190      *
191      */
192     public void setItems(List items) {
193         _items = items;
194     }
195 
196     /***
197      * Returns the channel text input.
198      * <p>
199      * @return the channel text input, <b>null</b> if none.
200      *
201      */
202     public TextInput getTextInput() {
203         return _textInput;
204     }
205 
206     /***
207      * Sets the channel text input.
208      * <p>
209      * @param textInput the channel text input to set, <b>null</b> if none.
210      *
211      */
212     public void setTextInput(TextInput textInput) {
213         _textInput = textInput;
214     }
215 
216     /***
217      * Returns the channel language.
218      * <p>
219      * @return the channel language, <b>null</b> if none.
220      *
221      */
222     public String getLanguage() {
223         return _language;
224     }
225 
226     /***
227      * Sets the channel language.
228      * <p>
229      * @param language the channel language to set, <b>null</b> if none.
230      *
231      */
232     public void setLanguage(String language) {
233         _language = language;
234     }
235 
236     /***
237      * Returns the channel rating.
238      * <p>
239      * @return the channel rating, <b>null</b> if none.
240      *
241      */
242     public String getRating() {
243         return _rating;
244     }
245 
246     /***
247      * Sets the channel rating.
248      * <p>
249      * @param rating the channel rating to set, <b>null</b> if none.
250      *
251      */
252     public void setRating(String rating) {
253         _rating = rating;
254     }
255 
256     /***
257      * Returns the channel copyright.
258      * <p>
259      * @return the channel copyright, <b>null</b> if none.
260      *
261      */
262     public String getCopyright() {
263         return _copyright;
264     }
265 
266     /***
267      * Sets the channel copyright.
268      * <p>
269      * @param copyright the channel copyright to set, <b>null</b> if none.
270      *
271      */
272     public void setCopyright(String copyright) {
273         _copyright = copyright;
274     }
275 
276     /***
277      * Returns the channel publishing date.
278      * <p>
279      * @return the channel publishing date, <b>null</b> if none.
280      *
281      */
282     public Date getPubDate() {
283         return _pubDate;
284     }
285 
286     /***
287      * Sets the channel publishing date.
288      * <p>
289      * @param pubDate the channel publishing date to set, <b>null</b> if none.
290      *
291      */
292     public void setPubDate(Date pubDate) {
293         _pubDate = pubDate;
294     }
295 
296     /***
297      * Returns the channel last build date.
298      * <p>
299      * @return the channel last build date, <b>null</b> if none.
300      *
301      */
302     public Date getLastBuildDate() {
303         return _lastBuildDate;
304     }
305 
306     /***
307      * Sets the channel last build date.
308      * <p>
309      * @param lastBuildDate the channel last build date to set, <b>null</b> if none.
310      *
311      */
312     public void setLastBuildDate(Date lastBuildDate) {
313         _lastBuildDate = lastBuildDate;
314     }
315 
316     /***
317      * Returns the channel docs.
318      * <p>
319      * @return the channel docs, <b>null</b> if none.
320      *
321      */
322     public String getDocs() {
323         return _docs;
324     }
325 
326     /***
327      * Sets the channel docs.
328      * <p>
329      * @param docs the channel docs to set, <b>null</b> if none.
330      *
331      */
332     public void setDocs(String docs) {
333         _docs = docs;
334     }
335 
336     /***
337      * Returns the channel managing editor.
338      * <p>
339      * @return the channel managing editor, <b>null</b> if none.
340      *
341      */
342     public String getManagingEditor() {
343         return _managingEditor;
344     }
345 
346     /***
347      * Sets the channel managing editor.
348      * <p>
349      * @param managingEditor the channel managing editor to set, <b>null</b> if none.
350      *
351      */
352     public void setManagingEditor(String managingEditor) {
353         _managingEditor = managingEditor;
354     }
355 
356     /***
357      * Returns the channel web master.
358      * <p>
359      * @return the channel web master, <b>null</b> if none.
360      *
361      */
362     public String getWebMaster() {
363         return _webMaster;
364     }
365 
366     /***
367      * Sets the channel web master.
368      * <p>
369      * @param webMaster the channel web master to set, <b>null</b> if none.
370      *
371      */
372     public void setWebMaster(String webMaster) {
373         _webMaster = webMaster;
374     }
375 
376     /***
377      * Returns the channel skip hours.
378      * <p>
379      * @return a list of Integer elements with the channel skip hours,
380      *         an empty list if none.
381      *
382      */
383     public List getSkipHours() {
384         return (_skipHours!=null) ? _skipHours : new ArrayList();
385     }
386 
387     /***
388      * Sets the channel skip hours.
389      * <p>
390      * @param skipHours the list of Integer elements with the channel skip hours to set,
391      *        an empty list or <b>null</b> if none.
392      *
393      */
394     public void setSkipHours(List skipHours) {
395         if (skipHours!=null) {
396             for (int i=0;i<skipHours.size();i++) {
397                 int hour = ((Integer) skipHours.get(i)).intValue();
398                 if (hour<0 || hour>24) {
399                     throw new IllegalArgumentException("Invalid hour ["+hour+"]");
400                 }
401             }
402         }
403         _skipHours = skipHours;
404     }
405 
406     /***
407      * Returns the channel skip days.
408      * <p>
409      * @return a list of Day elements with the channel skip days,
410      *         an empty list if none.
411      *
412      */
413     public List getSkipDays() {
414         return (_skipDays!=null) ? _skipDays : new ArrayList();
415     }
416 
417     /***
418      * Sets the channel skip days.
419      * <p>
420      * @param skipDays the list of Day elements with the channel skip days to set,
421      *        an empty list or <b>null</b> if none.
422      *
423      */
424     public void setSkipDays(List skipDays) {
425         if (skipDays!=null) {
426             for (int i=0;i<skipDays.size();i++) {
427                 if (!DAYS.contains(skipDays.get(i))) {
428                     throw new IllegalArgumentException("Invalid day ["+skipDays.get(i)+"]");
429                 }
430             }
431         }
432         _skipDays = skipDays;
433     }
434 
435     /***
436      * Returns the channel cloud.
437      * <p>
438      * @return the channel cloud, <b>null</b> if none.
439      *
440      */
441     public Cloud getCloud() {
442         return _cloud;
443     }
444 
445     /***
446      * Sets the channel cloud.
447      * <p>
448      * @param cloud the channel cloud to set, <b>null</b> if none.
449      *
450      */
451     public void setCloud(Cloud cloud) {
452         _cloud = cloud;
453     }
454 
455     /***
456      * Returns the channel categories.
457      * <p>
458      * @return a list of Category elements with the channel categories,
459      *         an empty list if none.
460      *
461      */
462     public List getCategories() {
463         return (_categories==null) ? (_categories=new ArrayList()) : _categories;
464     }
465 
466     /***
467      * Sets the channel categories.
468      * <p>
469      * @param categories the list of Category elements with the channel categories to set,
470      *        an empty list or <b>null</b> if none.
471      *
472      */
473     public void setCategories(List categories) {
474         _categories = categories;
475     }
476 
477     /***
478      * Returns the channel generator.
479      * <p>
480      * @return the channel generator, <b>null</b> if none.
481      *
482      */
483     public String getGenerator() {
484         return _generator;
485     }
486 
487     /***
488      * Sets the channel generator.
489      * <p>
490      * @param generator the channel generator to set, <b>null</b> if none.
491      *
492      */
493     public void setGenerator(String generator) {
494         _generator = generator;
495     }
496 
497     /***
498      * Returns the channel time to live.
499      * <p>
500      * @return the channel time to live, <b>null</b> if none.
501      *
502      */
503     public int getTtl() {
504         return _ttl;
505     }
506 
507     /***
508      * Sets the channel time to live.
509      * <p>
510      * @param ttl the channel time to live to set, <b>null</b> if none.
511      *
512      */
513     public void setTtl(int ttl) {
514         _ttl = ttl;
515     }
516 
517     /***
518      * Returns the channel modules.
519      * <p>
520      * @return a list of ModuleImpl elements with the channel modules,
521      *         an empty list if none.
522      *
523      */
524     public List getModules() {
525         return (_modules==null) ? (_modules=new ArrayList()) : _modules;
526     }
527 
528     /***
529      * Sets the channel modules.
530      * <p>
531      * @param modules the list of ModuleImpl elements with the channel modules to set,
532      *        an empty list or <b>null</b> if none.
533      *
534      */
535     public void setModules(List modules) {
536         _modules = modules;
537     }
538 
539     /***
540      * Returns the module identified by a given URI.
541      * <p>
542      * @param uri the URI of the ModuleImpl.
543      * @return The module with the given URI, <b>null</b> if none.
544      */
545     public Module getModule(String uri) {
546         return ModuleUtils.getModule(_modules,uri);
547     }
548 
549 
550 }