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.rss;
018:
019: import com.sun.syndication.feed.impl.ObjectBean;
020: import com.sun.syndication.feed.module.Module;
021: import com.sun.syndication.feed.module.impl.ModuleUtils;
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 items of RSS feeds.
031: * <p>
032: * It handles all RSS versions without loosing information.
033: * <p>
034: * For RSS1.0 it supports Dublin Core and Syndication modules. Note that
035: * those modules currently support simple syntax format only.
036: * <p>
037: * @author Alejandro Abdelnur
038: *
039: */
040: public class Item implements Cloneable, Serializable, Extendable {
041: private ObjectBean _objBean;
042: private String _title;
043: private String _link;
044: private String _uri;
045: private Description _description;
046: private Content _content;
047: private Source _source;
048: private List _enclosures;
049: private List _categories;
050: private Guid _guid;
051: private String _comments;
052: private String _author;
053: private Date _pubDate;
054: private Date _expirationDate;
055: private List _modules;
056: private List _foreignMarkup;
057:
058: /**
059: * Default constructor. All properties are set to <b>null</b>.
060: * <p>
061: *
062: */
063: public Item() {
064: _objBean = new ObjectBean(this .getClass(), this );
065: }
066:
067: /**
068: * Creates a deep 'bean' clone of the object.
069: * <p>
070: * @return a clone of the object.
071: * @throws CloneNotSupportedException thrown if an element of the object cannot be cloned.
072: *
073: */
074: public Object clone() throws CloneNotSupportedException {
075: return _objBean.clone();
076: }
077:
078: /**
079: * Indicates whether some other object is "equal to" this one as defined by the Object equals() method.
080: * <p>
081: * @param other he reference object with which to compare.
082: * @return <b>true</b> if 'this' object is equal to the 'other' object.
083: *
084: */
085: public boolean equals(Object other) {
086: // can't use foreign markup in equals, due to JDOM equals impl
087: Object fm = getForeignMarkup();
088: setForeignMarkup(((Item) other).getForeignMarkup());
089: boolean ret = _objBean.equals(other);
090: // restore foreign markup
091: setForeignMarkup(fm);
092: return ret;
093: }
094:
095: /**
096: * Returns a hashcode value for the object.
097: * <p>
098: * It follows the contract defined by the Object hashCode() method.
099: * <p>
100: * @return the hashcode of the bean object.
101: *
102: */
103: public int hashCode() {
104: return _objBean.hashCode();
105: }
106:
107: /**
108: * Returns the String representation for the object.
109: * <p>
110: * @return String representation for the object.
111: *
112: */
113: public String toString() {
114: return _objBean.toString();
115: }
116:
117: /**
118: * Returns the item title.
119: * <p>
120: * @return the item title, <b>null</b> if none.
121: *
122: */
123: public String getTitle() {
124: return _title;
125: }
126:
127: /**
128: * Sets the item title.
129: * <p>
130: * @param title the item title to set, <b>null</b> if none.
131: *
132: */
133: public void setTitle(String title) {
134: _title = title;
135: }
136:
137: /**
138: * Returns the item link.
139: * <p>
140: * @return the item link, <b>null</b> if none.
141: *
142: */
143: public String getLink() {
144: return _link;
145: }
146:
147: /**
148: * Sets the item link.
149: * <p>
150: * @param link the item link to set, <b>null</b> if none.
151: *
152: */
153: public void setLink(String link) {
154: _link = link;
155: }
156:
157: /**
158: * Returns the item uri.
159: * <p>
160: * @return the item uri, <b>null</b> if none.
161: */
162: public String getUri() {
163: return _uri;
164: }
165:
166: /**
167: * Sets the item uri.
168: * <p>
169: * @param uri the item uri to set, <b>null</b> if none.
170: */
171: public void setUri(String uri) {
172: _uri = uri;
173: }
174:
175: /**
176: * Returns the item description.
177: * <p>
178: * @return the item description, <b>null</b> if none.
179: *
180: */
181: public Description getDescription() {
182: return _description;
183: }
184:
185: /**
186: * Sets the item description.
187: * <p>
188: * @param description the item description to set, <b>null</b> if none.
189: *
190: */
191: public void setDescription(Description description) {
192: _description = description;
193: }
194:
195: /**
196: * Returns the item content.
197: * <p>
198: * @return the item content, <b>null</b> if none.
199: *
200: */
201: public Content getContent() {
202: return _content;
203: }
204:
205: /**
206: * Sets the item content.
207: * <p>
208: * @param content the item content to set, <b>null</b> if none.
209: *
210: */
211: public void setContent(Content content) {
212: _content = content;
213: }
214:
215: /**
216: * Returns the item source.
217: * <p>
218: * @return the item source, <b>null</b> if none.
219: *
220: */
221: public Source getSource() {
222: return _source;
223: }
224:
225: /**
226: * Sets the item source.
227: * <p>
228: * @param source the item source to set, <b>null</b> if none.
229: *
230: */
231: public void setSource(Source source) {
232: _source = source;
233: }
234:
235: /**
236: * Returns the item enclosures.
237: * <p>
238: * @return a list of Enclosure elements with the item enclosures,
239: * an empty list if none.
240: *
241: */
242: public List getEnclosures() {
243: return (_enclosures == null) ? (_enclosures = new ArrayList())
244: : _enclosures;
245: }
246:
247: /**
248: * Sets the item enclosures.
249: * <p>
250: * @param enclosures the list of Enclosure elements with the item enclosures to set,
251: * an empty list or <b>null</b> if none.
252: *
253: */
254: public void setEnclosures(List enclosures) {
255: _enclosures = enclosures;
256: }
257:
258: /**
259: * Returns the item categories.
260: * <p>
261: * @return a list of Category elements with the item categories,
262: * an empty list if none.
263: *
264: */
265: public List getCategories() {
266: return (_categories == null) ? (_categories = new ArrayList())
267: : _categories;
268: }
269:
270: /**
271: * Sets the item categories.
272: * <p>
273: * @param categories the list of Categories elements with the item categories to set,
274: * an empty list or <b>null</b> if none.
275: *
276: */
277: public void setCategories(List categories) {
278: _categories = categories;
279: }
280:
281: /**
282: * Returns the item GUID.
283: * <p>
284: * @return the item GUID, <b>null</b> if none.
285: *
286: */
287: public Guid getGuid() {
288: return _guid;
289: }
290:
291: /**
292: * Sets the item GUID.
293: * <p>
294: * @param guid the item GUID to set, <b>null</b> if none.
295: *
296: */
297: public void setGuid(Guid guid) {
298: _guid = guid;
299: }
300:
301: /**
302: * Returns the item comments.
303: * <p>
304: * @return the item comments, <b>null</b> if none.
305: *
306: */
307: public String getComments() {
308: return _comments;
309: }
310:
311: /**
312: * Sets the item comments.
313: * <p>
314: * @param comments the item comments to set, <b>null</b> if none.
315: *
316: */
317: public void setComments(String comments) {
318: _comments = comments;
319: }
320:
321: /**
322: * Returns the item author.
323: * <p>
324: * @return the item author, <b>null</b> if none.
325: *
326: */
327: public String getAuthor() {
328: return _author;
329: }
330:
331: /**
332: * Sets the item author.
333: * <p>
334: * @param author the item author to set, <b>null</b> if none.
335: *
336: */
337: public void setAuthor(String author) {
338: _author = author;
339: }
340:
341: /**
342: * Returns the item modules.
343: * <p>
344: * @return a list of ModuleImpl elements with the item modules,
345: * an empty list if none.
346: *
347: */
348: public List getModules() {
349: return (_modules == null) ? (_modules = new ArrayList())
350: : _modules;
351: }
352:
353: /**
354: * Sets the item modules.
355: * <p>
356: * @param modules the list of ModuleImpl elements with the item modules to set,
357: * an empty list or <b>null</b> if none.
358: *
359: */
360: public void setModules(List modules) {
361: _modules = modules;
362: }
363:
364: /**
365: * Returns the module identified by a given URI.
366: * <p>
367: * @param uri the URI of the ModuleImpl.
368: * @return The module with the given URI, <b>null</b> if none.
369: */
370: public Module getModule(String uri) {
371: return ModuleUtils.getModule(_modules, uri);
372: }
373:
374: /**
375: * Returns the item publishing date.
376: * <p>
377: * @return the item publishing date, <b>null</b> if none.
378: *
379: */
380: public Date getPubDate() {
381: return _pubDate;
382: }
383:
384: /**
385: * Sets the item publishing date.
386: * <p>
387: * @param pubDate the item publishing date to set, <b>null</b> if none.
388: *
389: */
390: public void setPubDate(Date pubDate) {
391: _pubDate = pubDate;
392: }
393:
394: /**
395: * Returns the item expiration date.
396: * <p>
397: * @return the item expiration date, <b>null</b> if none.
398: *
399: */
400: public Date getExpirationDate() {
401: return _expirationDate;
402: }
403:
404: /**
405: * Sets the item expiration date.
406: * <p>
407: * @param expirationDate the item expiration date to set, <b>null</b> if none.
408: *
409: */
410: public void setExpirationDate(Date expirationDate) {
411: _expirationDate = expirationDate;
412: }
413:
414: /**
415: * Returns foreign markup found at item level.
416: * <p>
417: * @return Opaque object to discourage use
418: *
419: */
420: public Object getForeignMarkup() {
421: return (_foreignMarkup == null) ? (_foreignMarkup = new ArrayList())
422: : _foreignMarkup;
423: }
424:
425: /**
426: * Sets foreign markup found at item level.
427: * <p>
428: * @param foreignMarkup Opaque object to discourage use
429: *
430: */
431: public void setForeignMarkup(Object foreignMarkup) {
432: _foreignMarkup = (List) foreignMarkup;
433: }
434:
435: }
|