| 1 25 26 package com.j2biz.blogunity.pojo; 27 28 import java.io.Serializable ; 29 import java.text.SimpleDateFormat ; 30 import java.util.Date ; 31 import java.util.Iterator ; 32 import java.util.Set ; 33 import java.util.TreeSet ; 34 35 import org.apache.commons.lang.StringUtils; 36 37 import net.sf.hibernate.Validatable; 38 import net.sf.hibernate.ValidationFailure; 39 40 import com.j2biz.blogunity.util.CategoryComparator; 41 import com.j2biz.blogunity.util.CommentComparator; 42 43 53 public class Entry implements Validatable, Serializable { 54 55 58 private static final long serialVersionUID = 3618698608472373556L; 59 60 61 public static final int PUBLIC = 0; 62 63 64 public static final int PRIVATE = 1; 65 66 67 public static final int DRAFT = 2; 68 69 public static final SimpleDateFormat PERMALINK_FORMAT = new SimpleDateFormat ("/yyyy/MM/dd/"); 70 71 private Long id; 72 73 private String aliasname; 74 75 private String title; 76 77 private String rawTitle; 78 79 private String excerpt; 80 81 private String rawExcerpt; 82 83 private String body; 84 85 private String rawBody; 86 87 private Date createTime; 88 89 private User author; 90 91 private String authorIP = "127.0.0.1"; 92 93 private Set categories = new TreeSet (new CategoryComparator()); 94 95 private Set comments = new TreeSet (new CommentComparator()); 96 97 private Set trackbacks = new TreeSet (); 99 102 private Blog blog; 103 104 private Userpic userpic; 105 106 private boolean trackbackAllowed = true; 107 108 private boolean commentingAllowed = true; 109 110 private boolean anonymousCommentingAllowed = true; 111 112 113 private int type = PUBLIC; 114 115 118 public Entry() { 119 super(); 120 } 121 122 129 public Blog getBlog() { 130 return blog; 131 } 132 133 137 public void setBlog(Blog blog) { 138 this.blog = blog; 139 } 140 141 147 public String getAliasname() { 148 return aliasname; 149 } 150 151 154 public void setAliasname(String aliasname) { 155 this.aliasname = aliasname; 156 } 157 158 164 public boolean getTrackbackAllowed() { 165 return trackbackAllowed; 166 } 167 168 171 public void setTrackbackAllowed(boolean tbAllowed) { 172 this.trackbackAllowed = tbAllowed; 173 } 174 175 178 public boolean isTrackbackAllowed() { 179 return getTrackbackAllowed(); 180 } 181 182 189 public boolean getAnonymousCommentingAllowed() { 190 return anonymousCommentingAllowed; 191 } 192 193 196 public boolean isAnonymousCommentingAllowed() { 197 return anonymousCommentingAllowed; 198 } 199 200 204 public void setAnonymousCommentingAllowed(boolean anonymousCommentingAllowed) { 205 this.anonymousCommentingAllowed = anonymousCommentingAllowed; 206 } 207 208 215 public User getAuthor() { 216 return author; 217 } 218 219 223 public void setAuthor(User author) { 224 this.author = author; 225 } 226 227 233 public String getBody() { 234 return body; 235 } 236 237 241 public void setBody(String body) { 242 this.body = body; 243 } 244 245 253 public String getRawBody() { 254 return rawBody; 255 } 256 257 261 public void setRawBody(String rawBody) { 262 this.rawBody = rawBody; 263 } 264 265 275 public Set getCategories() { 276 return categories; 277 } 278 279 public void addCategory(Category category) { 280 categories.add(category); 281 } 282 283 public boolean containsCategory(Category category) { 284 285 Iterator it = getCategories().iterator(); 286 while (it.hasNext()) { 287 Category c = (Category) it.next(); 288 if (c.getId().longValue() == category.getId().longValue()) return true; 289 } 290 291 return false; 292 } 293 294 299 public Set getGlobalCategories() { 300 301 Set global = new TreeSet (new CategoryComparator()); 302 Iterator it = categories.iterator(); 303 304 while (it.hasNext()) { 305 Category c = (Category) it.next(); 306 if (c.getType() == Category.GLOBAL) global.add(c); 307 } 308 309 return global; 310 311 } 312 313 318 public Set getLocalCategories() { 319 Set local = new TreeSet (new CategoryComparator()); 320 Iterator it = categories.iterator(); 321 322 while (it.hasNext()) { 323 Category c = (Category) it.next(); 324 if (c.getType() == Category.LOCAL) local.add(c); 325 } 326 327 return local; 328 } 329 330 334 public void setCategories(Set categories) { 335 this.categories = categories; 336 } 337 338 344 public boolean getCommentingAllowed() { 345 return commentingAllowed; 346 } 347 348 351 public boolean isCommentingAllowed() { 352 return commentingAllowed; 353 } 354 355 359 public void setCommentingAllowed(boolean commentingAllowed) { 360 this.commentingAllowed = commentingAllowed; 361 } 362 363 373 public Set getComments() { 374 return comments; 375 } 376 377 381 public void setComments(Set comments) { 382 this.comments = comments; 383 } 384 385 public Set getFirstLevelComments() { 386 387 Set directAnswers = new TreeSet (new CommentComparator()); 388 389 for (Iterator it = comments.iterator(); it.hasNext();) { 390 Comment c = (Comment) it.next(); 391 if (c.getRepliedComment() == null) directAnswers.add(c); 392 } 393 394 return directAnswers; 395 396 } 397 398 404 public Date getCreateTime() { 405 return createTime; 406 } 407 408 412 public void setCreateTime(Date createTime) { 413 this.createTime = createTime; 414 } 415 416 422 public String getExcerpt() { 423 return excerpt; 424 } 425 426 430 public void setExcerpt(String exrept) { 431 this.excerpt = exrept; 432 } 433 434 440 public String getRawExcerpt() { 441 return rawExcerpt; 442 } 443 444 448 public void setRawExcerpt(String rawExcerpt) { 449 this.rawExcerpt = rawExcerpt; 450 } 451 452 458 public Long getId() { 459 return id; 460 } 461 462 466 public void setId(Long id) { 467 this.id = id; 468 } 469 470 476 public String getTitle() { 477 return title; 478 } 479 480 484 public void setTitle(String title) { 485 this.title = title; 486 } 487 488 495 public String getRawTitle() { 496 return rawTitle; 497 } 498 499 503 public void setRawTitle(String rawTitle) { 504 this.rawTitle = rawTitle; 505 } 506 507 513 public int getType() { 514 return type; 515 } 516 517 521 public void setType(int type) { 522 this.type = type; 523 } 524 525 531 public String getAuthorIP() { 532 return authorIP; 533 } 534 535 539 public void setAuthorIP(String authorIP) { 540 this.authorIP = authorIP; 541 } 542 543 549 public Userpic getUserpic() { 550 return userpic; 551 } 552 553 557 public void setUserpic(Userpic userpic) { 558 this.userpic = userpic; 559 } 560 561 571 public Set getTrackbacks() { 572 return trackbacks; 573 } 574 575 579 public void setTrackbacks(Set trackbacks) { 580 this.trackbacks = trackbacks; 581 } 582 583 588 public void validate() throws ValidationFailure { 589 591 } 595 596 603 public String getPermalink() { 604 605 String permalink = PERMALINK_FORMAT.format(createTime); 606 if (StringUtils.isNotEmpty(aliasname)) { return permalink + aliasname; } 607 608 return permalink + id; 609 610 } 611 612 } | Popular Tags |