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.module.Module;
20  import com.sun.syndication.feed.module.impl.ModuleUtils;
21  import com.sun.syndication.feed.impl.ObjectBean;
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  import java.util.Iterator;
29  
30  /***
31   * Bean for entry elements of Atom feeds.
32   * <p>
33   * @author Alejandro Abdelnur
34   * @author Dave Johnson (updated for Atom 1.0)
35   */
36  public class Entry implements Cloneable, Serializable, Extendable {
37      
38      private ObjectBean _objBean;
39      
40      private String  _xmlBase;
41      private List    _authors;
42      private List    _contributors;
43      private List    _categories;   
44      private List    _contents;       
45      private String  _id;
46      private Date    _published;      // AKA issued  
47      private String  _rights;        
48      private Feed    _source;     
49      private Content _summary;
50      private Content _title;
51      private Date    _updated;        // AKA modified
52      private List    _alternateLinks; 
53      private List    _otherLinks;   
54      private List    _foreignMarkup;
55      
56      private List    _modules;
57      
58      private Date    _created;        // Atom 0.3 only
59  
60  
61      /***
62       * Default constructor. All properties are set to <b>null</b>.
63       * <p>
64       *
65       */
66      public Entry() {
67          _objBean = new ObjectBean(this.getClass(),this);
68      }
69  
70      /***
71       * Creates a deep 'bean' clone of the object.
72       * <p>
73       * @return a clone of the object.
74       * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
75       *
76       */
77      public Object clone() throws CloneNotSupportedException {
78          return _objBean.clone();
79      }
80  
81      /***
82       * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
83       * <p>
84       * @param other he reference object with which to compare.
85       * @return <b>true</b> if 'this' object is equal to the 'other' object.
86       *
87       */
88      public boolean equals(Object other) {
89          if (other == null) {
90              return false;
91          }
92          // can't use foreign markup in equals, due to JDOM equals impl
93          Object fm = getForeignMarkup();
94          setForeignMarkup(((Entry)other).getForeignMarkup());       
95          boolean ret = _objBean.equals(other);
96          // restore foreign markup
97          setForeignMarkup(fm);
98          return ret;
99      }
100 
101     /***
102      * Returns a hashcode value for the object.
103      * <p>
104      * It follows the contract defined by the Object hashCode() method.
105      * <p>
106      * @return the hashcode of the bean object.
107      *
108      */
109     public int hashCode() {
110         return _objBean.hashCode();
111     }
112 
113     /***
114      * Returns the String representation for the object.
115      * <p>
116      * @return String representation for the object.
117      *
118      */
119     public String toString() {
120         return _objBean.toString();
121     }
122 
123     /***
124      * Returns the entry title.
125      * <p>
126      * @return the entry title, <b>null</b> if none.
127      *
128      */
129     public String getTitle() {
130         if (_title != null) return _title.getValue();
131         return null;
132     }
133 
134     /***
135      * Sets the entry title.
136      * <p>
137      * @param title the entry title, <b>null</b> if none.
138      *
139      */
140     public void setTitle(String title) {
141         if (_title == null) _title = new Content();
142         _title.setValue(title);
143     }
144 
145     /***
146      * Returns the entry title as a text construct.
147      * <p>
148      * @return the entry title, <b>null</b> if none.
149      *
150      */
151     public Content getTitleEx() {
152         return _title;
153     }
154 
155     /***
156      * Sets the entry title as a text construct.
157      * <p>
158      * @param title the entry title, <b>null</b> if none.
159      *
160      */
161     public void setTitleEx(Content title) {
162         _title = title;
163     }
164 
165     /***
166      * Returns the entry alternate links.
167      * <p>
168      * @return a list of Link elements with the entry alternate links, an empty list if none.
169      */
170     public List getAlternateLinks() {
171         return (_alternateLinks==null) ? (_alternateLinks=new ArrayList()) : _alternateLinks;
172     }
173 
174     /***
175      * Sets the entry alternate links.
176      * <p>
177      * @param alternateLinks the list of Link elements with the entry alternate links to set,
178      *        an empty list or <b>null</b> if none.
179      */
180     public void setAlternateLinks(List alternateLinks) {
181         _alternateLinks = alternateLinks;
182     }
183 
184     /***
185      * Returns the entry non-alternate links.
186      * <p>
187      * @return the list of Link elements with the entry non-alternate links to set,
188      *         an empty list if none.
189      */
190     public List getOtherLinks() {
191         return (_otherLinks==null) ? (_otherLinks=new ArrayList()) : _otherLinks;
192     }
193 
194     /***
195      * Sets the entry non-alternate links.
196      * <p>
197      * @param otherLinks the list Link elements with the entry non-alternate links to set,
198      *        an empty list or <b>null</b> if none.
199      */
200     public void setOtherLinks(List otherLinks) {
201         _otherLinks = otherLinks;
202     }
203 
204     /***
205      * Returns the entry author.
206      * <p>
207      * @return the entry author, <b>null</b> if none.
208      *
209      */
210     public List getAuthors() {
211         return (_authors==null) ? (_authors=new ArrayList()) : _authors;
212     }
213 
214     /***
215      * Sets the author of the entry.
216      * <p>
217      * @param author the author of the entry, <b>null</b> if none.
218      *
219      */
220     public void setAuthors(List authors) {
221         _authors = authors;
222     }
223 
224     /***
225      * Returns the entry contributors.
226      * <p>
227      * @return a list of Person elements with the entry contributors,
228      *         an empty list if none.
229      *
230      */
231     public List getContributors() {
232         return (_contributors==null) ? (_contributors=new ArrayList()) : _contributors;
233     }
234 
235     /***
236      * Sets the entry contributors.
237      * <p>
238      * @param contributors the list of Person elements with the entry contributors to set,
239      *        an empty list or <b>null</b> if none.
240      *
241      */
242     public void setContributors(List contributors) {
243         _contributors = contributors;
244     }
245 
246     /***
247      * Returns the entry ID.
248      * <p>
249      * @return the entry ID, <b>null</b> if none.
250      *
251      */
252     public String getId() {
253         return _id;
254     }
255 
256     /***
257      * Sets the entry ID.
258      * <p>
259      * @param id the entry ID, <b>null</b> if none.
260      *
261      */
262     public void setId(String id) {
263         _id = id;
264     }
265 
266     /***
267      * Returns the entry modified date (Atom 0.3, maps to {@link getUpdated()}).
268      * <p>
269      * @return the entry modified date, <b>null</b> if none.
270      */
271     public Date getModified() {
272         return _updated;
273     }
274 
275     /***
276      * Sets the entry modified date (Atom 0.3, maps to {@link setUpdated()}).
277      * <p>
278      * @param modified the entry modified date, <b>null</b> if none.
279      */
280     public void setModified(Date modified) {
281         _updated = modified;
282     }
283 
284     /***
285      * Returns the entry issued date (Atom 0.3, maps to {@link getPublished()}).
286      * <p>
287      * @return the entry issued date, <b>null</b> if none.
288      */
289     public Date getIssued() {
290         return _published;
291     }
292 
293     /***
294      * Sets the entry issued date (Atom 0.3, maps to {@link setPublished()}).
295      * <p>
296      * @param issued the entry issued date, <b>null</b> if none.
297      */
298     public void setIssued(Date issued) {
299         _published = issued;
300     }
301 
302     /***
303      * Returns the entry created date (Atom 0.3 only)
304      * <p>
305      * @return the entry created date, <b>null</b> if none.
306      */
307     public Date getCreated() {
308         return _created;
309     }
310 
311     /***
312      * Sets the entry created date (Atom 0.3 only)
313      * <p>
314      * @param created the entry created date, <b>null</b> if none.
315      */
316     public void setCreated(Date created) {
317         _created = created;
318     }
319 
320     /***
321      * Returns the entry summary.
322      * <p>
323      * @return  the entry summary, <b>null</b> if none.
324      *
325      */
326     public Content getSummary() {
327         return _summary;
328     }
329 
330     /***
331      * Sets the entry summary.
332      * <p>
333      * @param summary the entry summary, <b>null</b> if none.
334      *
335      */
336     public void setSummary(Content summary) {
337         _summary = summary;
338     }
339 
340     /***
341      * Returns the entry contents.
342      * <p>
343      * @return a list of Content elements with the entry contents,
344      *         an empty list if none.
345      */
346     public List getContents() {
347         return (_contents==null) ? (_contents=new ArrayList()) : _contents;
348     }
349 
350     /***
351      * Sets the entry contents.
352      * <p>
353      * @param contents the list of Content elements with the entry contents to set,
354      *        an empty list or <b>null</b> if none.
355      */
356     public void setContents(List contents) {
357         _contents = contents;
358     }
359 
360     /***
361      * Returns the entry modules.
362      * <p>
363      * @return a list of ModuleImpl elements with the entry modules,
364      *         an emtpy list if none.
365      *
366      */
367     public List getModules() {
368         return (_modules==null) ? (_modules=new ArrayList()) : _modules;
369     }
370 
371     /***
372      * Sets the entry modules.
373      * <p>
374      * @param modules the list of ModuleImpl elements with the entry modules to set,
375      *        an empty list or <b>null</b> if none.
376      *
377      */
378     public void setModules(List modules) {
379         _modules = modules;
380     }
381 
382     /***
383      * Returns the module identified by a given URI.
384      * <p>
385      * @param uri the URI of the ModuleImpl.
386      * @return The module with the given URI, <b>null</b> if none.
387      */
388     public Module getModule(String uri) {
389         return ModuleUtils.getModule(_modules,uri);
390     }
391         
392     /***
393      * Returns the published
394      * <p>
395      * @return Returns the published.
396      * @since Atom 1.0
397      */
398     public Date getPublished() {
399         return _published;
400     }
401     
402     /***
403      * Set the published
404      * <p>
405      * @param published The published to set.
406      * @since Atom 1.0
407      */
408     public void setPublished(Date published) {
409         _published = published;
410     }
411     
412     /***
413      * Returns the rights
414      * <p>
415      * @return Returns the rights.
416      * @since Atom 1.0
417      */
418     public String getRights() {
419         return _rights;
420     }
421     
422     /***
423      * Set the rights
424      * <p>
425      * @param rights The rights to set.
426      * @since Atom 1.0
427      */
428     public void setRights(String rights) {
429         _rights = rights;
430     }
431     
432     /***
433      * Returns the source
434      * <p>
435      * @return Returns the source.
436      */
437     public Feed getSource() {
438         return _source;
439     }
440     
441     /***
442      * Set the source
443      * <p>
444      * @param source The source to set.
445      */
446     public void setSource(Feed source) {
447         _source = source;
448     }
449     
450     /***
451      * Returns the updated
452      * <p>
453      * @return Returns the updated.
454      * @since Atom 1.0
455      */
456     public Date getUpdated() {
457         return _updated;
458     }
459     
460     /***
461      * Set the updated
462      * <p>
463      * @param updated The updated to set.
464      * @since Atom 1.0
465      */
466     public void setUpdated(Date updated) {
467         _updated = updated;
468     }
469     
470     /***
471      * Returns the categories
472      * <p>
473      * @return Returns the categories.
474      * @since Atom 1.0
475      */
476     public List getCategories() {
477        return (_categories==null) ? (_categories=new ArrayList()) : _categories;
478 
479     }
480     
481     /***
482      * Set the categories
483      * <p>
484      * @param categories The categories to set.
485      * @since Atom 1.0
486      */
487     public void setCategories(List categories) {
488         _categories = categories;
489     }
490 
491     /***
492      * Returns the xmlBase
493      * <p>
494      * @return Returns the xmlBase.
495      * @since Atom 1.0
496      */
497     public String getXmlBase() {
498         return _xmlBase;
499     }
500     
501     /***
502      * Set the xmlBase
503      * <p>
504      * @param xmlBase The xmlBase to set.
505      * @since Atom 1.0
506      */
507     public void setXmlBase(String xmlBase) {
508         _xmlBase = xmlBase;
509     }
510     
511     
512     /***
513      * Returns foreign markup found at entry level.
514      * <p>
515      * @return list of Opaque object to discourage use
516      *
517      */
518     public Object getForeignMarkup() {
519         return (_foreignMarkup==null) ? (_foreignMarkup=new ArrayList()) : _foreignMarkup;
520     }
521 
522     /***
523      * Sets foreign markup found at entry level.
524      * <p>
525      * @param foreignMarkup Opaque object to discourage use
526      *
527      */
528     public void setForeignMarkup(Object foreignMarkup) {
529         _foreignMarkup = (List)foreignMarkup;
530     }
531     
532     /***
533      * Returns true if entry is a media entry, i.e. has rel="edit-media".
534      *
535      */
536     public boolean isMediaEntry() {
537         boolean mediaEntry = false;
538         List links = getOtherLinks();
539         for (Iterator it = links.iterator(); it.hasNext();) {
540             Link link = (Link) it.next();
541             if ("edit-media".equals(link.getRel())) {
542                 mediaEntry = true;
543                 break;
544             }
545         }
546         return mediaEntry;
547     } 
548 
549 }