1 4 package com.openedit.blog; 5 6 import java.io.Serializable ; 7 import java.text.ParseException ; 8 import java.text.SimpleDateFormat ; 9 import java.util.ArrayList ; 10 import java.util.Date ; 11 import java.util.Iterator ; 12 import java.util.List ; 13 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 import org.openedit.blog.archive.CommentArchive; 17 import org.openedit.links.LinkTree; 18 19 import com.openedit.OpenEditException; 20 import com.openedit.OpenEditRuntimeException; 21 import com.openedit.page.manage.PageManager; 22 import com.openedit.users.User; 23 import com.sun.syndication.feed.synd.SyndContentImpl; 24 import com.sun.syndication.feed.synd.SyndEntryImpl; 25 26 30 public class BlogEntry extends SyndEntryImpl implements Serializable , Comparable 31 { 32 protected String fieldPath; 33 protected List fieldComments; 34 transient protected PageManager fieldPageManager; 35 protected LinkTree fieldLinkTree; 36 protected boolean fieldVisible = false; 37 protected static SimpleDateFormat fieldGmtStandard; 38 protected User fieldUser; 39 protected List fieldNotify; 40 protected CommentArchive fieldCommentArchive; 41 private static final Log log = LogFactory.getLog(BlogEntry.class); 42 43 public BlogEntry() 44 { 45 } 46 47 48 public String getPath() 49 { 50 return fieldPath; 51 } 52 53 57 58 public void setPath(String inPath) 59 { 60 fieldPath = inPath; 61 } 62 63 public String published(String inFormat) 64 { 65 SimpleDateFormat format = new SimpleDateFormat (inFormat); 66 return format.format(getPublishedDate()); 67 } 68 public String getId() 69 { 70 return getPath(); 71 } 72 73 82 public int countComments() throws OpenEditException 83 { 84 return getComments().size(); 85 } 86 87 95 public int countVisibleComments() throws OpenEditException 96 { 97 return getVisibleComments().size(); 98 } 99 100 108 public List getComments() throws OpenEditException 109 { 110 if( fieldComments == null) 111 { 112 fieldComments = new ArrayList (); 113 getCommentArchive().loadComments(this); 114 } 115 return fieldComments; 116 } 117 118 126 public List getVisibleComments() throws OpenEditException 127 { 128 List comments = getComments(); 129 List visibleComments = new ArrayList (); 130 for ( Iterator iter = comments.iterator(); iter.hasNext(); ) 131 { 132 Comment comment = (Comment) iter.next(); 133 if ( comment.isVisible() ) 134 { 135 visibleComments.add( comment ); 136 } 137 } 138 return visibleComments; 139 } 140 141 public List getAllowedComments(User inUser) throws OpenEditException 142 { 143 List comments = getComments(); 144 List allowedComments = new ArrayList (); 145 for ( Iterator iter = comments.iterator(); iter.hasNext(); ) 146 { 147 Comment comment = (Comment) iter.next(); 148 if ( comment.isVisible() || comment.canEdit(inUser)) 149 { 150 allowedComments.add( comment ); 151 } 152 } 153 return allowedComments; 154 } 155 156 public PageManager getPageManager() 157 { 158 return fieldPageManager; 159 } 160 public void setPageManager(PageManager inPageManager) 161 { 162 fieldPageManager = inPageManager; 163 } 164 public LinkTree getLinkTree() 165 { 166 return fieldLinkTree; 167 } 168 public void setLinkTree(LinkTree inLinkTree) 169 { 170 fieldLinkTree = inLinkTree; 171 } 172 178 public void addComment(Comment inComment) throws OpenEditException 179 { 180 getComments().add(inComment); 182 } 183 184 192 public Comment getComment(String inId) throws OpenEditException 193 { 194 for (Iterator iter = getComments().iterator(); iter.hasNext();) 195 { 196 Comment comment = (Comment) iter.next(); 197 if (comment.getId().equals(inId)) 198 { 199 return comment; 200 } 201 } 202 return null; 203 } 204 205 public void removeComment(String inId) throws OpenEditException 206 { 207 Comment comment = getComment(inId); 208 removeComment(comment); 209 } 210 211 public void removeComment(Comment inComment) throws OpenEditException 212 { 213 if ( inComment != null ) 214 { 215 getComments().remove( inComment ); 216 } 217 } 218 219 220 223 public void setDescription(String inContent) 224 { 225 SyndContentImpl content = new SyndContentImpl(); 226 content.setType("text/html"); 227 content.setValue(inContent); 228 setDescription(content); 229 } 230 public boolean isVisible() 231 { 232 return fieldVisible; 233 } 234 public void setVisible(boolean invisible) 235 { 236 this.fieldVisible = invisible; 237 } 238 239 public SimpleDateFormat getGmtStandard() 240 { 241 if ( fieldGmtStandard == null) 242 { 243 fieldGmtStandard = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); 244 } 245 return fieldGmtStandard; 246 } 247 public Date parse(String inDate) 248 { 249 try 250 { 251 if ( inDate.startsWith("2")) 252 { 253 return getGmtStandard().parse(inDate); 254 } 255 else 256 { 257 return SimpleDateFormat.getDateTimeInstance().parse(inDate); 258 } 259 } catch( ParseException ex) 260 { 261 throw new OpenEditRuntimeException(ex); 262 } 263 } 264 public void setGmtStandard(SimpleDateFormat inGmtStandard) 265 { 266 fieldGmtStandard = inGmtStandard; 267 } 268 269 public User getUser() 270 { 271 return fieldUser; 272 } 273 274 public void setUser(User inUser) 275 { 276 fieldUser = inUser; 277 } 278 279 public List getNotify() 280 { 281 return fieldNotify; 282 } 283 284 public void setNotify(List inNotify) 285 { 286 fieldNotify = inNotify; 287 } 288 289 public CommentArchive getCommentArchive() 290 { 291 return fieldCommentArchive; 292 } 293 294 public void setCommentArchive(CommentArchive inCommentArchive) 295 { 296 fieldCommentArchive = inCommentArchive; 297 } 298 public int compareTo(Object inEntry) 299 { 300 BlogEntry in = (BlogEntry)inEntry; 301 return getPublishedDate().compareTo(in.getPublishedDate()); 302 } 303 } 304 | Popular Tags |