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  
23  import java.util.ArrayList;
24  import java.util.Date;
25  import java.util.List;
26  import java.io.Serializable;
27  
28  /***
29   * Bean for items of RSS feeds.
30   * <p>
31   * It handles all RSS versions without loosing information.
32   * <p>
33   * For RSS1.0 it supports Dublin Core and Syndication modules. Note that
34   * those modules currently support simple syntax format only.
35   * <p>
36   * @author Alejandro Abdelnur
37   *
38   */
39  public class Item implements Cloneable,Serializable {
40      private ObjectBean _objBean;
41      private String _title;
42      private String _link;
43      private String _uri;
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 uri.
150      * <p>
151      * @return the item uri, <b>null</b> if none.
152      */
153     public String getUri() {
154         return _uri;
155     }
156 
157     /***
158      * Sets the item uri.
159      * <p>
160      * @param uri the item uri to set, <b>null</b> if none.
161      */
162     public void setUri(String uri) {
163         _uri = uri;
164     }
165 
166     /***
167      * Returns the item description.
168      * <p>
169      * @return the item description, <b>null</b> if none.
170      *
171      */
172     public Description getDescription() {
173         return _description;
174     }
175 
176     /***
177      * Sets the item description.
178      * <p>
179      * @param description the item description to set, <b>null</b> if none.
180      *
181      */
182     public void setDescription(Description description) {
183         _description = description;
184     }
185 
186     /***
187      * Returns the item source.
188      * <p>
189      * @return the item source, <b>null</b> if none.
190      *
191      */
192     public Source getSource() {
193         return _source;
194     }
195 
196     /***
197      * Sets the item source.
198      * <p>
199      * @param source the item source to set, <b>null</b> if none.
200      *
201      */
202     public void setSource(Source source) {
203         _source = source;
204     }
205 
206     /***
207      * Returns the item enclosures.
208      * <p>
209      * @return a list of Enclosure elements with the item enclosures,
210      *         an empty list if none.
211      *
212      */
213     public List getEnclosures() {
214         return (_enclosures==null) ? (_enclosures=new ArrayList()) : _enclosures;
215     }
216 
217     /***
218      * Sets the item enclosures.
219      * <p>
220      * @param enclosures the list of Enclosure elements with the item enclosures to set,
221      *        an empty list or <b>null</b> if none.
222      *
223      */
224     public void setEnclosures(List enclosures) {
225         _enclosures = enclosures;
226     }
227 
228     /***
229      * Returns the item categories.
230      * <p>
231      * @return a list of Category elements with the item categories,
232      *         an empty list if none.
233      *
234      */
235     public List getCategories() {
236         return (_categories==null) ? (_categories=new ArrayList()) : _categories;
237     }
238 
239     /***
240      * Sets the item categories.
241      * <p>
242      * @param categories the list of Categories elements with the item categories to set,
243      *        an empty list or <b>null</b> if none.
244      *
245      */
246     public void setCategories(List categories) {
247         _categories = categories;
248     }
249 
250     /***
251      * Returns the item GUID.
252      * <p>
253      * @return the item GUID, <b>null</b> if none.
254      *
255      */
256     public Guid getGuid() {
257         return _guid;
258     }
259 
260     /***
261      * Sets the item GUID.
262      * <p>
263      * @param guid the item GUID to set, <b>null</b> if none.
264      *
265      */
266     public void setGuid(Guid guid) {
267         _guid = guid;
268     }
269 
270     /***
271      * Returns the item comments.
272      * <p>
273      * @return the item comments, <b>null</b> if none.
274      *
275      */
276     public String getComments() {
277         return _comments;
278     }
279 
280     /***
281      * Sets the item comments.
282      * <p>
283      * @param comments the item comments to set, <b>null</b> if none.
284      *
285      */
286     public void setComments(String comments) {
287         _comments = comments;
288     }
289 
290     /***
291      * Returns the item author.
292      * <p>
293      * @return the item author, <b>null</b> if none.
294      *
295      */
296     public String getAuthor() {
297         return _author;
298     }
299 
300     /***
301      * Sets the item author.
302      * <p>
303      * @param author the item author to set, <b>null</b> if none.
304      *
305      */
306     public void setAuthor(String author) {
307         _author = author;
308     }
309 
310     /***
311      * Returns the item modules.
312      * <p>
313      * @return a list of ModuleImpl elements with the item modules,
314      *         an empty list if none.
315      *
316      */
317     public List getModules() {
318         return (_modules==null) ? (_modules=new ArrayList()) : _modules;
319     }
320 
321     /***
322      * Sets the item modules.
323      * <p>
324      * @param modules the list of ModuleImpl elements with the item modules to set,
325      *        an empty list or <b>null</b> if none.
326      *
327      */
328     public void setModules(List modules) {
329         _modules = modules;
330     }
331 
332     /***
333      * Returns the module identified by a given URI.
334      * <p>
335      * @param uri the URI of the ModuleImpl.
336      * @return The module with the given URI, <b>null</b> if none.
337      */
338     public Module getModule(String uri) {
339         return ModuleUtils.getModule(_modules,uri);
340     }
341 
342 
343     /***
344      * Returns the item publishing date.
345      * <p>
346      * @return the item publishing date, <b>null</b> if none.
347      *
348      */
349     public Date getPubDate() {
350         return _pubDate;
351     }
352 
353     /***
354      * Sets the item publishing date.
355      * <p>
356      * @param pubDate the item publishing date to set, <b>null</b> if none.
357      *
358      */
359     public void setPubDate(Date pubDate) {
360         _pubDate = pubDate;
361     }
362 
363     /***
364      * Returns the item expiration date.
365      * <p>
366      * @return the item expiration date, <b>null</b> if none.
367      *
368      */
369     public Date getExpirationDate() {
370         return _expirationDate;
371     }
372 
373     /***
374      * Sets the item expiration date.
375      * <p>
376      * @param expirationDate the item expiration date to set, <b>null</b> if none.
377      *
378      */
379     public void setExpirationDate(Date expirationDate) {
380         _expirationDate = expirationDate;
381     }
382 
383 }