1 18 package org.apache.roller.pojos; 19 20 import java.io.Serializable ; 21 import java.sql.Timestamp ; 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 import org.apache.roller.config.RollerRuntimeConfig; 27 import org.apache.roller.util.rome.ContentModule; 28 29 import org.apache.roller.util.Utilities; 30 import org.apache.commons.lang.StringUtils; 31 import com.sun.syndication.feed.module.DCModule; 32 import com.sun.syndication.feed.synd.SyndCategory; 33 import com.sun.syndication.feed.synd.SyndContent; 34 import com.sun.syndication.feed.synd.SyndEntry; 35 import com.sun.syndication.feed.synd.SyndFeed; 36 37 import java.util.Map ; 38 import org.apache.commons.lang.StringEscapeUtils; 39 import org.apache.roller.RollerException; 40 import org.apache.roller.model.PluginManager; 41 import org.apache.roller.model.Roller; 42 import org.apache.roller.model.RollerFactory; 43 44 54 public class PlanetEntryData extends PersistentObject 55 implements Serializable , Comparable { 56 protected String id; 57 protected String handle; 58 protected String title; 59 protected String guid; 60 protected String permalink; 61 protected String author; 62 protected String text = ""; 63 protected Timestamp published; 64 protected Timestamp updated; 65 66 private String categoriesString; 67 protected PlanetSubscriptionData subscription = null; 68 69 72 public PlanetEntryData() { 73 } 74 75 78 public PlanetEntryData( 79 SyndFeed romeFeed, SyndEntry romeEntry, PlanetSubscriptionData sub) { 80 setSubscription(sub); 81 initFromRomeEntry(romeFeed, romeEntry); 82 } 83 84 87 public PlanetEntryData( 88 WeblogEntryData rollerEntry, 89 PlanetSubscriptionData sub, 90 Map pagePlugins) throws RollerException { 91 setSubscription(sub); 92 initFromRollerEntry(rollerEntry, pagePlugins); 93 } 94 95 98 private void initFromRomeEntry(SyndFeed romeFeed, SyndEntry romeEntry) { 99 setTitle(romeEntry.getTitle()); 100 setPermalink(romeEntry.getLink()); 101 102 DCModule entrydc = (DCModule)romeEntry.getModule(DCModule.URI); 104 DCModule feeddc = (DCModule)romeFeed.getModule(DCModule.URI); 105 if (romeEntry.getAuthor() != null) { 106 setAuthor(romeEntry.getAuthor()); 107 } else { 108 setAuthor(entrydc.getCreator()); } 110 111 if (romeEntry.getPublishedDate() != null) { 113 setPubTime(new Timestamp (romeEntry.getPublishedDate().getTime())); } else if (entrydc != null) { 115 setPubTime(new Timestamp (entrydc.getDate().getTime())); } 117 118 if (romeEntry.getContents().size() > 0) { 120 SyndContent content= (SyndContent)romeEntry.getContents().get(0); 121 if (content != null && content.getType().equals("text/plain")) { 122 setText(StringEscapeUtils.unescapeHtml(content.getValue())); 123 } else if (content != null) { 124 setText(content.getValue()); 125 } 126 } 127 128 if (getText() == null || getText().trim().length() == 0) { 130 ContentModule cm = (ContentModule)romeEntry.getModule(ContentModule.URI); 131 if (cm != null) { 132 setText(StringEscapeUtils.unescapeHtml(cm.getEncoded())); 133 } 134 } 135 136 if (romeEntry.getCategories().size() > 0) { 138 List list = new ArrayList (); 139 Iterator cats = romeEntry.getCategories().iterator(); 140 while (cats.hasNext()) { 141 SyndCategory cat = (SyndCategory)cats.next(); 142 list.add(cat.getName()); 143 } 144 setCategoriesString(list); 145 } 146 } 147 148 151 private void initFromRollerEntry(WeblogEntryData rollerEntry, Map pagePlugins) 152 throws RollerException { 153 Roller roller = RollerFactory.getRoller(); 154 PluginManager ppmgr = roller.getPagePluginManager(); 155 156 String content = ""; 157 if (!StringUtils.isEmpty(rollerEntry.getText())) { 158 content = rollerEntry.getText(); 159 } else { 160 content = rollerEntry.getSummary(); 161 } 162 content = ppmgr.applyWeblogEntryPlugins(pagePlugins, rollerEntry, content); 163 164 setAuthor( rollerEntry.getCreator().getFullName()); 165 setTitle( rollerEntry.getTitle()); 166 setPermalink( rollerEntry.getLink()); 167 setPubTime( rollerEntry.getPubTime()); 168 setText( content); 169 170 setPermalink(RollerRuntimeConfig.getProperty("site.absoluteurl") 171 + rollerEntry.getPermaLink()); 172 173 List cats = new ArrayList (); 174 cats.add(rollerEntry.getCategory().getPath()); 175 setCategoriesString(cats); 176 } 177 178 180 185 public String getId() { 186 return id; 187 } 188 public void setId(String id) { 189 this.id = id; 190 } 191 195 public String getCategoriesString() { 196 return categoriesString; 197 } 198 public void setCategoriesString(String categoriesString) { 199 this.categoriesString = categoriesString; 200 } 201 204 public PlanetSubscriptionData getSubscription() { 205 return subscription; 206 } 207 public void setSubscription(PlanetSubscriptionData subscription) { 208 this.subscription = subscription; 209 } 210 214 public String getAuthor() { 215 return author; 216 } 217 public void setAuthor(String author) { 218 this.author = author; 219 } 220 224 public String getText() { 225 return text; 226 } 227 public void setText(String content) { 228 this.text = content; 229 } 230 234 public String getGuid() { 235 return guid; 236 } 237 public void setGuid(String guid) { 238 this.guid = guid; 239 } 240 244 public String getHandle() { 245 return handle; 246 } 247 public void setHandle(String handle) { 248 this.handle = handle; 249 } 250 254 public Timestamp getPubTime() { 255 return published; 256 } 257 public void setPubTime(Timestamp published) { 258 this.published = published; 259 } 260 264 public String getPermalink() { 265 return permalink; 266 } 267 public void setPermalink(String permalink) { 268 this.permalink = permalink; 269 } 270 274 public String getTitle() { 275 return title; 276 } 277 public void setTitle(String title) { 278 this.title = title; 279 } 280 284 public Timestamp getUpdateTime() { 285 return updated; 286 } 287 public void setUpdateTime(Timestamp updated) { 288 this.updated = updated; 289 } 290 291 293 297 public boolean inCategory(String category) { 298 Iterator cats = getCategories().iterator(); 299 while (cats.hasNext()) { 300 String catName = ((String )cats.next()).toLowerCase(); 301 if (catName.indexOf(category.toLowerCase()) != -1) { 302 return true; 303 } 304 } 305 return false; 306 } 307 308 310 313 public List getCategories() { 314 List list = new ArrayList (); 315 if (categoriesString != null) { 316 String [] catArray = Utilities.stringToStringArray(categoriesString,","); 317 for (int i=0; i<catArray.length; i++) { 318 WeblogCategoryData cat = new WeblogCategoryData(); 319 cat.setName(catArray[i]); 320 cat.setPath(catArray[i]); 321 list.add(cat); 322 } 323 } 324 return list; 325 } 326 327 331 public WeblogCategoryData getCategory() { 332 WeblogCategoryData cat = null; 333 List cats = getCategories(); 334 if (cats.size() > 0) { 335 cat = (WeblogCategoryData)cats.get(0); 336 } 337 return cat; 338 } 339 340 private void setCategoriesString(List categories) { 341 StringBuffer sb = new StringBuffer (); 342 Iterator cats = categories.iterator(); 343 while (cats.hasNext()) { 344 String cat = (String )cats.next(); 345 sb.append(cat); 346 if (cats.hasNext()) sb.append(","); 347 } 348 categoriesString = sb.toString(); 349 } 350 351 356 public UserData getCreator() { 357 UserData user = null; 358 if (author != null) { 359 user = new UserData(); 360 user.setFullName(author); 361 user.setUserName(author); 362 } 363 return user; 364 } 365 366 370 public String getSummary() { 371 return null; 372 } 373 374 377 public int compareTo(Object o) { 378 PlanetEntryData other = (PlanetEntryData)o; 379 return getPermalink().compareTo(other.getPermalink()); 380 } 381 382 385 public boolean equals(Object other) { 386 if(this == other) return true; 387 if(!(other instanceof PlanetEntryData)) return false; 388 final PlanetEntryData that = (PlanetEntryData) other; 389 return this.permalink.equals(that.getPermalink()); 390 } 391 392 395 public int hashCode() { 396 return this.permalink.hashCode(); 397 } 398 399 public void setData(PersistentObject vo) {} 400 401 405 public PlanetSubscriptionData getWebsite() { 406 return this.subscription; 407 } 408 public void setWebsite() { 409 } 411 } 412 413 414 415 | Popular Tags |