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.impl.ObjectBean;
20  import com.sun.syndication.feed.module.Module;
21  import com.sun.syndication.feed.module.impl.ModuleUtils;
22  import com.sun.syndication.feed.module.Extendable;
23  
24  import java.util.ArrayList;
25  import java.util.Date;
26  import java.util.List;
27  import java.io.Serializable;
28  
29  /**
30   * Bean for items of RSS feeds.
31   * <p>
32   * It handles all RSS versions without loosing information.
33   * <p>
34   * For RSS1.0 it supports Dublin Core and Syndication modules. Note that
35   * those modules currently support simple syntax format only.
36   * <p>
37   * @author Alejandro Abdelnur
38   *
39   */
40  public class Item implements Cloneable, Serializable, Extendable {
41      private ObjectBean _objBean;
42      private String _title;
43      private String _link;
44      private String _uri;
45      private Description _description;
46      private Content _content;
47      private Source _source;
48      private List _enclosures;
49      private List _categories;
50      private Guid _guid;
51      private String _comments;
52      private String _author;
53      private Date _pubDate;
54      private Date _expirationDate;
55      private List _modules;
56      private List _foreignMarkup;
57  
58      /**
59       * Default constructor. All properties are set to <b>null</b>.
60       * <p>
61       *
62       */
63      public Item() {
64          _objBean = new ObjectBean(this.getClass(),this);
65      }
66  
67      /**
68       * Creates a deep 'bean' clone of the object.
69       * <p>
70       * @return a clone of the object.
71       * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
72       *
73       */
74      public Object clone() throws CloneNotSupportedException {
75          return _objBean.clone();
76      }
77  
78      /**
79       * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
80       * <p>
81       * @param other he reference object with which to compare.
82       * @return <b>true</b> if 'this' object is equal to the 'other' object.
83       *
84       */
85      public boolean equals(Object other) {
86          // can't use foreign markup in equals, due to JDOM equals impl
87          Object fm = getForeignMarkup();
88          setForeignMarkup(((Item)other).getForeignMarkup());       
89          boolean ret = _objBean.equals(other);
90          // restore foreign markup
91          setForeignMarkup(fm);
92          return ret;
93      }
94  
95      /**
96       * Returns a hashcode value for the object.
97       * <p>
98       * It follows the contract defined by the Object hashCode() method.
99       * <p>
100      * @return the hashcode of the bean object.
101      *
102      */
103     public int hashCode() {
104         return _objBean.hashCode();
105     }
106 
107     /**
108      * Returns the String representation for the object.
109      * <p>
110      * @return String representation for the object.
111      *
112      */
113     public String toString() {
114         return _objBean.toString();
115     }
116 
117     /**
118      * Returns the item title.
119      * <p>
120      * @return the item title, <b>null</b> if none.
121      *
122      */
123     public String getTitle() {
124         return _title;
125     }
126 
127     /**
128      * Sets the item title.
129      * <p>
130      * @param title the item title to set, <b>null</b> if none.
131      *
132      */
133     public void setTitle(String title) {
134         _title = title;
135     }
136 
137     /**
138      * Returns the item link.
139      * <p>
140      * @return the item link, <b>null</b> if none.
141      *
142      */
143     public String getLink() {
144         return _link;
145     }
146 
147     /**
148      * Sets the item link.
149      * <p>
150      * @param link the item link to set, <b>null</b> if none.
151      *
152      */
153     public void setLink(String link) {
154         _link = link;
155     }
156 
157     /**
158      * Returns the item uri.
159      * <p>
160      * @return the item uri, <b>null</b> if none.
161      */
162     public String getUri() {
163         return _uri;
164     }
165 
166     /**
167      * Sets the item uri.
168      * <p>
169      * @param uri the item uri to set, <b>null</b> if none.
170      */
171     public void setUri(String uri) {
172         _uri = uri;
173     }
174 
175     /**
176      * Returns the item description.
177      * <p>
178      * @return the item description, <b>null</b> if none.
179      *
180      */
181     public Description getDescription() {
182         return _description;
183     }
184 
185     /**
186      * Sets the item description.
187      * <p>
188      * @param description the item description to set, <b>null</b> if none.
189      *
190      */
191     public void setDescription(Description description) {
192         _description = description;
193     }
194 
195     /**
196      * Returns the item content.
197      * <p>
198      * @return the item content, <b>null</b> if none.
199      *
200      */
201     public Content getContent() {
202         return _content;
203     }
204 
205     /**
206      * Sets the item content.
207      * <p>
208      * @param content the item content to set, <b>null</b> if none.
209      *
210      */
211     public void setContent(Content content) {
212         _content = content;
213     }
214 
215     /**
216      * Returns the item source.
217      * <p>
218      * @return the item source, <b>null</b> if none.
219      *
220      */
221     public Source getSource() {
222         return _source;
223     }
224 
225     /**
226      * Sets the item source.
227      * <p>
228      * @param source the item source to set, <b>null</b> if none.
229      *
230      */
231     public void setSource(Source source) {
232         _source = source;
233     }
234 
235     /**
236      * Returns the item enclosures.
237      * <p>
238      * @return a list of Enclosure elements with the item enclosures,
239      *         an empty list if none.
240      *
241      */
242     public List getEnclosures() {
243         return (_enclosures==null) ? (_enclosures=new ArrayList()) : _enclosures;
244     }
245 
246     /**
247      * Sets the item enclosures.
248      * <p>
249      * @param enclosures the list of Enclosure elements with the item enclosures to set,
250      *        an empty list or <b>null</b> if none.
251      *
252      */
253     public void setEnclosures(List enclosures) {
254         _enclosures = enclosures;
255     }
256 
257     /**
258      * Returns the item categories.
259      * <p>
260      * @return a list of Category elements with the item categories,
261      *         an empty list if none.
262      *
263      */
264     public List getCategories() {
265         return (_categories==null) ? (_categories=new ArrayList()) : _categories;
266     }
267 
268     /**
269      * Sets the item categories.
270      * <p>
271      * @param categories the list of Categories elements with the item categories to set,
272      *        an empty list or <b>null</b> if none.
273      *
274      */
275     public void setCategories(List categories) {
276         _categories = categories;
277     }
278 
279     /**
280      * Returns the item GUID.
281      * <p>
282      * @return the item GUID, <b>null</b> if none.
283      *
284      */
285     public Guid getGuid() {
286         return _guid;
287     }
288 
289     /**
290      * Sets the item GUID.
291      * <p>
292      * @param guid the item GUID to set, <b>null</b> if none.
293      *
294      */
295     public void setGuid(Guid guid) {
296         _guid = guid;
297     }
298 
299     /**
300      * Returns the item comments.
301      * <p>
302      * @return the item comments, <b>null</b> if none.
303      *
304      */
305     public String getComments() {
306         return _comments;
307     }
308 
309     /**
310      * Sets the item comments.
311      * <p>
312      * @param comments the item comments to set, <b>null</b> if none.
313      *
314      */
315     public void setComments(String comments) {
316         _comments = comments;
317     }
318 
319     /**
320      * Returns the item author.
321      * <p>
322      * @return the item author, <b>null</b> if none.
323      *
324      */
325     public String getAuthor() {
326         return _author;
327     }
328 
329     /**
330      * Sets the item author.
331      * <p>
332      * @param author the item author to set, <b>null</b> if none.
333      *
334      */
335     public void setAuthor(String author) {
336         _author = author;
337     }
338 
339     /**
340      * Returns the item modules.
341      * <p>
342      * @return a list of ModuleImpl elements with the item modules,
343      *         an empty list if none.
344      *
345      */
346     public List getModules() {
347         return (_modules==null) ? (_modules=new ArrayList()) : _modules;
348     }
349 
350     /**
351      * Sets the item modules.
352      * <p>
353      * @param modules the list of ModuleImpl elements with the item modules to set,
354      *        an empty list or <b>null</b> if none.
355      *
356      */
357     public void setModules(List modules) {
358         _modules = modules;
359     }
360 
361     /**
362      * Returns the module identified by a given URI.
363      * <p>
364      * @param uri the URI of the ModuleImpl.
365      * @return The module with the given URI, <b>null</b> if none.
366      */
367     public Module getModule(String uri) {
368         return ModuleUtils.getModule(_modules,uri);
369     }
370 
371 
372     /**
373      * Returns the item publishing date.
374      * <p>
375      * @return the item publishing date, <b>null</b> if none.
376      *
377      */
378     public Date getPubDate() {
379         return _pubDate;
380     }
381 
382     /**
383      * Sets the item publishing date.
384      * <p>
385      * @param pubDate the item publishing date to set, <b>null</b> if none.
386      *
387      */
388     public void setPubDate(Date pubDate) {
389         _pubDate = pubDate;
390     }
391 
392     /**
393      * Returns the item expiration date.
394      * <p>
395      * @return the item expiration date, <b>null</b> if none.
396      *
397      */
398     public Date getExpirationDate() {
399         return _expirationDate;
400     }
401 
402     /**
403      * Sets the item expiration date.
404      * <p>
405      * @param expirationDate the item expiration date to set, <b>null</b> if none.
406      *
407      */
408     public void setExpirationDate(Date expirationDate) {
409         _expirationDate = expirationDate;
410     }
411 
412     /**
413      * Returns foreign markup found at item level.
414      * <p>
415      * @return Opaque object to discourage use
416      *
417      */
418     public Object getForeignMarkup() {
419         return (_foreignMarkup==null) ? (_foreignMarkup=new ArrayList()) : _foreignMarkup;
420     }
421 
422     /**
423      * Sets foreign markup found at item level.
424      * <p>
425      * @param foreignMarkup Opaque object to discourage use
426      *
427      */
428     public void setForeignMarkup(Object foreignMarkup) {
429         _foreignMarkup = (List)foreignMarkup;
430     }
431 
432 }