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.atom;
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.ArrayList;
24  import java.util.Date;
25  import java.util.List;
26  
27  /***
28   * Bean for Atom feeds.
29   * <p>
30   * It handles Atom feeds version 0.3 without loosing any feed information.
31   * <p>
32   * @author Alejandro Abdelnur
33   * @author Dave Johnson (updated for Atom 1.0)
34   */
35  public class Feed extends WireFeed {
36      
37      private String    _xmlBase;
38      private List      _categories;    
39      private List      _authors; 
40      private List      _contributors;
41      private Generator _generator;
42      private String    _icon;       
43      private String    _id;
44      private String    _logo;
45      private String    _rights;         // AKA copyright
46      private Content   _subtitle;       // AKA tagline   
47      private Content   _title;
48      private Date      _updated;        // AKA modified
49      private List      _alternateLinks; 
50      private List      _otherLinks;    
51      private List      _entries;
52      
53      private List      _modules;
54     
55      private Content   _info;           // Atom 0.3 only
56      private String    _language;       // Atom 0.3 only
57  
58      /***
59       * Default constructor, for bean cloning purposes only.
60       *
61       */
62      public Feed() {
63      }
64  
65      /***
66       * Feed Constructor. All properties, except the type, are set to <b>null</b>.
67       * <p>
68       * @param type the type of the Atom feed.
69       *
70       */
71      public Feed(String type) {
72          super(type);
73      }
74  
75      /***
76       * Returns the feed language (Atom 0.3 only)
77       * <p>
78       * @return the feed language, <b>null</b> if none.
79       *
80       */
81      public String getLanguage() {
82          return _language;
83      }
84  
85      /***
86       * Sets the feed language (Atom 0.3 only)
87       * <p>
88       * @param language the feed language to set, <b>null</b> if none.
89       *
90       */
91      public void setLanguage(String language) {
92          _language = language;
93      }
94  
95      /***
96       * Returns the feed title.
97       * <p>
98       * @return the feed title, <b>null</b> if none.
99       *
100      */
101     public String getTitle() {
102         if (_title != null) return _title.getValue();
103         return null;
104     }
105 
106     /***
107      * Sets the feed title.
108      * <p>
109      * @param title the feed title to set, <b>null</b> if none.
110      *
111      */
112     public void setTitle(String title) {
113         if (_title == null) _title = new Content();
114         _title.setValue(title);
115     }
116     
117     /***
118      * Returns the feed title.
119      * <p>
120      * @return the feed title, <b>null</b> if none.
121      *
122      */
123     public Content getTitleEx() {
124         return _title;
125     }
126 
127     /***
128      * Sets the feed title.
129      * <p>
130      * @param title the feed title to set, <b>null</b> if none.
131      *
132      */
133     public void setTitleEx(Content title) {
134         _title = title;
135     }
136 
137     /***
138      * Returns the feed alternate links.
139      * <p>
140      * @return a list of Link elements with the feed alternate links,
141      *         an empty list if none.
142      */
143     public List getAlternateLinks() {
144         return (_alternateLinks==null) ? (_alternateLinks=new ArrayList()) : _alternateLinks;
145     }
146 
147     /***
148      * Sets the feed alternate links.
149      * <p>
150      * @param alternateLinks the list of Link elements with the feed alternate links to set,
151      *        an empty list or <b>null</b> if none.
152      */
153     public void setAlternateLinks(List alternateLinks) {
154         _alternateLinks = alternateLinks;
155     }
156 
157     /***
158      * Returns the feed other links (non-alternate ones).
159      * <p>
160      * @return a list of Link elements with the feed other links (non-alternate ones),
161      *         an empty list if none.
162      */
163     public List getOtherLinks() {
164         return (_otherLinks==null) ? (_otherLinks=new ArrayList()) : _otherLinks;
165     }
166 
167     /***
168      * Sets the feed other links (non-alternate ones).
169      * <p>
170      * @param otherLinks the list of Link elements with the feed other links (non-alternate ones) to set,
171      *        an empty list or <b>null</b> if none.
172      */
173     public void setOtherLinks(List otherLinks) {
174         _otherLinks = otherLinks;
175     }
176 
177     /***
178      * Returns the feed author.
179      * <p>
180      * @return the feed author, <b>null</b> if none.
181      * 
182      */
183     public List getAuthors() {
184         return (_authors==null) ? (_authors=new ArrayList()) : _authors;
185     }
186 
187     /***
188      * Sets the feed author.
189      * <p>
190      * @param author the feed author to set, <b>null</b> if none.
191      * 
192      */
193     public void setAuthors(List authors) {
194         _authors = authors;
195     }
196 
197     /***
198      * Returns the feed contributors.
199      * <p>
200      * @return a list of Person elements with the feed contributors,
201      *         an empty list if none.
202      *
203      */
204     public List getContributors() {
205         return (_contributors==null) ? (_contributors=new ArrayList()) : _contributors;
206     }
207 
208     /***
209      * Sets the feed contributors.
210      * <p>
211      * @param contributors the list of Person elements with the feed contributors to set,
212      *        an empty list or <b>null</b> if none.
213      *
214      */
215     public void setContributors(List contributors) {
216         _contributors = contributors;
217     }
218 
219     /***
220      * Returns the feed tag line (Atom 0.3, maps to {@link getSubtitle()}).
221      * <p>
222      * @return the feed tag line, <b>null</b> if none.
223      */
224     public Content getTagline() {
225         return _subtitle;
226     }
227 
228     /***
229      * Sets the feed tagline (Atom 0.3, maps to {@link getSubtitle()}).
230      * <p>
231      * @param tagline the feed tagline to set, <b>null</b> if none.
232      */
233     public void setTagline(Content tagline) {
234         _subtitle = tagline;
235     }
236 
237     /***
238      * Returns the feed ID.
239      * <p>
240      * @return the feed ID, <b>null</b> if none.
241      *
242      */
243     public String getId() {
244         return _id;
245     }
246 
247     /***
248      * Sets the feed ID.
249      * <p>
250      * @param id the feed ID to set, <b>null</b> if none.
251      *
252      */
253     public void setId(String id) {
254         _id = id;
255     }
256 
257     /***
258      * Returns the feed generator.
259      * <p>
260      * @return the feed generator, <b>null</b> if none.
261      *
262      */
263     public Generator getGenerator() {
264         return _generator;
265     }
266 
267     /***
268      * Sets the feed generator.
269      * <p>
270      * @param generator the feed generator to set, <b>null</b> if none.
271      *
272      */
273     public void setGenerator(Generator generator) {
274         _generator = generator;
275     }
276 
277     /***
278      * Returns the feed copyright (Atom 0.3, maps to {@link getRights()}).
279      * <p>
280      * @return the feed copyright, <b>null</b> if none.
281      */
282     public String getCopyright() {
283         return _rights;
284     }
285 
286     /***
287      * Sets the feed copyright (Atom 0.3, maps to {@link setRights()}).
288      * <p>
289      * @param copyright the feed copyright to set, <b>null</b> if none.
290      */
291     public void setCopyright(String copyright) {
292         _rights = copyright;
293     }
294 
295     /***
296      * Returns the feed info (Atom 0.3 only)
297      * <p>
298      * @return the feed info, <b>null</b> if none.
299      */
300     public Content getInfo() {
301         return _info;
302     }
303 
304     /***
305      * Sets the feed info (Atom 0.3 only)
306      * <p>
307      * @param info the feed info to set, <b>null</b> if none.
308      */
309     public void setInfo(Content info) {
310         _info = info;
311     }
312 
313     /***
314      * Returns the feed modified date (Atom 0.3, maps to {@link getUpdated()}).
315      * <p>
316      * @return the feed modified date, <b>null</b> if none.
317      */
318     public Date getModified() {
319         return _updated;
320     }
321 
322     /***
323      * Sets the feed modified date (Atom 0.3, maps to {@link setUpdated()}).
324      * <p>
325      * @param modified the feed modified date to set, <b>null</b> if none.
326      */
327     public void setModified(Date modified) {
328         _updated = modified;
329     }
330 
331     /***
332      * Returns the feed entries.
333      * <p>
334      * @return a list of Entry elements with the feed entries,
335      *         an empty list if none.
336      *
337      */
338     public List getEntries() {
339         return (_entries==null) ? (_entries=new ArrayList()) : _entries;
340     }
341 
342     /***
343      * Sets the feed entries.
344      * <p>
345      * @param entries the list of Entry elements with the feed entries to set,
346      *        an empty list or <b>null</b> if none.
347      *
348      */
349     public void setEntries(List entries) {
350         _entries = entries;
351     }
352 
353     /***
354      * Returns the feed modules.
355      * <p>
356      * @return a list of ModuleImpl elements with the feed modules,
357      *         an empty list if none.
358      *
359      */
360     public List getModules() {
361         return (_modules==null) ? (_modules=new ArrayList()) : _modules;
362     }
363 
364     /***
365      * Sets the feed moduless.
366      * <p>
367      * @param modules the list of ModuleImpl elements with the feed moduless to set,
368      *        an empty list or <b>null</b> if none.
369      *
370      */
371     public void setModules(List modules) {
372         _modules = modules;
373     }
374 
375     /***
376      * Returns the module identified by a given URI.
377      * <p>
378      * @param uri the URI of the ModuleImpl.
379      * @return The module with the given URI, <b>null</b> if none.
380      */
381     public Module getModule(String uri) {
382         return ModuleUtils.getModule(_modules,uri);
383     }
384 
385     /***
386      * Returns the categories
387      * <p>
388      * @return Returns the categories.
389      * @since Atom 1.0
390      */
391     public List getCategories() {
392         return (_categories==null) ? (_categories=new ArrayList()) : _categories;
393     }
394     
395     /***
396      * Set the categories
397      * <p>
398      * @param categories The categories to set.
399      * @since Atom 1.0
400      */
401     public void setCategories(List categories) {
402         _categories = categories;
403     }
404     
405     /***
406      * Returns the icon
407      * <p>
408      * @return Returns the icon.
409      * @since Atom 1.0
410      */
411     public String getIcon() {
412         return _icon;
413     }
414     
415     /***
416      * Set the icon
417      * <p>
418      * @param icon The icon to set.
419      * @since Atom 1.0
420      */
421     public void setIcon(String icon) {
422         _icon = icon;
423     }
424         
425     /***
426      * Returns the logo
427      * <p>
428      * @return Returns the logo.
429      * @since Atom 1.0
430      */
431     public String getLogo() {
432         return _logo;
433     }
434     
435     /***
436      * Set the logo
437      * <p>
438      * @param logo The logo to set.
439      * @since Atom 1.0
440      */
441     public void setLogo(String logo) {
442         _logo = logo;
443     }
444     
445     /***
446      * Returns the rights
447      * <p>
448      * @return Returns the rights.
449      * @since Atom 1.0
450      */
451     public String getRights() {
452         return _rights;
453     }
454     
455     /***
456      * Set the rights
457      * <p>
458      * @param rights The rights to set.
459      * @since Atom 1.0
460      */
461     public void setRights(String rights) {
462         _rights = rights;
463     }
464     
465     /***
466      * Returns the subtitle
467      * <p>
468      * @return Returns the subtitle.
469      * @since Atom 1.0
470      */ 
471     public Content getSubtitle() {
472         return _subtitle;
473     }
474     
475     /***
476      * Set the subtitle
477      * <p>
478      * @param subtitle The subtitle to set.
479      * @since Atom 1.0
480      */
481     public void setSubtitle(Content subtitle) {
482         _subtitle = subtitle;
483     }
484     
485     /***
486      * Returns the updated
487      * <p>
488      * @return Returns the updated.
489      * @since Atom 1.0
490      */
491     public Date getUpdated() {
492         return _updated;
493     }
494     
495     /***
496      * Set the updated
497      * <p>
498      * @param updated The updated to set.
499      * @since Atom 1.0
500      */
501     public void setUpdated(Date updated) {
502         _updated = updated;
503     }
504 
505     /***
506      * Returns the xmlBase
507      * <p>
508      * @return Returns the xmlBase.
509      * @since Atom 1.0
510      */
511     public String getXmlBase() {
512         return _xmlBase;
513     }
514     
515     /***
516      * Set the xmlBase
517      * <p>
518      * @param xmlBase The xmlBase to set.
519      * @since Atom 1.0
520      */
521     public void setXmlBase(String xmlBase) {
522         _xmlBase = xmlBase;
523     }
524 }
525