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