1 16 package org.roller.pojos; 17 18 import java.io.Serializable ; 19 import java.util.ArrayList ; 20 import java.util.Date ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import org.roller.util.Utilities; 25 import org.roller.util.rome.ContentModule; 26 27 import com.sun.syndication.feed.module.DCModule; 28 import com.sun.syndication.feed.synd.SyndCategory; 29 import com.sun.syndication.feed.synd.SyndContent; 30 import com.sun.syndication.feed.synd.SyndEntry; 31 import com.sun.syndication.feed.synd.SyndFeed; 32 33 40 public class PlanetEntryData extends PersistentObject 41 implements Serializable , Comparable 42 { 43 protected String id; 44 protected String handle; 45 protected String title; 46 protected String guid; 47 protected String permalink; 48 protected String author; 49 protected String content = ""; 50 protected Date published; 51 protected Date updated; 52 53 private String categoriesString; 54 protected PlanetSubscriptionData subscription = null; 55 56 59 public PlanetEntryData() 60 { 61 } 62 63 66 public PlanetEntryData( 67 SyndFeed romeFeed, SyndEntry romeEntry, PlanetSubscriptionData sub) 68 { 69 setSubscription(sub); 70 initFromRomeEntry(romeFeed, romeEntry); 71 } 72 73 76 private void initFromRomeEntry(SyndFeed romeFeed, SyndEntry romeEntry) 77 { 78 setAuthor(romeEntry.getAuthor()); 79 setTitle(romeEntry.getTitle()); 80 setPermalink(romeEntry.getLink()); 81 82 DCModule entrydc = (DCModule)romeEntry.getModule(DCModule.URI); 84 DCModule feeddc = (DCModule)romeFeed.getModule(DCModule.URI); 85 if (romeEntry.getPublishedDate() != null) 86 { 87 setPublished(romeEntry.getPublishedDate()); } 89 else if (entrydc != null) 90 { 91 setPublished(entrydc.getDate()); } 93 106 if (romeEntry.getContents().size() > 0) 108 { 109 SyndContent content= (SyndContent)romeEntry.getContents().get(0); 110 if (content != null && content.getType().equals("text/plain")) 111 { 112 setContent(Utilities.unescapeHTML(content.getValue())); 113 } 114 else if (content != null) 115 { 116 setContent(content.getValue()); 117 } 118 } 119 120 if (getContent() == null || getContent().trim().length() == 0) 122 { 123 ContentModule cm = (ContentModule)romeEntry.getModule(ContentModule.URI); 124 if (cm != null) 125 { 126 setContent(Utilities.unescapeHTML(cm.getEncoded())); 127 } 128 } 129 130 if (romeEntry.getCategories().size() > 0) 132 { 133 List list = new ArrayList (); 134 Iterator cats = romeEntry.getCategories().iterator(); 135 while (cats.hasNext()) 136 { 137 SyndCategory cat = (SyndCategory)cats.next(); 138 list.add(cat.getName()); 139 } 140 setCategories(list); 141 } 142 } 143 144 146 150 public String getId() 151 { 152 return id; 153 } 154 public void setId(String id) 155 { 156 this.id = id; 157 } 158 161 public String getCategoriesString() 162 { 163 return categoriesString; 164 } 165 public void setCategoriesString(String categoriesString) 166 { 167 this.categoriesString = categoriesString; 168 } 169 172 public PlanetSubscriptionData getSubscription() 173 { 174 return subscription; 175 } 176 public void setSubscription(PlanetSubscriptionData subscription) 177 { 178 this.subscription = subscription; 179 } 180 183 public String getAuthor() 184 { 185 return author; 186 } 187 public void setAuthor(String author) 188 { 189 this.author = author; 190 } 191 194 public String getContent() 195 { 196 return content; 197 } 198 public void setContent(String content) 199 { 200 this.content = content; 201 } 202 205 public String getGuid() 206 { 207 return guid; 208 } 209 public void setGuid(String guid) 210 { 211 this.guid = guid; 212 } 213 216 public String getHandle() 217 { 218 return handle; 219 } 220 public void setHandle(String handle) 221 { 222 this.handle = handle; 223 } 224 227 public Date getPublished() 228 { 229 return published; 230 } 231 public void setPublished(Date published) 232 { 233 this.published = published; 234 } 235 238 public String getPermalink() 239 { 240 return permalink; 241 } 242 public void setPermalink(String permalink) 243 { 244 this.permalink = permalink; 245 } 246 249 public String getTitle() 250 { 251 return title; 252 } 253 public void setTitle(String title) 254 { 255 this.title = title; 256 } 257 260 public Date getUpdated() 261 { 262 return updated; 263 } 264 public void setUpdated(Date updated) 265 { 266 this.updated = updated; 267 } 268 269 271 275 public boolean inCategory(String category) 276 { 277 Iterator cats = getCategories().iterator(); 278 while (cats.hasNext()) 279 { 280 String catName = ((String )cats.next()).toLowerCase(); 281 if (catName.indexOf(category.toLowerCase()) != -1) 282 { 283 return true; 284 } 285 } 286 return false; 287 } 288 289 public List getCategories() 291 { 292 List list = new ArrayList (); 293 if (categoriesString != null) 294 { 295 String [] catArray = Utilities.stringToStringArray(categoriesString,","); 296 for (int i=0; i<catArray.length; i++) 297 { 298 list.add(catArray[i]); 299 } 300 } 301 return list; 302 } 303 public void setCategories(List categories) 304 { 305 StringBuffer sb = new StringBuffer (); 306 Iterator cats = categories.iterator(); 307 while (cats.hasNext()) 308 { 309 String cat = (String )cats.next(); 310 sb.append(cat); 311 if (cats.hasNext()) sb.append(","); 312 } 313 categoriesString = sb.toString(); 314 } 315 316 319 public String getCategoriesAsString(String delim) 320 { 321 StringBuffer sb = new StringBuffer (); 322 Iterator cats = getCategories().iterator(); 323 while (cats.hasNext()) 324 { 325 String catName = ((String )cats.next()).toLowerCase(); 326 sb.append(catName); 327 if (cats.hasNext()) sb.append(delim); 328 } 329 return sb.toString(); 330 } 331 332 public int compareTo(Object o) 333 { 334 PlanetEntryData other = (PlanetEntryData)o; 335 return getPermalink().compareTo(other.getPermalink()); 336 } 337 public void setData(PersistentObject vo) 338 { 339 } 340 } 341 342 | Popular Tags |