1 26 27 29 package de.nava.informa.impl.hibernate; 30 31 import java.net.URL ; 32 import java.util.ArrayList ; 33 import java.util.Collection ; 34 import java.util.Date ; 35 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 import org.jdom.Element; 39 40 import de.nava.informa.core.CategoryIF; 41 import de.nava.informa.core.ChannelIF; 42 import de.nava.informa.core.ItemEnclosureIF; 43 import de.nava.informa.core.ItemGuidIF; 44 import de.nava.informa.core.ItemIF; 45 import de.nava.informa.core.ItemSourceIF; 46 import de.nava.informa.utils.XmlPathUtils; 47 48 56 public class Item implements ItemIF, java.io.Serializable { 57 58 private static final Log LOG = LogFactory.getLog(Item.class); 59 60 private int id = -1; 61 private String title; 62 private String description; 63 private URL link; 64 private Collection categories; 65 private String creator; 66 private String subject; 67 private Date date; 68 private Date found; 69 private ItemGuidIF guid; 70 private URL comments; 71 private ItemEnclosureIF enclosure; 72 private ItemSourceIF source; 73 private ChannelIF channel; 74 private Element itemElement; 75 private boolean unRead; 76 77 public Item() { 78 this(null, null, "[Unnamed item]", null, null); 79 } 80 81 public Item(String title, String description, URL link) { 82 this(null, null, title, description, link); 83 } 84 85 public Item(ChannelIF channel, String title, String description, URL link) { 86 this(null, channel, title, description, link); 87 } 88 89 public Item(Element itemElement, String title, String description, URL link) { 90 this(itemElement, null, title, description, link); 91 } 92 93 public Item(Element itemElement, ChannelIF channel, String title, String description, URL link) { 94 this.itemElement = itemElement; 95 this.channel = channel; 96 this.title = title; 97 this.description = description; 98 this.link = link; 99 this.categories = new ArrayList (); 100 this.unRead = true; 101 } 102 103 107 116 public int getIntId() { 117 return id; 118 } 119 120 public void setIntId(int anId) { 121 this.id = anId; 122 } 123 124 public long getId() { 125 return id; 126 } 127 128 public void setId(long longid) { 129 this.id = (int) longid; 130 } 131 132 140 public ChannelIF getChannel() { 141 return channel; 142 } 143 144 public void setChannel(ChannelIF parentChannel) { 145 this.channel = parentChannel; 146 } 147 148 155 public String getTitle() { 156 return title; 157 } 158 159 public void setTitle(String aTitle) { 160 this.title = aTitle; 161 } 162 163 169 public String getDescription() { 170 return description; 171 } 172 173 public void setDescription(String aDescription) { 174 this.description = aDescription; 175 } 176 177 183 public boolean getUnRead() { 184 return unRead; 185 } 186 187 public void setUnRead(boolean val) { 188 this.unRead = val; 189 } 190 191 197 public URL getLink() { 198 return link; 199 } 200 201 public void setLink(URL aLink) { 202 this.link = aLink; 203 } 204 205 217 public Collection getCategories() { 218 return categories; 219 } 220 221 public void setCategories(Collection aCategories) { 222 this.categories = aCategories; 223 } 224 225 public void addCategory(CategoryIF category) { 226 categories.add(category); 227 } 228 229 public void removeCategory(CategoryIF category) { 230 categories.remove(category); 231 } 232 233 239 public String getCreator() { 240 return creator; 241 } 242 243 public void setCreator(String aCreator) { 244 this.creator = aCreator; 245 } 246 247 253 public String getSubject() { 254 return subject; 255 } 256 257 public void setSubject(String aSubject) { 258 this.subject = aSubject; 259 } 260 261 267 public Date getDate() { 268 return date; 269 } 270 271 public void setDate(Date aDate) { 272 this.date = aDate; 273 } 274 275 281 public Date getFound() { 282 return found; 283 } 284 285 public void setFound(Date foundDate) { 286 this.found = foundDate; 287 } 288 289 296 public ItemGuidIF getGuid() { 297 return guid; 298 } 299 300 public void setGuid(ItemGuidIF guid) { 301 this.guid = guid; 302 } 303 304 310 public URL getComments() { 311 return comments; 312 } 313 314 public void setComments(URL comments) { 315 this.comments = comments; 316 } 317 318 325 public ItemSourceIF getSource() { 326 return source; 327 } 328 329 public void setSource(ItemSourceIF aSource) { 330 this.source = aSource; 331 } 332 333 340 public ItemEnclosureIF getEnclosure() { 341 return enclosure; 342 } 343 344 public void setEnclosure(ItemEnclosureIF anEnclosure) { 345 this.enclosure = anEnclosure; 346 } 347 348 public String getElementValue(final String path) { 349 return XmlPathUtils.getElementValue(itemElement, path); 350 } 351 352 public String [] getElementValues(final String path, final String [] elements) { 353 return XmlPathUtils.getElementValues(itemElement, path, elements); 354 } 355 356 public String getAttributeValue(final String path, final String attribute) { 357 return XmlPathUtils.getAttributeValue(itemElement, path, attribute); 358 } 359 360 public String [] getAttributeValues(final String path, final String [] attributes) { 361 return XmlPathUtils.getAttributeValues(itemElement, path, attributes); 362 } 363 364 368 373 public String toString() { 374 return "[Item (" + id + "): " + title + "]"; 375 } 376 377 381 391 public boolean equals(Object obj) { 392 if (!(obj instanceof ItemIF)) { 393 return false; 394 } 395 ItemIF cmp = (ItemIF) obj; 396 397 boolean te; 398 if (title != null) { 399 te = title.equals(cmp.getTitle()); 400 } else { 401 te = (cmp.getTitle() == null); 402 } 403 boolean le; 411 if (link != null) { 412 le = link.toString().equals(cmp.getLink().toString()); 416 } else { 417 le = (cmp.getLink() == null); 418 } 419 boolean result = te && le; 420 LOG.debug("Item.equals = " + result + "(te=" + te + ",le=" + le + ")"); 421 return (result); 422 } 423 424 431 public int hashCode() { 432 StringBuffer sb = new StringBuffer (64); 433 sb.append(title).append(link); 436 return sb.toString().hashCode(); 437 } 438 } 439 | Popular Tags |