001: /*
002: * Copyright 2004 Sun Microsystems, Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: */
017: package com.sun.syndication.feed.atom;
018:
019: import com.sun.syndication.feed.module.Module;
020: import com.sun.syndication.feed.module.impl.ModuleUtils;
021: import com.sun.syndication.feed.impl.ObjectBean;
022: import com.sun.syndication.feed.module.Extendable;
023:
024: import java.util.ArrayList;
025: import java.util.Date;
026: import java.util.List;
027: import java.io.Serializable;
028:
029: /**
030: * Bean for entry elements of Atom feeds.
031: * <p>
032: * @author Alejandro Abdelnur
033: * @author Dave Johnson (updated for Atom 1.0)
034: */
035: public class Entry implements Cloneable, Serializable, Extendable {
036:
037: private ObjectBean _objBean;
038:
039: private String _xmlBase;
040: private List _authors;
041: private List _contributors;
042: private List _categories;
043: private List _contents;
044: private String _id;
045: private Date _published; // AKA issued
046: private String _rights;
047: private Feed _source;
048: private Content _summary;
049: private Content _title;
050: private Date _updated; // AKA modified
051: private List _alternateLinks;
052: private List _otherLinks;
053: private List _foreignMarkup;
054:
055: private List _modules;
056:
057: private Date _created; // Atom 0.3 only
058:
059: /**
060: * Default constructor. All properties are set to <b>null</b>.
061: * <p>
062: *
063: */
064: public Entry() {
065: _objBean = new ObjectBean(this .getClass(), this );
066: }
067:
068: /**
069: * Creates a deep 'bean' clone of the object.
070: * <p>
071: * @return a clone of the object.
072: * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
073: *
074: */
075: public Object clone() throws CloneNotSupportedException {
076: return _objBean.clone();
077: }
078:
079: /**
080: * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
081: * <p>
082: * @param other he reference object with which to compare.
083: * @return <b>true</b> if 'this' object is equal to the 'other' object.
084: *
085: */
086: public boolean equals(Object other) {
087: // can't use foreign markup in equals, due to JDOM equals impl
088: Object fm = getForeignMarkup();
089: setForeignMarkup(((Entry) other).getForeignMarkup());
090: boolean ret = _objBean.equals(other);
091: // restore foreign markup
092: setForeignMarkup(fm);
093: return ret;
094: }
095:
096: /**
097: * Returns a hashcode value for the object.
098: * <p>
099: * It follows the contract defined by the Object hashCode() method.
100: * <p>
101: * @return the hashcode of the bean object.
102: *
103: */
104: public int hashCode() {
105: return _objBean.hashCode();
106: }
107:
108: /**
109: * Returns the String representation for the object.
110: * <p>
111: * @return String representation for the object.
112: *
113: */
114: public String toString() {
115: return _objBean.toString();
116: }
117:
118: /**
119: * Returns the entry title.
120: * <p>
121: * @return the entry title, <b>null</b> if none.
122: *
123: */
124: public String getTitle() {
125: if (_title != null)
126: return _title.getValue();
127: return null;
128: }
129:
130: /**
131: * Sets the entry title.
132: * <p>
133: * @param title the entry title, <b>null</b> if none.
134: *
135: */
136: public void setTitle(String title) {
137: if (_title == null)
138: _title = new Content();
139: _title.setValue(title);
140: }
141:
142: /**
143: * Returns the entry title as a text construct.
144: * <p>
145: * @return the entry title, <b>null</b> if none.
146: *
147: */
148: public Content getTitleEx() {
149: return _title;
150: }
151:
152: /**
153: * Sets the entry title as a text construct.
154: * <p>
155: * @param title the entry title, <b>null</b> if none.
156: *
157: */
158: public void setTitleEx(Content title) {
159: _title = title;
160: }
161:
162: /**
163: * Returns the entry alternate links.
164: * <p>
165: * @return a list of Link elements with the entry alternate links, an empty list if none.
166: */
167: public List getAlternateLinks() {
168: return (_alternateLinks == null) ? (_alternateLinks = new ArrayList())
169: : _alternateLinks;
170: }
171:
172: /**
173: * Sets the entry alternate links.
174: * <p>
175: * @param alternateLinks the list of Link elements with the entry alternate links to set,
176: * an empty list or <b>null</b> if none.
177: */
178: public void setAlternateLinks(List alternateLinks) {
179: _alternateLinks = alternateLinks;
180: }
181:
182: /**
183: * Returns the entry non-alternate links.
184: * <p>
185: * @return the list of Link elements with the entry non-alternate links to set,
186: * an empty list if none.
187: */
188: public List getOtherLinks() {
189: return (_otherLinks == null) ? (_otherLinks = new ArrayList())
190: : _otherLinks;
191: }
192:
193: /**
194: * Sets the entry non-alternate links.
195: * <p>
196: * @param otherLinks the list Link elements with the entry non-alternate links to set,
197: * an empty list or <b>null</b> if none.
198: */
199: public void setOtherLinks(List otherLinks) {
200: _otherLinks = otherLinks;
201: }
202:
203: /**
204: * Returns the entry author.
205: * <p>
206: * @return the entry author, <b>null</b> if none.
207: *
208: */
209: public List getAuthors() {
210: return _authors;
211: }
212:
213: /**
214: * Sets the author of the entry.
215: * <p>
216: * @param author the author of the entry, <b>null</b> if none.
217: *
218: */
219: public void setAuthors(List authors) {
220: _authors = authors;
221: }
222:
223: /**
224: * Returns the entry contributors.
225: * <p>
226: * @return a list of Person elements with the entry contributors,
227: * an empty list if none.
228: *
229: */
230: public List getContributors() {
231: return (_contributors == null) ? (_contributors = new ArrayList())
232: : _contributors;
233: }
234:
235: /**
236: * Sets the entry contributors.
237: * <p>
238: * @param contributors the list of Person elements with the entry contributors to set,
239: * an empty list or <b>null</b> if none.
240: *
241: */
242: public void setContributors(List contributors) {
243: _contributors = contributors;
244: }
245:
246: /**
247: * Returns the entry ID.
248: * <p>
249: * @return the entry ID, <b>null</b> if none.
250: *
251: */
252: public String getId() {
253: return _id;
254: }
255:
256: /**
257: * Sets the entry ID.
258: * <p>
259: * @param id the entry ID, <b>null</b> if none.
260: *
261: */
262: public void setId(String id) {
263: _id = id;
264: }
265:
266: /**
267: * Returns the entry modified date (Atom 0.3, maps to {@link getUpdated()}).
268: * <p>
269: * @return the entry modified date, <b>null</b> if none.
270: */
271: public Date getModified() {
272: return _updated;
273: }
274:
275: /**
276: * Sets the entry modified date (Atom 0.3, maps to {@link setUpdated()}).
277: * <p>
278: * @param modified the entry modified date, <b>null</b> if none.
279: */
280: public void setModified(Date modified) {
281: _updated = modified;
282: }
283:
284: /**
285: * Returns the entry issued date (Atom 0.3, maps to {@link getPublished()}).
286: * <p>
287: * @return the entry issued date, <b>null</b> if none.
288: */
289: public Date getIssued() {
290: return _published;
291: }
292:
293: /**
294: * Sets the entry issued date (Atom 0.3, maps to {@link setPublished()}).
295: * <p>
296: * @param issued the entry issued date, <b>null</b> if none.
297: */
298: public void setIssued(Date issued) {
299: _published = issued;
300: }
301:
302: /**
303: * Returns the entry created date (Atom 0.3 only)
304: * <p>
305: * @return the entry created date, <b>null</b> if none.
306: */
307: public Date getCreated() {
308: return _created;
309: }
310:
311: /**
312: * Sets the entry created date (Atom 0.3 only)
313: * <p>
314: * @param created the entry created date, <b>null</b> if none.
315: */
316: public void setCreated(Date created) {
317: _created = created;
318: }
319:
320: /**
321: * Returns the entry summary.
322: * <p>
323: * @return the entry summary, <b>null</b> if none.
324: *
325: */
326: public Content getSummary() {
327: return _summary;
328: }
329:
330: /**
331: * Sets the entry summary.
332: * <p>
333: * @param summary the entry summary, <b>null</b> if none.
334: *
335: */
336: public void setSummary(Content summary) {
337: _summary = summary;
338: }
339:
340: /**
341: * Returns the entry contents.
342: * <p>
343: * @return a list of Content elements with the entry contents,
344: * an empty list if none.
345: */
346: public List getContents() {
347: return (_contents == null) ? (_contents = new ArrayList())
348: : _contents;
349: }
350:
351: /**
352: * Sets the entry contents.
353: * <p>
354: * @param contents the list of Content elements with the entry contents to set,
355: * an empty list or <b>null</b> if none.
356: */
357: public void setContents(List contents) {
358: _contents = contents;
359: }
360:
361: /**
362: * Returns the entry modules.
363: * <p>
364: * @return a list of ModuleImpl elements with the entry modules,
365: * an emtpy list if none.
366: *
367: */
368: public List getModules() {
369: return (_modules == null) ? (_modules = new ArrayList())
370: : _modules;
371: }
372:
373: /**
374: * Sets the entry modules.
375: * <p>
376: * @param modules the list of ModuleImpl elements with the entry modules to set,
377: * an empty list or <b>null</b> if none.
378: *
379: */
380: public void setModules(List modules) {
381: _modules = modules;
382: }
383:
384: /**
385: * Returns the module identified by a given URI.
386: * <p>
387: * @param uri the URI of the ModuleImpl.
388: * @return The module with the given URI, <b>null</b> if none.
389: */
390: public Module getModule(String uri) {
391: return ModuleUtils.getModule(_modules, uri);
392: }
393:
394: /**
395: * Returns the published
396: * <p>
397: * @return Returns the published.
398: * @since Atom 1.0
399: */
400: public Date getPublished() {
401: return _published;
402: }
403:
404: /**
405: * Set the published
406: * <p>
407: * @param published The published to set.
408: * @since Atom 1.0
409: */
410: public void setPublished(Date published) {
411: _published = published;
412: }
413:
414: /**
415: * Returns the rights
416: * <p>
417: * @return Returns the rights.
418: * @since Atom 1.0
419: */
420: public String getRights() {
421: return _rights;
422: }
423:
424: /**
425: * Set the rights
426: * <p>
427: * @param rights The rights to set.
428: * @since Atom 1.0
429: */
430: public void setRights(String rights) {
431: _rights = rights;
432: }
433:
434: /**
435: * Returns the source
436: * <p>
437: * @return Returns the source.
438: */
439: public Feed getSource() {
440: return _source;
441: }
442:
443: /**
444: * Set the source
445: * <p>
446: * @param source The source to set.
447: */
448: public void setSource(Feed source) {
449: _source = source;
450: }
451:
452: /**
453: * Returns the updated
454: * <p>
455: * @return Returns the updated.
456: * @since Atom 1.0
457: */
458: public Date getUpdated() {
459: return _updated;
460: }
461:
462: /**
463: * Set the updated
464: * <p>
465: * @param updated The updated to set.
466: * @since Atom 1.0
467: */
468: public void setUpdated(Date updated) {
469: _updated = updated;
470: }
471:
472: /**
473: * Returns the categories
474: * <p>
475: * @return Returns the categories.
476: * @since Atom 1.0
477: */
478: public List getCategories() {
479: return _categories;
480: }
481:
482: /**
483: * Set the categories
484: * <p>
485: * @param categories The categories to set.
486: * @since Atom 1.0
487: */
488: public void setCategories(List categories) {
489: _categories = categories;
490: }
491:
492: /**
493: * Returns the xmlBase
494: * <p>
495: * @return Returns the xmlBase.
496: * @since Atom 1.0
497: */
498: public String getXmlBase() {
499: return _xmlBase;
500: }
501:
502: /**
503: * Set the xmlBase
504: * <p>
505: * @param xmlBase The xmlBase to set.
506: * @since Atom 1.0
507: */
508: public void setXmlBase(String xmlBase) {
509: _xmlBase = xmlBase;
510: }
511:
512: /**
513: * Returns foreign markup found at entry level.
514: * <p>
515: * @return list of Opaque object to discourage use
516: *
517: */
518: public Object getForeignMarkup() {
519: return (_foreignMarkup == null) ? (_foreignMarkup = new ArrayList())
520: : _foreignMarkup;
521: }
522:
523: /**
524: * Sets foreign markup found at entry level.
525: * <p>
526: * @param foreignMarkup Opaque object to discourage use
527: *
528: */
529: public void setForeignMarkup(Object foreignMarkup) {
530: _foreignMarkup = (List) foreignMarkup;
531: }
532:
533: }
|