1 26 27 29 package de.nava.informa.impl.basic; 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.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 51 public class Item implements ItemIF, java.io.Serializable { 52 53 private long id; 54 private String title; 55 private String description; 56 private URL link; 57 private Collection categories; 58 private String creator; 59 private String subject; 60 private Date date; 61 private Date found; 62 private ItemGuidIF guid; 63 private URL 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 title, String description, URL link) { 75 this(null, null, title, description, link); 76 } 77 78 public Item(ChannelIF channel, String title, String description, URL link) { 79 this(null, channel, title, description, link); 80 } 81 82 public Item(Element itemElement, String title, String description, URL link) { 83 this(itemElement, null, title, description, link); 84 } 85 86 public Item(Element itemElement, ChannelIF channel, String title, String description, URL 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 (); 94 this.unRead = true; 95 unRead = true; 96 } 97 98 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 getTitle() { 119 return title; 120 } 121 122 public void setTitle(String title) { 123 this.title = title; 124 } 125 126 public String getDescription() { 127 return description; 128 } 129 130 public void setDescription(String 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 getLink() { 143 return link; 144 } 145 146 public void setLink(URL link) { 147 this.link = link; 148 } 149 150 public Collection getCategories() { 151 return categories; 152 } 153 154 public void setCategories(Collection 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 getCreator() { 167 return creator; 168 } 169 170 public void setCreator(String creator) { 171 this.creator = creator; 172 } 173 174 public String getSubject() { 175 return subject; 176 } 177 178 public void setSubject(String subject) { 179 this.subject = subject; 180 } 181 182 public Date getDate() { 183 return date; 184 } 185 186 public void setDate(Date date) { 187 this.date = date; 188 } 189 190 public Date getFound() { 191 return found; 192 } 193 194 public void setFound(Date 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 getComments() { 207 return comments; 208 } 209 210 public void setComments(URL 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 getElementValue(final String path) { 231 return XmlPathUtils.getElementValue(itemElement, path); 232 } 233 234 public String [] getElementValues(final String path, final String [] elements) { 235 return XmlPathUtils.getElementValues(itemElement, path, elements); 236 } 237 238 public String getAttributeValue(final String path, final String attribute) { 239 return XmlPathUtils.getAttributeValue(itemElement, path, attribute); 240 } 241 242 public String [] getAttributeValues(final String path, final String [] attributes) { 243 return XmlPathUtils.getAttributeValues(itemElement, path, attributes); 244 } 245 246 250 260 public boolean equals(Object 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 le = link.toString().equals(cmp.getLink().toString()); 284 } else { 285 le = (cmp.getLink() == null); 286 } 287 288 return (te && de && le); 289 } 290 291 298 public int hashCode() { 299 StringBuffer sb = new StringBuffer (64); 300 sb.append(title).append(description).append(link); 301 return sb.toString().hashCode(); 302 } 303 304 309 public String toString() { 310 return "[Item (" + id + "): " + title + "]"; 311 } 312 313 } 314 | Popular Tags |