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