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.CopyFromHelper;
24
25 import java.util.*;
26 import java.io.Serializable;
27
28 /***
29 * Bean for entries of SyndFeedImpl feeds.
30 * <p>
31 * @author Alejandro Abdelnur
32 *
33 */
34 public class SyndEntryImpl implements Serializable,SyndEntry {
35 private ObjectBean _objBean;
36 private String _uri;
37 private String _title;
38 private String _link;
39 private Date _updatedDate;
40 private SyndContent _summary;
41 private SyndContent _description;
42 private List _links;
43 private List _contents;
44 private List _modules;
45 private List _enclosures;
46 private List _authors;
47 private List _contributors;
48
49
50 private List _categories = new ArrayList();
51
52 private static final Set IGNORE_PROPERTIES = new HashSet();
53
54 /***
55 * Unmodifiable Set containing the convenience properties of this class.
56 * <p>
57 * Convenience properties are mapped to Modules, for cloning the convenience properties
58 * can be ignored as the will be copied as part of the module cloning.
59 */
60 public static final Set CONVENIENCE_PROPERTIES = Collections.unmodifiableSet(IGNORE_PROPERTIES);
61
62 static {
63 IGNORE_PROPERTIES.add("publishedDate");
64 IGNORE_PROPERTIES.add("author");
65 }
66
67 /***
68 * For implementations extending SyndEntryImpl to be able to use the ObjectBean functionality
69 * with extended interfaces.
70 * <p>
71 * @param beanClass
72 * @param convenienceProperties set containing the convenience properties of the SyndEntryImpl
73 * (the are ignored during cloning, check CloneableBean for details).
74 *
75 */
76 protected SyndEntryImpl(Class beanClass,Set convenienceProperties) {
77 _objBean = new ObjectBean(beanClass,this,convenienceProperties);
78 }
79
80 /***
81 * Default constructor. All properties are set to <b>null</b>.
82 * <p>
83 *
84 */
85 public SyndEntryImpl() {
86 this(SyndEntry.class,IGNORE_PROPERTIES);
87 }
88
89 /***
90 * Creates a deep 'bean' clone of the object.
91 * <p>
92 * @return a clone of the object.
93 * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
94 *
95 */
96 public Object clone() throws CloneNotSupportedException {
97 return _objBean.clone();
98 }
99
100 /***
101 * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
102 * <p>
103 * @param other he reference object with which to compare.
104 * @return <b>true</b> if 'this' object is equal to the 'other' object.
105 *
106 */
107 public boolean equals(Object other) {
108 return _objBean.equals(other);
109 }
110
111 /***
112 * Returns a hashcode value for the object.
113 * <p>
114 * It follows the contract defined by the Object hashCode() method.
115 * <p>
116 * @return the hashcode of the bean object.
117 *
118 */
119 public int hashCode() {
120 return _objBean.hashCode();
121 }
122
123 /***
124 * Returns the String representation for the object.
125 * <p>
126 * @return String representation for the object.
127 *
128 */
129 public String toString() {
130 return _objBean.toString();
131 }
132
133
134 /***
135 * Returns the entry URI.
136 * <p>
137 * How the entry URI maps to a concrete feed type (RSS or Atom) depends on
138 * the concrete feed type. This is explained in detail in Rome documentation,
139 * <a href="http://wiki.java.net/bin/edit/Javawsxml/Rome04URIMapping">Feed and entry URI mapping</a>.
140 * <p>
141 * The returned URI is a normalized URI as specified in RFC 2396bis.
142 * <p>
143 * @return the entry URI, <b>null</b> if none.
144 *
145 */
146 public String getUri() {
147 return _uri;
148 }
149
150 /***
151 * Sets the entry URI.
152 * <p>
153 * How the entry URI maps to a concrete feed type (RSS or Atom) depends on
154 * the concrete feed type. This is explained in detail in Rome documentation,
155 * <a href="http://wiki.java.net/bin/edit/Javawsxml/Rome04URIMapping">Feed and entry URI mapping</a>.
156 * <p>
157 * @param uri the entry URI to set, <b>null</b> if none.
158 *
159 */
160 public void setUri(String uri) {
161 _uri = URINormalizer.normalize(uri);
162 }
163
164 /***
165 * Returns the entry title.
166 * <p>
167 * @return the entry title, <b>null</b> if none.
168 *
169 */
170 public String getTitle() {
171 return _title;
172 }
173
174 /***
175 * Sets the entry title.
176 * <p>
177 * @param title the entry title to set, <b>null</b> if none.
178 *
179 */
180 public void setTitle(String title) {
181 _title = title;
182 }
183
184 /***
185 * Returns the entry link.
186 * <p>
187 * @return the entry link, <b>null</b> if none.
188 *
189 */
190 public String getLink() {
191 return _link;
192 }
193
194 /***
195 * Sets the entry link.
196 * <p>
197 * @param link the entry link to set, <b>null</b> if none.
198 *
199 */
200 public void setLink(String link) {
201 _link = link;
202 }
203
204 /***
205 * Returns the entry description.
206 * <p>
207 * @return the entry description, <b>null</b> if none.
208 *
209 */
210 public SyndContent getDescription() {
211 return _description;
212 }
213
214 /***
215 * Sets the entry description.
216 * <p>
217 * @param description the entry description to set, <b>null</b> if none.
218 *
219 */
220 public void setDescription(SyndContent description) {
221 _description = description;
222 }
223
224 /***
225 * Returns the entry contents.
226 * <p>
227 * @return a list of SyndContentImpl elements with the entry contents,
228 * an empty list if none.
229 *
230 */
231 public List getContents() {
232 return (_contents==null) ? (_contents=new ArrayList()) : _contents;
233 }
234
235 /***
236 * Sets the entry contents.
237 * <p>
238 * @param contents the list of SyndContentImpl elements with the entry contents to set,
239 * an empty list or <b>null</b> if none.
240 *
241 */
242 public void setContents(List contents) {
243 _contents = contents;
244 }
245
246 /***
247 * Returns the entry enclosures.
248 * <p>
249 * @return a list of SyndEnclosure elements with the entry enclosures,
250 * an empty list if none.
251 *
252 */
253 public List getEnclosures() {
254 return (_enclosures==null) ? (_enclosures=new ArrayList()) : _enclosures;
255 }
256
257 /***
258 * Sets the entry enclosures.
259 * <p>
260 * @param enclosures the list of SyndEnclosure elements with the entry enclosures to set,
261 * an empty list or <b>null</b> if none.
262 *
263 */
264 public void setEnclosures(List enclosures) {
265 _enclosures = enclosures;
266 }
267
268
269 /***
270 * Returns the entry published date.
271 * <p>
272 * This method is a convenience method, it maps to the Dublin Core module date.
273 * <p>
274 * @return the entry published date, <b>null</b> if none.
275 *
276 */
277 public Date getPublishedDate() {
278 return getDCModule().getDate();
279 }
280
281 /***
282 * Sets the entry published date.
283 * <p>
284 * This method is a convenience method, it maps to the Dublin Core module date.
285 * <p>
286 * @param publishedDate the entry published date to set, <b>null</b> if none.
287 *
288 */
289 public void setPublishedDate(Date publishedDate) {
290 getDCModule().setDate(publishedDate);
291 }
292
293 /***
294 * Returns the entry categories.
295 * <p>
296 * @return a list of SyndCategoryImpl elements with the entry categories,
297 * an empty list if none.
298 *
299 */
300 public List getCategories() {
301 return _categories;
302 }
303
304 /***
305 * Sets the entry categories.
306 * <p>
307 * This method is a convenience method, it maps to the Dublin Core module subjects.
308 * <p>
309 * @param categories the list of SyndCategoryImpl elements with the entry categories to set,
310 * an empty list or <b>null</b> if none.
311 *
312 */
313 public void setCategories(List categories) {
314 _categories = categories;
315 }
316
317 /***
318 * Returns the entry modules.
319 * <p>
320 * @return a list of ModuleImpl elements with the entry modules,
321 * an empty list if none.
322 *
323 */
324 public List getModules() {
325 if (_modules==null) {
326 _modules=new ArrayList();
327 }
328 if (ModuleUtils.getModule(_modules,DCModule.URI)==null) {
329 _modules.add(new DCModuleImpl());
330 }
331 return _modules;
332 }
333
334 /***
335 * Sets the entry modules.
336 * <p>
337 * @param modules the list of ModuleImpl elements with the entry modules to set,
338 * an empty list or <b>null</b> if none.
339 *
340 */
341 public void setModules(List modules) {
342 _modules = modules;
343 }
344
345 /***
346 * Returns the module identified by a given URI.
347 * <p>
348 * @param uri the URI of the ModuleImpl.
349 * @return The module with the given URI, <b>null</b> if none.
350 */
351 public Module getModule(String uri) {
352 return ModuleUtils.getModule(getModules(),uri);
353 }
354
355 /***
356 * Returns the Dublin Core module of the feed.
357 * @return the DC module, it's never <b>null</b>
358 *
359 */
360 private DCModule getDCModule() {
361 return (DCModule) getModule(DCModule.URI);
362 }
363
364 public Class getInterface() {
365 return SyndEntry.class;
366 }
367
368 public void copyFrom(Object obj) {
369 COPY_FROM_HELPER.copy(this,obj);
370 }
371
372 private static final CopyFromHelper COPY_FROM_HELPER;
373
374 static {
375 Map basePropInterfaceMap = new HashMap();
376 basePropInterfaceMap.put("uri",String.class);
377 basePropInterfaceMap.put("title",String.class);
378 basePropInterfaceMap.put("link",String.class);
379 basePropInterfaceMap.put("uri",String.class);
380 basePropInterfaceMap.put("description",SyndContent.class);
381 basePropInterfaceMap.put("contents",SyndContent.class);
382 basePropInterfaceMap.put("enclosures",SyndEnclosure.class);
383 basePropInterfaceMap.put("modules",Module.class);
384
385 Map basePropClassImplMap = new HashMap();
386 basePropClassImplMap.put(SyndContent.class,SyndContentImpl.class);
387 basePropClassImplMap.put(SyndEnclosure.class,SyndEnclosureImpl.class);
388 basePropClassImplMap.put(DCModule.class,DCModuleImpl.class);
389 basePropClassImplMap.put(SyModule.class,SyModuleImpl.class);
390
391 COPY_FROM_HELPER = new CopyFromHelper(SyndEntry.class,basePropInterfaceMap,basePropClassImplMap);
392 }
393
394 /***
395 * Returns the links
396 * <p>
397 * @return Returns the links.
398 */
399 public List getLinks() {
400 return _links;
401 }
402
403 /***
404 * Set the links
405 * <p>
406 * @param links The links to set.
407 */
408 public void setLinks(List links) {
409 _links = links;
410 }
411
412 /***
413 * Returns the summary
414 * <p>
415 * @return Returns the summary.
416 */
417 public SyndContent getSummary() {
418 return _summary;
419 }
420
421 /***
422 * Set the summary
423 * <p>
424 * @param summary The summary to set.
425 */
426 public void setSummary(SyndContent summary) {
427 _summary = summary;
428 }
429
430 /***
431 * Returns the updatedDate
432 * <p>
433 * @return Returns the updatedDate.
434 */
435 public Date getUpdatedDate() {
436 return _updatedDate;
437 }
438
439 /***
440 * Set the updatedDate
441 * <p>
442 * @param updatedDate The updatedDate to set.
443 */
444 public void setUpdatedDate(Date updatedDate) {
445 _updatedDate = updatedDate;
446 }
447
448 public List getAuthors() {
449 return _authors;
450 }
451
452
453
454
455 public void setAuthors(List authors) {
456 _authors = authors;
457 }
458
459 /***
460 * Returns the entry author.
461 * <p>
462 * This method is a convenience method, it maps to the Dublin Core module creator.
463 * <p>
464 * @return the entry author, <b>null</b> if none.
465 *
466 */
467 public String getAuthor() {
468 String author;
469
470
471
472 if ((_authors != null) && (_authors.size() > 0)) {
473 author = ((SyndPerson)_authors.get(0)).getName();
474 } else {
475 author = getDCModule().getCreator();
476 }
477 if (author == null) {
478 author = "";
479 }
480
481 return author;
482 }
483
484 /***
485 * Sets the entry author.
486 * <p>
487 * This method is a convenience method, it maps to the Dublin Core module creator.
488 * <p>
489 * @param author the entry author to set, <b>null</b> if none.
490 *
491 */
492 public void setAuthor(String author) {
493
494
495 DCModule dcModule = getDCModule();
496 String currentValue = dcModule.getCreator();
497
498 if ((currentValue == null) || (currentValue.length() == 0)) {
499 getDCModule().setCreator(author);
500 }
501 }
502
503 public List getContributors() {
504 return _contributors;
505 }
506
507
508
509
510 public void setContributors(List contributors) {
511 _contributors = contributors;
512 }
513 }