1 26 27 29 package de.nava.informa.impl.hibernate; 30 31 import de.nava.informa.core.CategoryIF; 32 import de.nava.informa.core.ChannelFormat; 33 import de.nava.informa.core.ChannelIF; 34 import de.nava.informa.core.ChannelObserverIF; 35 import de.nava.informa.core.CloudIF; 36 import de.nava.informa.core.ImageIF; 37 import de.nava.informa.core.ItemIF; 38 import de.nava.informa.core.TextInputIF; 39 import de.nava.informa.utils.XmlPathUtils; 40 import org.jdom.Element; 41 42 import java.net.MalformedURLException ; 43 import java.net.URL ; 44 import java.util.ArrayList ; 45 import java.util.Collection ; 46 import java.util.Date ; 47 import java.util.HashSet ; 48 import java.util.Iterator ; 49 import java.util.Set ; 50 51 59 public class Channel implements ChannelIF, java.io.Serializable { 60 61 private int id = -1; 62 private String title; 63 private String description; 64 private URL location; 65 private URL site; 66 private String creator; 67 private String publisher; 68 private String language; 69 private ChannelFormat format; 70 private Collection items; 71 private Set groups; 72 private CloudIF cloud; 73 private ImageIF image; 74 private TextInputIF textInput; 75 private String copyright; 76 private Collection categories; 77 private Date lastUpdated; 78 private Date lastBuild; 79 private Date pubDate; 80 81 private String rating; 82 private String generator; 83 private String docs; 84 private int ttl = -1; 85 private Element channelElement; 86 87 private String updatePeriod = UPDATE_DAILY; 89 private int updateFrequency = 1; 90 private Date updateBase; 91 92 private transient Collection observers; 93 94 public Channel() { 95 this((String ) null); 96 } 97 98 public Channel(String title) { 99 this(null, title); 100 } 101 102 public Channel(Element channelElement) { 103 this(channelElement, "Unnamed channel"); 104 } 105 106 public Channel(Element channelElement, String title) { 107 this.channelElement = channelElement; 108 this.title = title; 109 this.items = new ArrayList (); 110 this.categories = new ArrayList (); 111 this.observers = new ArrayList (); 112 this.groups = new HashSet (); 113 this.format = ChannelFormat.UNKNOWN_CHANNEL_FORMAT; 114 this.lastUpdated = new Date (); 115 } 116 117 121 130 public int getIntId() { 131 return id; 132 } 133 134 public void setIntId(int anId) { 135 this.id = anId; 136 } 137 138 public long getId() { 139 return id; 140 } 141 142 public void setId(long longid) { 143 this.id = (int) longid; 144 } 145 146 153 public String getTitle() { 154 return title; 155 } 156 157 public void setTitle(String aTitle) { 158 this.title = aTitle; 159 } 160 161 167 public String getDescription() { 168 return description; 169 } 170 171 public void setDescription(String aDescription) { 172 this.description = aDescription; 173 } 174 175 179 186 public String getLocationString() { 187 return (location == null) ? "" : location.toString(); 188 } 189 190 public void setLocationString(String loc) { 191 if (loc == null || loc.trim().length() == 0) { 192 location = null; 193 return; 194 } else { 195 try { 196 this.location = new URL (loc); 197 } catch (MalformedURLException e) { 198 e.printStackTrace(); 199 } 200 } 201 } 202 203 public URL getLocation() { 204 return location; 205 } 206 207 public void setLocation(URL location) { 208 this.location = location; 209 } 210 211 212 218 public URL getSite() { 219 return site; 220 } 221 222 public void setSite(URL siteUrl) { 223 this.site = siteUrl; 224 } 225 226 232 public String getCreator() { 233 return creator; 234 } 235 236 public void setCreator(String aCreator) { 237 this.creator = aCreator; 238 } 239 240 246 public String getPublisher() { 247 return publisher; 248 } 249 250 public void setPublisher(String aPublisher) { 251 this.publisher = aPublisher; 252 } 253 254 260 public String getLanguage() { 261 return language; 262 } 263 264 public void setLanguage(String aLanguage) { 265 this.language = aLanguage; 266 } 267 268 275 public String getFormatString() { 276 return format.toString(); 277 } 278 279 public void setFormatString(String strFormat) { 280 if (strFormat.equals(ChannelFormat.RSS_0_90.toString())) { 282 format = ChannelFormat.RSS_0_90; 283 } else if (strFormat.equals(ChannelFormat.RSS_0_91.toString())) { 284 format = ChannelFormat.RSS_0_91; 285 } else if (strFormat.equals(ChannelFormat.RSS_0_92.toString())) { 286 format = ChannelFormat.RSS_0_92; 287 } else if (strFormat.equals(ChannelFormat.RSS_0_93.toString())) { 288 format = ChannelFormat.RSS_0_93; 289 } else if (strFormat.equals(ChannelFormat.RSS_0_94.toString())) { 290 format = ChannelFormat.RSS_0_94; 291 } else if (strFormat.equals(ChannelFormat.RSS_1_0.toString())) { 292 format = ChannelFormat.RSS_1_0; 293 } else if (strFormat.equals(ChannelFormat.RSS_2_0.toString())) { 294 format = ChannelFormat.RSS_2_0; 295 } 296 } 297 298 public ChannelFormat getFormat() { 299 return format; 300 } 301 302 public void setFormat(ChannelFormat aFormat) { 303 this.format = aFormat; 304 } 305 306 319 public Set getGroups() { 320 return groups; 321 } 322 323 public void setGroups(Set aGroups) { 324 this.groups = aGroups; 325 } 326 327 339 public Collection getItems() { 340 return items; 341 } 342 343 public void setItems(Collection anItems) { 344 this.items = anItems; 345 } 346 347 public void addItem(ItemIF item) { 348 items.add(item); 349 item.setChannel(this); 350 notifyObserversItemAdded(item); 351 } 352 353 public void removeItem(ItemIF item) { 354 items.remove(item); 355 } 356 357 public ItemIF getItem(long itemId) { 358 ItemIF theItem = null; 362 Iterator it = items.iterator(); 363 while (it.hasNext()) { 364 ItemIF curItem = (ItemIF) it.next(); 365 if (curItem.getId() == itemId) { 366 theItem = curItem; 367 break; 368 } 369 } 370 return theItem; 371 } 372 373 381 public ImageIF getImage() { 382 return image; 383 } 384 385 public void setImage(ImageIF anImage) { 386 this.image = anImage; 387 } 388 389 397 public TextInputIF getTextInput() { 398 return textInput; 399 } 400 401 public void setTextInput(TextInputIF aTextInput) { 402 this.textInput = aTextInput; 403 } 404 405 411 public String getCopyright() { 412 return copyright; 413 } 414 415 public void setCopyright(String aCopyright) { 416 this.copyright = aCopyright; 417 } 418 419 425 public String getRating() { 426 return rating; 427 } 428 429 public void setRating(String aRating) { 430 this.rating = aRating; 431 } 432 433 441 public CloudIF getCloud() { 442 return cloud; 443 } 444 445 public void setCloud(CloudIF aCloud) { 446 this.cloud = aCloud; 447 } 448 449 455 public String getGenerator() { 456 return generator; 457 } 458 459 public void setGenerator(String aGenerator) { 460 this.generator = aGenerator; 461 } 462 463 469 public String getDocs() { 470 return docs; 471 } 472 473 public void setDocs(String aDocs) { 474 this.docs = aDocs; 475 } 476 477 483 public int getTtl() { 484 return ttl; 485 } 486 487 public void setTtl(int aTtl) { 488 this.ttl = aTtl; 489 } 490 491 503 public Collection getCategories() { 504 return categories; 505 } 506 507 public void setCategories(Collection aCategories) { 508 this.categories = aCategories; 509 } 510 511 public void addCategory(CategoryIF category) { 512 categories.add(category); 513 } 514 515 public void removeCategory(CategoryIF category) { 516 categories.remove(category); 517 } 518 519 525 public Date getLastUpdated() { 526 return lastUpdated; 527 } 528 529 public void setLastUpdated(Date date) { 530 this.lastUpdated = date; 531 notifyObserversChannelUpdated(); 532 } 533 534 540 public Date getLastBuildDate() { 541 return lastBuild; 542 } 543 544 public void setLastBuildDate(Date date) { 545 this.lastBuild = date; 546 } 547 548 554 public Date getPubDate() { 555 return pubDate; 556 } 557 558 public void setPubDate(Date date) { 559 this.pubDate = date; 560 } 561 562 564 570 public String getUpdatePeriod() { 571 return updatePeriod; 572 } 573 574 public void setUpdatePeriod(String anUpdatePeriod) { 575 this.updatePeriod = anUpdatePeriod; 576 } 577 578 584 public int getUpdateFrequency() { 585 return updateFrequency; 586 } 587 588 public void setUpdateFrequency(int anUpdateFrequency) { 589 this.updateFrequency = anUpdateFrequency; 590 } 591 592 598 public Date getUpdateBase() { 599 return updateBase; 600 } 601 602 public void setUpdateBase(Date date) { 603 this.updateBase = date; 604 } 605 606 public String getElementValue(final String path) { 607 return XmlPathUtils.getElementValue(channelElement, path); 608 } 609 610 public String [] getElementValues(final String path, final String [] elements) { 611 return XmlPathUtils.getElementValues(channelElement, path, elements); 612 } 613 614 public String getAttributeValue(final String path, final String attribute) { 615 return XmlPathUtils.getAttributeValue(channelElement, path, attribute); 616 } 617 618 public String [] getAttributeValues(final String path, final String [] attributes) { 619 return XmlPathUtils.getAttributeValues(channelElement, path, attributes); 620 } 621 622 626 public void addObserver(ChannelObserverIF o) { 627 observers.add(o); 628 } 629 630 public void removeObserver(ChannelObserverIF o) { 631 observers.remove(o); 632 } 633 634 638 643 public String toString() { 644 return "[Hibernate Channel (" + id + "): " + title + "(" 645 + getItems().size() + ")( " + location + " )]"; 646 } 647 648 663 public boolean equals(Object obj) { 664 if (!(obj instanceof ChannelIF)) { 665 return false; 666 } 667 ChannelIF cmp = (ChannelIF) obj; 668 669 boolean res = getLocation().toString().equals(cmp.getLocation().toString()); 673 674 return res; 675 } 676 677 683 public int hashCode() { 684 return location.toString().hashCode(); 685 } 686 687 693 public void notifyObserversItemAdded(ItemIF newItem) { 694 Iterator it = observers.iterator(); 695 while (it.hasNext()) { 696 ChannelObserverIF o = (ChannelObserverIF) it.next(); 697 o.itemAdded(newItem); 698 } 699 } 700 701 705 public void notifyObserversChannelUpdated() { 706 Iterator it = observers.iterator(); 707 while (it.hasNext()) { 708 ChannelObserverIF o = (ChannelObserverIF) it.next(); 709 o.channelRetrieved(this); 710 } 711 } 712 } 713 | Popular Tags |