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.impl.ObjectBean;
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 {
41      private ObjectBean _objBean;
42      private String _title;
43      private String _link;
44      private Description _description;
45      private Source _source;
46      private List _enclosures;
47      private List _categories;
48      private Guid _guid;
49      private String _comments;
50      private String _author;
51      private Date _pubDate;
52      private Date _expirationDate;
53      private List _modules;
54  
55      /***
56       * Default constructor. All properties are set to <b>null</b>.
57       * <p>
58       *
59       */
60      public Item() {
61          _objBean = new ObjectBean(this.getClass(),this);
62      }
63  
64      /***
65       * Creates a deep 'bean' clone of the object.
66       * <p>
67       * @return a clone of the object.
68       * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
69       *
70       */
71      public Object clone() throws CloneNotSupportedException {
72          return _objBean.clone();
73      }
74  
75      /***
76       * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
77       * <p>
78       * @param other he reference object with which to compare.
79       * @return <b>true</b> if 'this' object is equal to the 'other' object.
80       *
81       */
82      public boolean equals(Object other) {
83          return _objBean.equals(other);
84      }
85  
86      /***
87       * Returns a hashcode value for the object.
88       * <p>
89       * It follows the contract defined by the Object hashCode() method.
90       * <p>
91       * @return the hashcode of the bean object.
92       *
93       */
94      public int hashCode() {
95          return _objBean.hashCode();
96      }
97  
98      /***
99       * Returns the String representation for the object.
100      * <p>
101      * @return String representation for the object.
102      *
103      */
104     public String toString() {
105         return _objBean.toString();
106     }
107 
108     /***
109      * Returns the item title.
110      * <p>
111      * @return the item title, <b>null</b> if none.
112      *
113      */
114     public String getTitle() {
115         return _title;
116     }
117 
118     /***
119      * Sets the item title.
120      * <p>
121      * @param title the item title to set, <b>null</b> if none.
122      *
123      */
124     public void setTitle(String title) {
125         _title = title;
126     }
127 
128     /***
129      * Returns the item link.
130      * <p>
131      * @return the item link, <b>null</b> if none.
132      *
133      */
134     public String getLink() {
135         return _link;
136     }
137 
138     /***
139      * Sets the item link.
140      * <p>
141      * @param link the item link to set, <b>null</b> if none.
142      *
143      */
144     public void setLink(String link) {
145         _link = link;
146     }
147 
148     /***
149      * Returns the item description.
150      * <p>
151      * @return the item description, <b>null</b> if none.
152      *
153      */
154     public Description getDescription() {
155         return _description;
156     }
157 
158     /***
159      * Sets the item description.
160      * <p>
161      * @param description the item description to set, <b>null</b> if none.
162      *
163      */
164     public void setDescription(Description description) {
165         _description = description;
166     }
167 
168     /***
169      * Returns the item source.
170      * <p>
171      * @return the item source, <b>null</b> if none.
172      *
173      */
174     public Source getSource() {
175         return _source;
176     }
177 
178     /***
179      * Sets the item source.
180      * <p>
181      * @param source the item source to set, <b>null</b> if none.
182      *
183      */
184     public void setSource(Source source) {
185         _source = source;
186     }
187 
188     /***
189      * Returns the item enclosures.
190      * <p>
191      * @return a list of Enclosure elements with the item enclosures,
192      *         an empty list if none.
193      *
194      */
195     public List getEnclosures() {
196         return (_enclosures==null) ? (_enclosures=new ArrayList()) : _enclosures;
197     }
198 
199     /***
200      * Sets the item enclosures.
201      * <p>
202      * @param enclosures the list of Enclosure elements with the item enclosures to set,
203      *        an empty list or <b>null</b> if none.
204      *
205      */
206     public void setEnclosures(List enclosures) {
207         _enclosures = enclosures;
208     }
209 
210     /***
211      * Returns the item categories.
212      * <p>
213      * @return a list of Category elements with the item categories,
214      *         an empty list if none.
215      *
216      */
217     public List getCategories() {
218         return (_categories==null) ? (_categories=new ArrayList()) : _categories;
219     }
220 
221     /***
222      * Sets the item categories.
223      * <p>
224      * @param categories the list of Categories elements with the item categories to set,
225      *        an empty list or <b>null</b> if none.
226      *
227      */
228     public void setCategories(List categories) {
229         _categories = categories;
230     }
231 
232     /***
233      * Returns the item GUID.
234      * <p>
235      * @return the item GUID, <b>null</b> if none.
236      *
237      */
238     public Guid getGuid() {
239         return _guid;
240     }
241 
242     /***
243      * Sets the item GUID.
244      * <p>
245      * @param guid the item GUID to set, <b>null</b> if none.
246      *
247      */
248     public void setGuid(Guid guid) {
249         _guid = guid;
250     }
251 
252     /***
253      * Returns the item comments.
254      * <p>
255      * @return the item comments, <b>null</b> if none.
256      *
257      */
258     public String getComments() {
259         return _comments;
260     }
261 
262     /***
263      * Sets the item comments.
264      * <p>
265      * @param comments the item comments to set, <b>null</b> if none.
266      *
267      */
268     public void setComments(String comments) {
269         _comments = comments;
270     }
271 
272     /***
273      * Returns the item author.
274      * <p>
275      * @return the item author, <b>null</b> if none.
276      *
277      */
278     public String getAuthor() {
279         return _author;
280     }
281 
282     /***
283      * Sets the item author.
284      * <p>
285      * @param author the item author to set, <b>null</b> if none.
286      *
287      */
288     public void setAuthor(String author) {
289         _author = author;
290     }
291 
292     /***
293      * Returns the item modules.
294      * <p>
295      * @return a list of ModuleImpl elements with the item modules,
296      *         an empty list if none.
297      *
298      */
299     public List getModules() {
300         return (_modules==null) ? (_modules=new ArrayList()) : _modules;
301     }
302 
303     /***
304      * Sets the item modules.
305      * <p>
306      * @param modules the list of ModuleImpl elements with the item modules to set,
307      *        an empty list or <b>null</b> if none.
308      *
309      */
310     public void setModules(List modules) {
311         _modules = modules;
312     }
313 
314     /***
315      * Returns the module identified by a given URI.
316      * <p>
317      * @param uri the URI of the ModuleImpl.
318      * @return The module with the given URI, <b>null</b> if none.
319      */
320     public Module getModule(String uri) {
321         return ModuleUtils.getModule(_modules,uri);
322     }
323 
324 
325     /***
326      * Returns the item publishing date.
327      * <p>
328      * @return the item publishing date, <b>null</b> if none.
329      *
330      */
331     public Date getPubDate() {
332         return _pubDate;
333     }
334 
335     /***
336      * Sets the item publishing date.
337      * <p>
338      * @param pubDate the item publishing date to set, <b>null</b> if none.
339      *
340      */
341     public void setPubDate(Date pubDate) {
342         _pubDate = pubDate;
343     }
344 
345     /***
346      * Returns the item expiration date.
347      * <p>
348      * @return the item expiration date, <b>null</b> if none.
349      *
350      */
351     public Date getExpirationDate() {
352         return _expirationDate;
353     }
354 
355     /***
356      * Sets the item expiration date.
357      * <p>
358      * @param expirationDate the item expiration date to set, <b>null</b> if none.
359      *
360      */
361     public void setExpirationDate(Date expirationDate) {
362         _expirationDate = expirationDate;
363     }
364 
365 }