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          if (other == null) {
87              return false;
88          }
89          // can't use foreign markup in equals, due to JDOM equals impl
90          Object fm = getForeignMarkup();
91          setForeignMarkup(((Item)other).getForeignMarkup());       
92          boolean ret = _objBean.equals(other);
93          // restore foreign markup
94          setForeignMarkup(fm);
95          return ret;
96      }
97  
98      /***
99       * Returns a hashcode value for the object.
100      * <p>
101      * It follows the contract defined by the Object hashCode() method.
102      * <p>
103      * @return the hashcode of the bean object.
104      *
105      */
106     public int hashCode() {
107         return _objBean.hashCode();
108     }
109 
110     /***
111      * Returns the String representation for the object.
112      * <p>
113      * @return String representation for the object.
114      *
115      */
116     public String toString() {
117         return _objBean.toString();
118     }
119 
120     /***
121      * Returns the item title.
122      * <p>
123      * @return the item title, <b>null</b> if none.
124      *
125      */
126     public String getTitle() {
127         return _title;
128     }
129 
130     /***
131      * Sets the item title.
132      * <p>
133      * @param title the item title to set, <b>null</b> if none.
134      *
135      */
136     public void setTitle(String title) {
137         _title = title;
138     }
139 
140     /***
141      * Returns the item link.
142      * <p>
143      * @return the item link, <b>null</b> if none.
144      *
145      */
146     public String getLink() {
147         return _link;
148     }
149 
150     /***
151      * Sets the item link.
152      * <p>
153      * @param link the item link to set, <b>null</b> if none.
154      *
155      */
156     public void setLink(String link) {
157         _link = link;
158     }
159 
160     /***
161      * Returns the item uri.
162      * <p>
163      * @return the item uri, <b>null</b> if none.
164      */
165     public String getUri() {
166         return _uri;
167     }
168 
169     /***
170      * Sets the item uri.
171      * <p>
172      * @param uri the item uri to set, <b>null</b> if none.
173      */
174     public void setUri(String uri) {
175         _uri = uri;
176     }
177 
178     /***
179      * Returns the item description.
180      * <p>
181      * @return the item description, <b>null</b> if none.
182      *
183      */
184     public Description getDescription() {
185         return _description;
186     }
187 
188     /***
189      * Sets the item description.
190      * <p>
191      * @param description the item description to set, <b>null</b> if none.
192      *
193      */
194     public void setDescription(Description description) {
195         _description = description;
196     }
197 
198     /***
199      * Returns the item content.
200      * <p>
201      * @return the item content, <b>null</b> if none.
202      *
203      */
204     public Content getContent() {
205         return _content;
206     }
207 
208     /***
209      * Sets the item content.
210      * <p>
211      * @param content the item content to set, <b>null</b> if none.
212      *
213      */
214     public void setContent(Content content) {
215         _content = content;
216     }
217 
218     /***
219      * Returns the item source.
220      * <p>
221      * @return the item source, <b>null</b> if none.
222      *
223      */
224     public Source getSource() {
225         return _source;
226     }
227 
228     /***
229      * Sets the item source.
230      * <p>
231      * @param source the item source to set, <b>null</b> if none.
232      *
233      */
234     public void setSource(Source source) {
235         _source = source;
236     }
237 
238     /***
239      * Returns the item enclosures.
240      * <p>
241      * @return a list of Enclosure elements with the item enclosures,
242      *         an empty list if none.
243      *
244      */
245     public List getEnclosures() {
246         return (_enclosures==null) ? (_enclosures=new ArrayList()) : _enclosures;
247     }
248 
249     /***
250      * Sets the item enclosures.
251      * <p>
252      * @param enclosures the list of Enclosure elements with the item enclosures to set,
253      *        an empty list or <b>null</b> if none.
254      *
255      */
256     public void setEnclosures(List enclosures) {
257         _enclosures = enclosures;
258     }
259 
260     /***
261      * Returns the item categories.
262      * <p>
263      * @return a list of Category elements with the item categories,
264      *         an empty list if none.
265      *
266      */
267     public List getCategories() {
268         return (_categories==null) ? (_categories=new ArrayList()) : _categories;
269     }
270 
271     /***
272      * Sets the item categories.
273      * <p>
274      * @param categories the list of Categories elements with the item categories to set,
275      *        an empty list or <b>null</b> if none.
276      *
277      */
278     public void setCategories(List categories) {
279         _categories = categories;
280     }
281 
282     /***
283      * Returns the item GUID.
284      * <p>
285      * @return the item GUID, <b>null</b> if none.
286      *
287      */
288     public Guid getGuid() {
289         return _guid;
290     }
291 
292     /***
293      * Sets the item GUID.
294      * <p>
295      * @param guid the item GUID to set, <b>null</b> if none.
296      *
297      */
298     public void setGuid(Guid guid) {
299         _guid = guid;
300     }
301 
302     /***
303      * Returns the item comments.
304      * <p>
305      * @return the item comments, <b>null</b> if none.
306      *
307      */
308     public String getComments() {
309         return _comments;
310     }
311 
312     /***
313      * Sets the item comments.
314      * <p>
315      * @param comments the item comments to set, <b>null</b> if none.
316      *
317      */
318     public void setComments(String comments) {
319         _comments = comments;
320     }
321 
322     /***
323      * Returns the item author.
324      * <p>
325      * @return the item author, <b>null</b> if none.
326      *
327      */
328     public String getAuthor() {
329         return _author;
330     }
331 
332     /***
333      * Sets the item author.
334      * <p>
335      * @param author the item author to set, <b>null</b> if none.
336      *
337      */
338     public void setAuthor(String author) {
339         _author = author;
340     }
341 
342     /***
343      * Returns the item modules.
344      * <p>
345      * @return a list of ModuleImpl elements with the item modules,
346      *         an empty list if none.
347      *
348      */
349     public List getModules() {
350         return (_modules==null) ? (_modules=new ArrayList()) : _modules;
351     }
352 
353     /***
354      * Sets the item modules.
355      * <p>
356      * @param modules the list of ModuleImpl elements with the item modules to set,
357      *        an empty list or <b>null</b> if none.
358      *
359      */
360     public void setModules(List modules) {
361         _modules = modules;
362     }
363 
364     /***
365      * Returns the module identified by a given URI.
366      * <p>
367      * @param uri the URI of the ModuleImpl.
368      * @return The module with the given URI, <b>null</b> if none.
369      */
370     public Module getModule(String uri) {
371         return ModuleUtils.getModule(_modules,uri);
372     }
373 
374 
375     /***
376      * Returns the item publishing date.
377      * <p>
378      * @return the item publishing date, <b>null</b> if none.
379      *
380      */
381     public Date getPubDate() {
382         return _pubDate;
383     }
384 
385     /***
386      * Sets the item publishing date.
387      * <p>
388      * @param pubDate the item publishing date to set, <b>null</b> if none.
389      *
390      */
391     public void setPubDate(Date pubDate) {
392         _pubDate = pubDate;
393     }
394 
395     /***
396      * Returns the item expiration date.
397      * <p>
398      * @return the item expiration date, <b>null</b> if none.
399      *
400      */
401     public Date getExpirationDate() {
402         return _expirationDate;
403     }
404 
405     /***
406      * Sets the item expiration date.
407      * <p>
408      * @param expirationDate the item expiration date to set, <b>null</b> if none.
409      *
410      */
411     public void setExpirationDate(Date expirationDate) {
412         _expirationDate = expirationDate;
413     }
414 
415     /***
416      * Returns foreign markup found at item level.
417      * <p>
418      * @return Opaque object to discourage use
419      *
420      */
421     public Object getForeignMarkup() {
422         return (_foreignMarkup==null) ? (_foreignMarkup=new ArrayList()) : _foreignMarkup;
423     }
424 
425     /***
426      * Sets foreign markup found at item level.
427      * <p>
428      * @param foreignMarkup Opaque object to discourage use
429      *
430      */
431     public void setForeignMarkup(Object foreignMarkup) {
432         _foreignMarkup = (List)foreignMarkup;
433     }
434 
435 }