KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > nava > informa > impl > basic > Item


1 //
2
// Informa -- RSS Library for Java
3
// Copyright (c) 2002 by Niko Schmuck
4
//
5
// Niko Schmuck
6
// http://sourceforge.net/projects/informa
7
// mailto:niko_schmuck@users.sourceforge.net
8
//
9
// This library is free software.
10
//
11
// You may redistribute it and/or modify it under the terms of the GNU
12
// Lesser General Public License as published by the Free Software Foundation.
13
//
14
// Version 2.1 of the license should be included with this distribution in
15
// the file LICENSE. If the license is not included with this distribution,
16
// you may find a copy at the FSF web site at 'www.gnu.org' or 'www.fsf.org',
17
// or you may write to the Free Software Foundation, 675 Mass Ave, Cambridge,
18
// MA 02139 USA.
19
//
20
// This library is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied waranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
// Lesser General Public License for more details.
24
//
25

26
27 // $Id: Item.java,v 1.28 2004/09/02 09:07:56 spyromus Exp $
28

29 package de.nava.informa.impl.basic;
30
31 import java.net.URL JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.Collection JavaDoc;
34 import java.util.Date JavaDoc;
35
36 import org.jdom.Element;
37
38 import de.nava.informa.core.CategoryIF;
39 import de.nava.informa.core.ChannelIF;
40 import de.nava.informa.core.ItemEnclosureIF;
41 import de.nava.informa.core.ItemGuidIF;
42 import de.nava.informa.core.ItemIF;
43 import de.nava.informa.core.ItemSourceIF;
44 import de.nava.informa.utils.XmlPathUtils;
45
46 /**
47  * In-Memory implementation of the ItemIF interface.
48  *
49  * @author Niko Schmuck (niko@nava.de)
50  */

51 public class Item implements ItemIF, java.io.Serializable JavaDoc {
52
53   private long id;
54   private String JavaDoc title;
55   private String JavaDoc description;
56   private URL JavaDoc link;
57   private Collection JavaDoc categories;
58   private String JavaDoc creator;
59   private String JavaDoc subject;
60   private Date JavaDoc date;
61   private Date JavaDoc found;
62   private ItemGuidIF guid;
63   private URL JavaDoc comments;
64   private ItemSourceIF source;
65   private ItemEnclosureIF enclosure;
66   private Element itemElement;
67   private ChannelIF channel;
68   private boolean unRead;
69
70   public Item() {
71     this(null, null, "[Unknown Item]", null, null);
72   }
73
74   public Item(String JavaDoc title, String JavaDoc description, URL JavaDoc link) {
75     this(null, null, title, description, link);
76   }
77
78   public Item(ChannelIF channel, String JavaDoc title, String JavaDoc description, URL JavaDoc link) {
79     this(null, channel, title, description, link);
80   }
81
82   public Item(Element itemElement, String JavaDoc title, String JavaDoc description, URL JavaDoc link) {
83     this(itemElement, null, title, description, link);
84   }
85
86   public Item(Element itemElement, ChannelIF channel, String JavaDoc title, String JavaDoc description, URL JavaDoc link) {
87     this.id = IdGenerator.getInstance().getId();
88     this.itemElement = itemElement;
89     this.channel = channel;
90     this.title = title;
91     this.description = description;
92     this.link = link;
93     this.categories = new ArrayList JavaDoc();
94     this.unRead = true;
95     unRead = true;
96   }
97
98   // --------------------------------------------------------------
99
// implementation of ItemIF interface
100
// --------------------------------------------------------------
101

102   public long getId() {
103     return id;
104   }
105
106   public void setId(long id) {
107     this.id = id;
108   }
109
110   public ChannelIF getChannel() {
111     return channel;
112   }
113
114   public void setChannel(ChannelIF channel) {
115     this.channel = channel;
116   }
117
118   public String JavaDoc getTitle() {
119     return title;
120   }
121
122   public void setTitle(String JavaDoc title) {
123     this.title = title;
124   }
125
126   public String JavaDoc getDescription() {
127     return description;
128   }
129
130   public void setDescription(String JavaDoc description) {
131     this.description = description;
132   }
133
134   public boolean getUnRead() {
135     return unRead;
136   }
137
138   public void setUnRead(boolean val) {
139     unRead = val;
140   }
141
142   public URL JavaDoc getLink() {
143     return link;
144   }
145
146   public void setLink(URL JavaDoc link) {
147     this.link = link;
148   }
149
150   public Collection JavaDoc getCategories() {
151     return categories;
152   }
153
154   public void setCategories(Collection JavaDoc categories) {
155     this.categories = categories;
156   }
157
158   public void addCategory(CategoryIF category) {
159     categories.add(category);
160   }
161
162   public void removeCategory(CategoryIF category) {
163     categories.remove(category);
164   }
165
166   public String JavaDoc getCreator() {
167     return creator;
168   }
169
170   public void setCreator(String JavaDoc creator) {
171     this.creator = creator;
172   }
173
174   public String JavaDoc getSubject() {
175     return subject;
176   }
177
178   public void setSubject(String JavaDoc subject) {
179     this.subject = subject;
180   }
181
182   public Date JavaDoc getDate() {
183     return date;
184   }
185
186   public void setDate(Date JavaDoc date) {
187     this.date = date;
188   }
189
190   public Date JavaDoc getFound() {
191     return found;
192   }
193
194   public void setFound(Date JavaDoc found) {
195     this.found = found;
196   }
197
198   public ItemGuidIF getGuid() {
199     return guid;
200   }
201
202   public void setGuid(ItemGuidIF guid) {
203     this.guid = guid;
204   }
205
206   public URL JavaDoc getComments() {
207     return comments;
208   }
209
210   public void setComments(URL JavaDoc comments) {
211     this.comments = comments;
212   }
213
214   public ItemSourceIF getSource() {
215     return source;
216   }
217
218   public void setSource(ItemSourceIF source) {
219     this.source = source;
220   }
221
222   public ItemEnclosureIF getEnclosure() {
223     return enclosure;
224   }
225
226   public void setEnclosure(ItemEnclosureIF enclosure) {
227     this.enclosure = enclosure;
228   }
229
230   public String JavaDoc getElementValue(final String JavaDoc path) {
231     return XmlPathUtils.getElementValue(itemElement, path);
232   }
233
234   public String JavaDoc[] getElementValues(final String JavaDoc path, final String JavaDoc[] elements) {
235     return XmlPathUtils.getElementValues(itemElement, path, elements);
236   }
237
238   public String JavaDoc getAttributeValue(final String JavaDoc path, final String JavaDoc attribute) {
239     return XmlPathUtils.getAttributeValue(itemElement, path, attribute);
240   }
241
242   public String JavaDoc[] getAttributeValues(final String JavaDoc path, final String JavaDoc[] attributes) {
243     return XmlPathUtils.getAttributeValues(itemElement, path, attributes);
244   }
245
246   // ----------------------------------------------------------------------
247
// overwrite default method implementation from Object
248
// ----------------------------------------------------------------------
249

250   /**
251    * Indicates whether some other object is "equal to" this one.
252    *
253    * @param obj the reference object with which to compare.
254    *
255    * @return <code>true</code> if this object is the same as the obj
256    * argument; <code>false</code> otherwise.
257    *
258    * @see #hashCode()
259    */

260   public boolean equals(Object JavaDoc obj) {
261     if (!(obj instanceof ItemIF)) {
262       return false;
263     }
264     ItemIF cmp = (ItemIF) obj;
265
266     boolean te;
267     if (title != null) {
268       te = title.equals(cmp.getTitle());
269     } else {
270       te = (cmp.getTitle() == null);
271     }
272     boolean de;
273     if (description != null) {
274       de = description.equals(cmp.getDescription());
275     } else {
276       de = (cmp.getDescription() == null);
277     }
278     boolean le;
279     if (link != null) {
280       // Comparison of links uses synchronized code of Java-NET.
281
// This may hurt multi-threaded applications. So, please think twice
282
// before using direct comparison of links.
283
le = link.toString().equals(cmp.getLink().toString());
284     } else {
285       le = (cmp.getLink() == null);
286     }
287
288     return (te && de && le);
289   }
290
291   /**
292    * Returns a hash code value for the object. This method is
293    * supported for the benefit of hashtables such as those provided by
294    * <code>java.util.Hashtable</code>.
295    *
296    * @return a hash code value for this object.
297    */

298   public int hashCode() {
299     StringBuffer JavaDoc sb = new StringBuffer JavaDoc(64);
300     sb.append(title).append(description).append(link);
301     return sb.toString().hashCode();
302   }
303
304   /**
305    * Returns a string representation of the object.
306    *
307    * @return a string representation of the object.
308    */

309   public String JavaDoc toString() {
310     return "[Item (" + id + "): " + title + "]";
311   }
312
313 }
314
Popular Tags