1 25 26 package com.j2biz.blogunity.pojo; 27 28 import java.io.File ; 29 import java.io.Serializable ; 30 import java.util.Date ; 31 import java.util.HashSet ; 32 import java.util.Iterator ; 33 import java.util.Set ; 34 import java.util.TreeSet ; 35 36 import net.sf.hibernate.Validatable; 37 import net.sf.hibernate.ValidationFailure; 38 39 import org.apache.commons.logging.Log; 40 import org.apache.commons.logging.LogFactory; 41 42 import com.j2biz.blogunity.BlogunityManager; 43 import com.j2biz.blogunity.util.BlogUtils; 44 import com.j2biz.blogunity.util.CategoryComparator; 45 import com.j2biz.blogunity.util.EntryComparator; 46 import com.j2biz.blogunity.util.LinkComparator; 47 import com.j2biz.blogunity.util.RefererComparator; 48 import com.j2biz.blogunity.util.UserComparator; 49 import com.j2biz.blogunity.util.VisitedPageComparator; 50 51 61 public class Blog implements Validatable, Serializable { 62 65 private static final long serialVersionUID = 3546084648699312176L; 66 67 70 private static final Log log = LogFactory.getLog(Blog.class); 71 72 public static final int INDIVIDUAL_BLOG = 0; 73 74 public static final int COMMUNITY_BLOG = 1; 75 76 public static final int PUBLIC_COMMUNTIY = 0; 77 78 public static final int PRIVATE_COMMUNTIY = 1; 79 80 private Long id; 81 82 private String urlName; 83 84 private String fullName; 85 86 private String description; 87 88 private String keywords; 89 90 private Date createTime = new Date (); 91 92 private Date lastModified = new Date (); 93 94 private User founder; 95 96 private Set contributors = new TreeSet (new UserComparator()); 97 98 private Set waitingForAcceptanceUsers = new TreeSet (new UserComparator()); 99 100 private Set entries = new TreeSet (new EntryComparator()); 101 102 private Set calendarEntries = new HashSet (); 103 104 private Set categories = new TreeSet (new CategoryComparator()); 105 106 private Set links = new TreeSet (new LinkComparator()); 107 108 private int type = INDIVIDUAL_BLOG; 109 110 private int communityType; 111 112 private Set todayVisitedPages = new TreeSet (new VisitedPageComparator()); 113 114 private Set todayReferers = new TreeSet (new RefererComparator()); 115 116 private transient File mainDataDirectory; 117 118 private transient File themeDirectory; 119 120 private transient File indexesDirectory; 121 122 private transient File imagesDirectory; 123 124 private transient File filesDirectory; 125 126 private transient File logsDirectory; 127 128 131 public Blog() { 132 super(); 133 } 134 135 146 public Set getCategories() { 147 return categories; 148 } 149 150 154 public void setCategories(Set categories) { 155 this.categories = categories; 156 } 157 158 public void addCategory(Category category) { 159 categories.add(category); 160 } 161 162 167 public Set getGlobalCategories() { 168 169 Set global = new TreeSet (new CategoryComparator()); 170 Iterator it = categories.iterator(); 171 172 while (it.hasNext()) { 173 Category c = (Category) it.next(); 174 if (c.getType() == Category.GLOBAL) global.add(c); 175 } 176 177 return global; 178 179 } 180 181 186 public Set getLocalCategories() { 187 Set local = new TreeSet (new CategoryComparator()); 188 Iterator it = categories.iterator(); 189 190 while (it.hasNext()) { 191 Category c = (Category) it.next(); 192 if (c.getType() == Category.LOCAL) local.add(c); 193 } 194 195 return local; 196 } 197 198 208 public Set getContributors() { 209 return contributors; 210 } 211 212 216 public void setContributors(Set contributors) { 217 this.contributors = contributors; 218 } 219 220 public void addContributor(User contributor) { 221 contributors.add(contributor); 222 } 223 224 235 public Set getWaitingForAcceptanceUsers() { 236 return waitingForAcceptanceUsers; 237 } 238 239 243 public void setWaitingForAcceptanceUsers(Set waitingForAcceptanceUsers) { 244 this.waitingForAcceptanceUsers = waitingForAcceptanceUsers; 245 } 246 247 public void addWaitingForAcceptanceUser(User user) { 248 waitingForAcceptanceUsers.add(user); 249 } 250 251 257 public Date getCreateTime() { 258 return createTime; 259 } 260 261 265 public void setCreateTime(Date createTime) { 266 this.createTime = createTime; 267 } 268 269 275 public Date getLastModified() { 276 return lastModified; 277 } 278 279 283 public void setLastModified(Date lastModified) { 284 this.lastModified = lastModified; 285 } 286 287 293 public String getDescription() { 294 return description; 295 } 296 297 301 public void setDescription(String description) { 302 this.description = description; 303 } 304 305 311 public String getKeywords() { 312 return keywords; 313 } 314 315 319 public void setKeywords(String keywords) { 320 this.keywords = keywords; 321 } 322 323 333 public Set getEntries() { 334 return entries; 335 } 336 337 341 public void setEntries(Set entries) { 342 this.entries = entries; 343 } 344 345 public void addEntry(Entry entry) { 346 entries.add(entry); 347 } 348 349 355 public Long getId() { 356 return id; 357 } 358 359 363 public void setId(Long id) { 364 this.id = id; 365 } 366 367 373 public String getUrlName() { 374 return urlName; 375 } 376 377 381 public void setUrlName(String name) { 382 this.urlName = name; 383 } 384 385 391 public String getFullName() { 392 return fullName; 393 } 394 395 398 public void setFullName(String fullName) { 399 this.fullName = fullName; 400 } 401 402 408 public User getFounder() { 409 return founder; 410 } 411 412 416 public void setFounder(User founder) { 417 this.founder = founder; 418 } 419 420 431 public Set getLinks() { 432 433 return links; 434 } 435 436 440 public void setLinks(Set links) { 441 this.links = links; 442 } 443 444 454 public Set getCalendarEntries() { 455 return calendarEntries; 456 } 457 458 462 public void setCalendarEntries(Set calendarEntries) { 463 this.calendarEntries = calendarEntries; 464 } 465 466 public void addLink(Link link) { 467 links.add(link); 468 } 469 470 476 public int getType() { 477 return type; 478 } 479 480 484 public void setType(int type) { 485 this.type = type; 486 } 487 488 494 public int getCommunityType() { 495 return communityType; 496 } 497 498 502 public void setCommunityType(int communityType) { 503 this.communityType = communityType; 504 } 505 506 public boolean containsCategory(Category c) { 507 508 Iterator it = getCategories().iterator(); 509 while (it.hasNext()) { 510 Category bc = (Category) it.next(); 511 if (bc.getId().longValue() == c.getId().longValue()) return true; 512 513 } 514 515 return false; 516 } 517 518 public boolean containsLink(Link link) { 519 520 Iterator it = getLinks().iterator(); 521 while (it.hasNext()) { 522 Link bc = (Link) it.next(); 523 if (bc.getId().longValue() == link.getId().longValue()) return true; 524 525 } 526 527 return false; 528 } 529 530 533 public int getMaximalLinkOrder() { 534 int order = 0; 535 536 for (Iterator it = links.iterator(); it.hasNext();) { 537 Link l = (Link) it.next(); 538 if (l.getOrder() > order) order = l.getOrder(); 539 } 540 541 return order; 542 } 543 544 554 public Set getTodayReferers() { 555 return todayReferers; 556 } 557 558 561 public void setTodayReferers(Set todayReferers) { 562 this.todayReferers = todayReferers; 563 } 564 565 568 public void addTodayReferer(Referer referer) { 569 todayReferers.add(referer); 570 } 571 572 581 public Set getTodayVisitedPages() { 582 return todayVisitedPages; 583 } 584 585 588 public void setTodayVisitedPages(Set todayVisitedPages) { 589 this.todayVisitedPages = todayVisitedPages; 590 } 591 592 595 public void addTodayVisitedPage(VisitedPage page) { 596 todayVisitedPages.add(page); 597 } 598 599 public File getMainDataDirectory() { 600 601 if (mainDataDirectory == null) 602 mainDataDirectory = new File (BlogunityManager.getSystemConfiguration() 603 .getBlogsDirectory(), getUrlName()); 604 return mainDataDirectory; 605 606 } 607 608 public File getThemeDirectory() { 609 if (themeDirectory == null) themeDirectory = new File (getMainDataDirectory(), "theme"); 610 return themeDirectory; 611 } 612 613 public File getLogsDirectory() { 614 if (logsDirectory == null) logsDirectory = new File (getMainDataDirectory(), "logs"); 615 return logsDirectory; 616 } 617 618 public File getIndexesDirectory() { 619 if (indexesDirectory == null) indexesDirectory = new File (getMainDataDirectory(), "indexes"); 620 return indexesDirectory; 621 } 622 623 public File getImagesDirectory() { 624 if (imagesDirectory == null) imagesDirectory = new File (getMainDataDirectory(), "images"); 625 return imagesDirectory; 626 } 627 628 public File getFilesDirectory() { 629 if (filesDirectory == null) filesDirectory = new File (getMainDataDirectory(), "files"); 630 return filesDirectory; 631 } 632 633 638 public void validate() throws ValidationFailure { 639 640 if (!BlogUtils.getInstance().isValidBlogname(urlName)) 641 throw new ValidationFailure("Blog urlName is not valid!"); 642 643 if (type == INDIVIDUAL_BLOG) { 644 if (contributors != null && contributors.size() > 0) { throw new ValidationFailure( 645 "Individual blog can not contains contributors other than founder!"); } 646 } 647 } 648 649 } | Popular Tags |