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.URINormalizer;
23  import com.sun.syndication.common.impl.CopyFromHelper;
24  
25  import java.util.*;
26  
27  /***
28   * Bean for entries of SyndFeedImpl feeds.
29   * <p>
30   * @author Alejandro Abdelnur
31   *
32   */
33  public class SyndEntryImpl extends ObjectBean implements SyndEntry {
34      private String _uri;
35      private String _title;
36      private String _link;
37      private SyndContent _description;
38      private List _contents;
39      private List _modules;
40  
41      private static final Set IGNORE_PROPERTIES = new HashSet();
42  
43      /***
44       * Unmodifiable Set containing the convenience properties of this class.
45       * <p>
46       * Convenience properties are mapped to Modules, for cloning the convenience properties
47       * can be ignored as the will be copied as part of the module cloning.
48       */
49      public static final Set CONVENIENCE_PROPERTIES = Collections.unmodifiableSet(IGNORE_PROPERTIES);
50  
51      static {
52          IGNORE_PROPERTIES.add("publishedDate");
53          IGNORE_PROPERTIES.add("author");
54          IGNORE_PROPERTIES.add("categories");
55      }
56  
57      /***
58       * For implementations extending SyndEntryImpl to be able to use the ObjectBean functionality
59       * with extended interfaces.
60       * <p>
61       * @param beanClass
62       * @param convenienceProperties set containing the convenience properties of the SyndEntryImpl
63       * (the are ignored during cloning, check CloneableBean for details).
64       *
65       */
66      protected SyndEntryImpl(Class beanClass,Set convenienceProperties) {
67          super(beanClass,convenienceProperties);
68      }
69  
70      /***
71       * Default constructor. All properties are set to <b>null</b>.
72       * <p>
73       *
74       */
75      public SyndEntryImpl() {
76          this(SyndEntry.class,IGNORE_PROPERTIES);
77      }
78  
79          /***
80       * Returns the entry URI.
81       * <p>
82       * How the entry URI maps to a concrete feed type (RSS or Atom) depends on
83       * the concrete feed type. This is explained in detail in Rome documentation,
84       * <a href="http://wiki.java.net/bin/edit/Javawsxml/Rome04URIMapping">Feed and entry URI mapping</a>.
85       * <p>
86       * The returned URI is a normalized URI as specified in RFC 2396bis.
87       * <p>
88       * @return the entry URI, <b>null</b> if none.
89       *
90       */
91      public String getUri() {
92          return _uri;
93      }
94  
95      /***
96       * Sets the entry URI.
97       * <p>
98       * How the entry URI maps to a concrete feed type (RSS or Atom) depends on
99       * the concrete feed type. This is explained in detail in Rome documentation,
100      * <a href="http://wiki.java.net/bin/edit/Javawsxml/Rome04URIMapping">Feed and entry URI mapping</a>.
101      * <p>
102      * @param uri the entry URI to set, <b>null</b> if none.
103      *
104      */
105     public void setUri(String uri) {
106         _uri = URINormalizer.normalize(uri);
107     }
108 
109     /***
110      * Returns the entry title.
111      * <p>
112      * @return the entry title, <b>null</b> if none.
113      *
114      */
115     public String getTitle() {
116         return _title;
117     }
118 
119     /***
120      * Sets the entry title.
121      * <p>
122      * @param title the entry title to set, <b>null</b> if none.
123      *
124      */
125     public void setTitle(String title) {
126         _title = title;
127     }
128 
129     /***
130      * Returns the entry link.
131      * <p>
132      * @return the entry link, <b>null</b> if none.
133      *
134      */
135     public String getLink() {
136         return _link;
137     }
138 
139     /***
140      * Sets the entry link.
141      * <p>
142      * @param link the entry link to set, <b>null</b> if none.
143      *
144      */
145     public void setLink(String link) {
146         _link = link;
147     }
148 
149     /***
150      * Returns the entry description.
151      * <p>
152      * @return the entry description, <b>null</b> if none.
153      *
154      */
155     public SyndContent getDescription() {
156         return _description;
157     }
158 
159     /***
160      * Sets the entry description.
161      * <p>
162      * @param description the entry description to set, <b>null</b> if none.
163      *
164      */
165     public void setDescription(SyndContent description) {
166         _description = description;
167     }
168 
169     /***
170      * Returns the entry contents.
171      * <p>
172      * @return a list of SyndContentImpl elements with the entry contents,
173      *         an empty list if none.
174      *
175      */
176     public List getContents() {
177         return (_contents==null) ? (_contents=new ArrayList()) : _contents;
178     }
179 
180     /***
181      * Sets the entry contents.
182      * <p>
183      * @param contents the list of SyndContentImpl elements with the entry contents to set,
184      *        an empty list or <b>null</b> if none.
185      *
186      */
187     public void setContents(List contents) {
188         _contents = contents;
189     }
190 
191 
192     /***
193      * Returns the entry published date.
194      * <p>
195      * This method is a convenience method, it maps to the Dublin Core module date.
196      * <p>
197      * @return the entry published date, <b>null</b> if none.
198      *
199      */
200     public Date getPublishedDate() {
201         return getDCModule().getDate();
202     }
203 
204     /***
205      * Sets the entry published date.
206      * <p>
207      * This method is a convenience method, it maps to the Dublin Core module date.
208      * <p>
209      * @param publishedDate the entry published date to set, <b>null</b> if none.
210      *
211      */
212     public void setPublishedDate(Date publishedDate) {
213         getDCModule().setDate(publishedDate);
214     }
215 
216     /***
217      * Returns the entry author.
218      * <p>
219      * This method is a convenience method, it maps to the Dublin Core module creator.
220      * <p>
221      * @return the entry author, <b>null</b> if none.
222      *
223      */
224     public String getAuthor() {
225         return getDCModule().getCreator();
226     }
227 
228     /***
229      * Sets the entry author.
230      * <p>
231      * This method is a convenience method, it maps to the Dublin Core module creator.
232      * <p>
233      * @param author the entry author to set, <b>null</b> if none.
234      *
235      */
236     public void setAuthor(String author) {
237         getDCModule().setCreator(author);
238     }
239 
240     /***
241      * Returns the entry categories.
242      * <p>
243      * This method is a convenience method, it maps to the Dublin Core module subjects.
244      * <p>
245      * @return a list of SyndCategoryImpl elements with the entry categories,
246      *         an empty list if none.
247      *
248      */
249     public List getCategories() {
250        return new SyndCategoryListFacade(getDCModule().getSubjects());
251     }
252 
253     /***
254      * Sets the entry categories.
255      * <p>
256      * This method is a convenience method, it maps to the Dublin Core module subjects.
257      * <p>
258      * @param categories the list of SyndCategoryImpl elements with the entry categories to set,
259      *        an empty list or <b>null</b> if none.
260      *
261      */
262     public void setCategories(List categories) {
263         getDCModule().setSubjects(SyndCategoryListFacade.convertElementsSyndCategoryToSubject(categories));
264     }
265 
266     /***
267      * Returns the entry modules.
268      * <p>
269      * @return a list of ModuleImpl elements with the entry modules,
270      *         an empty list if none.
271      *
272      */
273     public List getModules() {
274         if  (_modules==null) {
275             _modules=new ArrayList();
276         }
277         if (ModuleUtils.getModule(_modules,DCModule.URI)==null) {
278             _modules.add(new DCModuleImpl());
279         }
280         return _modules;
281     }
282 
283     /***
284      * Sets the entry modules.
285      * <p>
286      * @param modules the list of ModuleImpl elements with the entry modules to set,
287      *        an empty list or <b>null</b> if none.
288      *
289      */
290     public void setModules(List modules) {
291         _modules = modules;
292     }
293 
294     /***
295      * Returns the module identified by a given URI.
296      * <p>
297      * @param uri the URI of the ModuleImpl.
298      * @return The module with the given URI, <b>null</b> if none.
299      */
300     public Module getModule(String uri) {
301         return ModuleUtils.getModule(getModules(),uri);
302     }
303 
304     /***
305      * Returns the Dublin Core module of the feed.
306      * @return the DC module, it's never <b>null</b>
307      *
308      */
309     private DCModule getDCModule() {
310         return (DCModule) getModule(DCModule.URI);
311     }
312 
313     public Class getInterface() {
314         return SyndEntry.class;
315     }
316 
317     public void copyFrom(Object obj) {
318         COPY_FROM_HELPER.copy(this,obj);
319     }
320 
321     private static final CopyFromHelper COPY_FROM_HELPER;
322 
323     static {
324         Map basePropInterfaceMap = new HashMap();
325         basePropInterfaceMap.put("uri",String.class);
326         basePropInterfaceMap.put("title",String.class);
327         basePropInterfaceMap.put("link",String.class);
328         basePropInterfaceMap.put("description",SyndContent.class);
329         basePropInterfaceMap.put("contents",SyndContent.class);
330         basePropInterfaceMap.put("modules",Module.class);
331 
332         Map basePropClassImplMap = new HashMap();
333         basePropClassImplMap.put(SyndContent.class,SyndContentImpl.class);
334         basePropClassImplMap.put(DCModule.class,DCModuleImpl.class);
335         basePropClassImplMap.put(SyModule.class,SyModuleImpl.class);
336 
337         COPY_FROM_HELPER = new CopyFromHelper(SyndEntry.class,basePropInterfaceMap,basePropClassImplMap);
338     }
339 
340 }