001: /*
002: * Copyright 2004 Sun Microsystems, Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: */
017: package com.sun.syndication.feed.rss;
018:
019: import com.sun.syndication.feed.WireFeed;
020: import com.sun.syndication.feed.module.Module;
021: import com.sun.syndication.feed.module.impl.ModuleUtils;
022:
023: import java.util.*;
024:
025: /**
026: * Bean for RSS feeds.
027: * <p>
028: * It handles all RSS versions (0.9, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0)
029: * without losing information.
030: * <p>
031: * @author Alejandro Abdelnur
032: *
033: */
034: public class Channel extends WireFeed {
035: public static final String SUNDAY = "sunday";
036: public static final String MONDAY = "monday";
037: public static final String TUESDAY = "tuesday";
038: public static final String WEDNESDAY = "wednesday";
039: public static final String THURSDAY = "thursday";
040: public static final String FRIDAY = "friday";
041: public static final String SATURDAY = "saturday";
042:
043: private static final Set DAYS = new HashSet();
044:
045: static {
046: DAYS.add(SUNDAY);
047: DAYS.add(MONDAY);
048: DAYS.add(TUESDAY);
049: DAYS.add(WEDNESDAY);
050: DAYS.add(THURSDAY);
051: DAYS.add(FRIDAY);
052: DAYS.add(SATURDAY);
053: }
054:
055: private String _title;
056: private String _description;
057: private String _link;
058: private String _uri;
059: private Image _image;
060: private List _items;
061: private TextInput _textInput;
062: private String _language;
063: private String _rating;
064: private String _copyright;
065: private Date _pubDate;
066: private Date _lastBuildDate;
067: private String _docs;
068: private String _managingEditor;
069: private String _webMaster;
070: private List _skipHours;
071: private List _skipDays;
072: private Cloud _cloud;
073: private List _categories;
074: private String _generator;
075: private int _ttl = -1;
076: private List _modules;
077:
078: /**
079: * Default constructor, for bean cloning purposes only.
080: *
081: */
082: public Channel() {
083: }
084:
085: /**
086: * Channel Constructor. All properties, except the type, are set to <b>null</b>.
087: * <p>
088: * @param type the type of the RSS feed.
089: *
090: */
091: public Channel(String type) {
092: super (type);
093: }
094:
095: /**
096: * Returns the channel title.
097: * <p>
098: * @return the channel title, <b>null</b> if none.
099: *
100: */
101: public String 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 iHour = (Integer) skipHours.get(i);
417: if (iHour != null) {
418: int hour = iHour.intValue();
419: if (hour < 0 || hour > 24) {
420: throw new IllegalArgumentException(
421: "Invalid hour [" + hour + "]");
422: }
423: } else {
424: throw new IllegalArgumentException(
425: "Invalid hour [null]");
426: }
427: }
428: }
429: _skipHours = skipHours;
430: }
431:
432: /**
433: * Returns the channel skip days.
434: * <p>
435: * @return a list of Day elements with the channel skip days,
436: * an empty list if none.
437: *
438: */
439: public List getSkipDays() {
440: return (_skipDays != null) ? _skipDays : new ArrayList();
441: }
442:
443: /**
444: * Sets the channel skip days.
445: * <p>
446: * @param skipDays the list of Day elements with the channel skip days to set,
447: * an empty list or <b>null</b> if none.
448: *
449: */
450: public void setSkipDays(List skipDays) {
451: if (skipDays != null) {
452: for (int i = 0; i < skipDays.size(); i++) {
453: String day = (String) skipDays.get(i);
454: if (day != null) {
455: day = day.toLowerCase();
456: if (!DAYS.contains(day)) {
457: throw new IllegalArgumentException(
458: "Invalid day [" + day + "]");
459: }
460: skipDays.set(i, day);
461: } else {
462: throw new IllegalArgumentException(
463: "Invalid day [null]");
464: }
465: }
466: }
467: _skipDays = skipDays;
468: }
469:
470: /**
471: * Returns the channel cloud.
472: * <p>
473: * @return the channel cloud, <b>null</b> if none.
474: *
475: */
476: public Cloud getCloud() {
477: return _cloud;
478: }
479:
480: /**
481: * Sets the channel cloud.
482: * <p>
483: * @param cloud the channel cloud to set, <b>null</b> if none.
484: *
485: */
486: public void setCloud(Cloud cloud) {
487: _cloud = cloud;
488: }
489:
490: /**
491: * Returns the channel categories.
492: * <p>
493: * @return a list of Category elements with the channel categories,
494: * an empty list if none.
495: *
496: */
497: public List getCategories() {
498: return (_categories == null) ? (_categories = new ArrayList())
499: : _categories;
500: }
501:
502: /**
503: * Sets the channel categories.
504: * <p>
505: * @param categories the list of Category elements with the channel categories to set,
506: * an empty list or <b>null</b> if none.
507: *
508: */
509: public void setCategories(List categories) {
510: _categories = categories;
511: }
512:
513: /**
514: * Returns the channel generator.
515: * <p>
516: * @return the channel generator, <b>null</b> if none.
517: *
518: */
519: public String getGenerator() {
520: return _generator;
521: }
522:
523: /**
524: * Sets the channel generator.
525: * <p>
526: * @param generator the channel generator to set, <b>null</b> if none.
527: *
528: */
529: public void setGenerator(String generator) {
530: _generator = generator;
531: }
532:
533: /**
534: * Returns the channel time to live.
535: * <p>
536: * @return the channel time to live, <b>null</b> if none.
537: *
538: */
539: public int getTtl() {
540: return _ttl;
541: }
542:
543: /**
544: * Sets the channel time to live.
545: * <p>
546: * @param ttl the channel time to live to set, <b>null</b> if none.
547: *
548: */
549: public void setTtl(int ttl) {
550: _ttl = ttl;
551: }
552:
553: /**
554: * Returns the channel modules.
555: * <p>
556: * @return a list of ModuleImpl elements with the channel modules,
557: * an empty list if none.
558: *
559: */
560: public List getModules() {
561: return (_modules == null) ? (_modules = new ArrayList())
562: : _modules;
563: }
564:
565: /**
566: * Sets the channel modules.
567: * <p>
568: * @param modules the list of ModuleImpl elements with the channel modules to set,
569: * an empty list or <b>null</b> if none.
570: *
571: */
572: public void setModules(List modules) {
573: _modules = modules;
574: }
575:
576: /**
577: * Returns the module identified by a given URI.
578: * <p>
579: * @param uri the URI of the ModuleImpl.
580: * @return The module with the given URI, <b>null</b> if none.
581: */
582: public Module getModule(String uri) {
583: return ModuleUtils.getModule(_modules, uri);
584: }
585:
586: }
|