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.synd;
18  
19  import com.sun.syndication.common.ObjectBean;
20  import com.sun.syndication.feed.module.DCModule;
21  import com.sun.syndication.feed.module.ModuleI;
22  import com.sun.syndication.feed.module.DCModuleI;
23  
24  import java.util.ArrayList;
25  import java.util.Date;
26  import java.util.List;
27  
28  /***
29   * Bean for entries of SyndFeed feeds.
30   * <p>
31   * @author Alejandro Abdelnur
32   *
33   */
34  public class SyndEntry extends ObjectBean implements SyndEntryI {
35      private String _title;
36      private String _link;
37      private SyndContentI _description;
38      private List _contents;
39      private List _modules;
40  
41      /***
42       * Default constructor. All properties are set to <b>null</b>.
43       * <p>
44       *
45       */
46      public SyndEntry() {
47      }
48  
49      /***
50       * Returns the entry title.
51       * <p>
52       * @return the entry title, <b>null</b> if none.
53       *
54       */
55      public String getTitle() {
56          return _title;
57      }
58  
59      /***
60       * Sets the entry title.
61       * <p>
62       * @param title the entry title to set, <b>null</b> if none.
63       *
64       */
65      public void setTitle(String title) {
66          _title = title;
67      }
68  
69      /***
70       * Returns the entry link.
71       * <p>
72       * @return the entry link, <b>null</b> if none.
73       *
74       */
75      public String getLink() {
76          return _link;
77      }
78  
79      /***
80       * Sets the entry link.
81       * <p>
82       * @param link the entry link to set, <b>null</b> if none.
83       *
84       */
85      public void setLink(String link) {
86          _link = link;
87      }
88  
89      /***
90       * Returns the entry description.
91       * <p>
92       * @return the entry description, <b>null</b> if none.
93       *
94       */
95      public SyndContentI getDescription() {
96          return _description;
97      }
98  
99      /***
100      * Sets the entry description.
101      * <p>
102      * @param description the entry description to set, <b>null</b> if none.
103      *
104      */
105     public void setDescription(SyndContentI description) {
106         _description = description;
107     }
108 
109     /***
110      * Returns the entry contents.
111      * <p>
112      * @return a list of SyndContent elements with the entry contents,
113      *         an empty list if none.
114      *
115      */
116     public List getContents() {
117         return (_contents==null) ? (_contents=new ArrayList()) : _contents;
118     }
119 
120     /***
121      * Sets the entry contents.
122      * <p>
123      * @param contents the list of SyndContent elements with the entry contents to set,
124      *        an empty list or <b>null</b> if none.
125      *
126      */
127     public void setContents(List contents) {
128         _contents = contents;
129     }
130 
131 
132     /***
133      * Returns the entry published date.
134      * <p>
135      * This method is a convenience method, it maps to the Dublin Core module date.
136      * <p>
137      * @return the entry published date, <b>null</b> if none.
138      *
139      */
140     public Date getPublishedDate() {
141         return getDCModule().getDate();
142     }
143 
144     /***
145      * Sets the entry published date.
146      * <p>
147      * This method is a convenience method, it maps to the Dublin Core module date.
148      * <p>
149      * @param publishedDate the entry published date to set, <b>null</b> if none.
150      *
151      */
152     public void setPublishedDate(Date publishedDate) {
153         getDCModule().setDate(publishedDate);
154     }
155 
156     /***
157      * Returns the entry author.
158      * <p>
159      * This method is a convenience method, it maps to the Dublin Core module creator.
160      * <p>
161      * @return the entry author, <b>null</b> if none.
162      *
163      */
164     public String getAuthor() {
165         return getDCModule().getCreator();
166     }
167 
168     /***
169      * Sets the entry author.
170      * <p>
171      * This method is a convenience method, it maps to the Dublin Core module creator.
172      * <p>
173      * @param author the entry author to set, <b>null</b> if none.
174      *
175      */
176     public void setAuthor(String author) {
177         getDCModule().setCreator(author);
178     }
179 
180     /***
181      * Returns the entry categories.
182      * <p>
183      * This method is a convenience method, it maps to the Dublin Core module subjects.
184      * <p>
185      * @return a list of SyndCategory elements with the entry categories,
186      *         an empty list if none.
187      *
188      */
189     public List getCategories() {
190        return new SyndCategoryListFacade(getDCModule().getSubjects());
191     }
192 
193     /***
194      * Sets the entry categories.
195      * <p>
196      * This method is a convenience method, it maps to the Dublin Core module subjects.
197      * <p>
198      * @param categories the list of SyndCategory elements with the entry categories to set,
199      *        an empty list or <b>null</b> if none.
200      *
201      */
202     public void setCategories(List categories) {
203         getDCModule().setSubjects(SyndCategoryListFacade.convertElementsSyndCategoryToSubject(categories));
204     }
205 
206     /***
207      * Returns the entry modules.
208      * <p>
209      * @return a list of Module elements with the entry modules,
210      *         an empty list if none.
211      *
212      */
213     public List getModules() {
214         return (_modules==null) ? (_modules=new ArrayList()) : _modules;
215     }
216 
217     /***
218      * Sets the entry modules.
219      * <p>
220      * @param modules the list of Module elements with the entry modules to set,
221      *        an empty list or <b>null</b> if none.
222      *
223      */
224     public void setModules(List modules) {
225         _modules = modules;
226     }
227 
228     /***
229      * Returns the Dublin Core module of the entry.
230      * @return the DC module, it's never <b>null</b>
231      *
232      */
233     private DCModuleI getDCModule() {
234         DCModuleI dcModule = null;
235         List modules = getModules();
236         for (int i=0;dcModule==null && i<modules.size();i++) {
237             ModuleI module = (ModuleI) modules.get(i);
238             if (module.getUri().equals(DCModuleI.URI)) {
239                 dcModule = (DCModuleI) module;
240             }
241         }
242         if (dcModule==null) {
243             dcModule = new DCModule();
244             modules.add(dcModule);
245         }
246         return dcModule;
247     }
248 
249 }