View Javadoc
1 package net.sf.flock.impl; 2 3 import java.net.MalformedURLException; 4 import java.net.URL; 5 import java.util.ArrayList; 6 import java.util.Date; 7 import java.util.Iterator; 8 import java.util.List; 9 10 import net.sf.flock.FeedI; 11 import net.sf.flock.ItemI; 12 import net.sf.flock.SubscriptionInfoI; 13 14 15 /*** 16 * @version $Revision$ 17 * @author $Author$ 18 */ 19 class Feed implements FeedI { 20 21 private String title = "New feed"; 22 private URL site; 23 private List items = new ArrayList(); 24 private SubscriptionInfoI subscriptionInfo; 25 26 27 /*** 28 * Constructor Feed. 29 * @param subscriptionInfoI 30 */ 31 public Feed(SubscriptionInfoI subscriptionInfo) { 32 this.subscriptionInfo = subscriptionInfo; 33 } 34 35 /*** 36 * Constructor Feed. 37 */ 38 public Feed() { 39 40 } 41 42 43 /*** 44 * @return site, or new URL("http://") if it's null 45 * @see net.sf.flock.FeedI#getSite() 46 */ 47 public URL getSite() { 48 if (site!=null) { 49 return site; 50 } else { 51 try { 52 return new URL("http://"); 53 } catch (MalformedURLException e) { 54 return null; 55 } 56 } 57 } 58 59 public void setSite(URL site) { 60 this.site = site; 61 } 62 63 /*** 64 * @see net.sf.flock.FeedI#getItems() 65 */ 66 public List getItems() { 67 return this.items; 68 } 69 70 public ItemI newItem(Date creationTime, String title, String description, URL link) { 71 Item item = new Item(this); 72 item.setCreationTime(creationTime); 73 item.setTitle(title); 74 item.setDescription(description); 75 item.setLink(link); 76 this.items.add( item ); 77 return item; 78 } 79 80 81 /*** 82 * @see net.sf.flock.FeedI#getTitle() 83 */ 84 public String getTitle() { 85 return this.title; 86 } 87 88 public void setTitle(String title) { 89 if (title==null) { 90 throw new IllegalArgumentException("Title cannot be null"); 91 } 92 this.title = title; 93 } 94 95 /*** 96 * @see net.sf.flock.FeedI#merge(FeedI) 97 */ 98 public List merge(FeedI feed) { 99 this.setTitle( feed.getTitle() ); 100 this.setSite( feed.getSite() ); 101 102 List newItems = new ArrayList(); 103 for (Iterator i=feed.getItems().iterator(); i.hasNext(); ) { 104 ItemI a = (ItemI)i.next(); 105 if (!this.getItems().contains(a)) { 106 newItems.add( 107 this.newItem( 108 a.getCreationTime(), 109 a.getTitle(), 110 a.getDescription(), 111 a.getLink() 112 ) 113 ); 114 } 115 } 116 117 return newItems; 118 } 119 120 121 /*** 122 * @see net.sf.flock.FeedInfoI#getSubscriptionInfo() 123 */ 124 public SubscriptionInfoI getSubscriptionInfo() { 125 return subscriptionInfo; 126 } 127 128 /*** 129 * Sets the subscriptionInfo. 130 * @param subscriptionInfo The subscriptionInfo to set 131 */ 132 public void setSubscriptionInfo(SubscriptionInfoI subscriptionInfo) { 133 this.subscriptionInfo = subscriptionInfo; 134 } 135 136 }

This page was automatically generated by Maven