1 18 19 package org.apache.roller.pojos; 20 21 import java.io.Serializable ; 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.Date ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Locale ; 28 import java.util.Map ; 29 import java.util.TimeZone ; 30 import java.util.TreeMap ; 31 import org.apache.commons.lang.StringUtils; 32 import org.apache.roller.RollerException; 33 import org.apache.roller.model.RefererManager; 34 import org.apache.roller.model.RollerFactory; 35 import org.apache.roller.util.PojoUtil; 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 import org.apache.roller.ThemeNotFoundException; 39 import org.apache.roller.config.RollerRuntimeConfig; 40 import org.apache.roller.model.BookmarkManager; 41 import org.apache.roller.model.PluginManager; 42 import org.apache.roller.model.Roller; 43 import org.apache.roller.model.ThemeManager; 44 import org.apache.roller.model.UserManager; 45 import org.apache.roller.model.WeblogManager; 46 47 59 public class WebsiteData extends org.apache.roller.pojos.PersistentObject 60 implements Serializable { 61 public static final long serialVersionUID = 206437645033737127L; 62 63 private static Log log = LogFactory.getLog(WebsiteData.class); 64 65 private String id = null; 67 private String handle = null; 68 private String name = null; 69 private String description = null; 70 private String defaultPageId = "dummy"; 71 private String weblogDayPageId = "dummy"; 72 private Boolean enableBloggerApi = Boolean.TRUE; 73 private String editorPage = null; 74 private String blacklist = null; 75 private Boolean allowComments = Boolean.TRUE; 76 private Boolean emailComments = Boolean.FALSE; 77 private String emailFromAddress = null; 78 private String emailAddress = null; 79 private String editorTheme = null; 80 private String locale = null; 81 private String timeZone = null; 82 private String defaultPlugins = null; 83 private Boolean enabled = Boolean.TRUE; 84 private Boolean active = Boolean.TRUE; 85 private Date dateCreated = new java.util.Date (); 86 private Boolean defaultAllowComments = Boolean.TRUE; 87 private int defaultCommentDays = 0; 88 private Boolean moderateComments = Boolean.FALSE; 89 private int entryDisplayCount = 15; 90 private Date lastModified = new Date (); 91 private String pageModels = new String (); 92 private boolean enableMultiLang = false; 93 private boolean showAllLangs = true; 94 95 96 private UserData creator = null; 98 private List permissions = new ArrayList (); 99 private WeblogCategoryData bloggerCategory = null; 100 private WeblogCategoryData defaultCategory = null; 101 102 private Map initializedPlugins = null; 103 104 public WebsiteData() { 105 } 106 107 public WebsiteData( 108 String handle, 109 UserData creator, 110 String name, 111 String desc, 112 String email, 113 String emailFrom, 114 String editorTheme, 115 String locale, 116 String timeZone) { 117 118 this.handle = handle; 119 this.creator = creator; 120 this.name = name; 121 this.description = desc; 122 this.emailAddress = email; 123 this.emailFromAddress = emailFrom; 124 this.editorTheme = editorTheme; 125 this.locale = locale; 126 this.timeZone = timeZone; 127 } 128 129 public WebsiteData(WebsiteData otherData) { 130 this.setData(otherData); 131 } 132 133 139 public List getPermissions() { 140 return permissions; 141 } 142 public void setPermissions(List perms) { 143 permissions = perms; 144 } 145 148 public void removePermission(PermissionsData perms) { 149 permissions.remove(perms); 150 } 151 152 155 public Template getDefaultPage() throws RollerException { 156 157 Template template = null; 158 159 if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) { 162 try { 163 ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager(); 164 Theme usersTheme = themeMgr.getTheme(this.editorTheme); 165 166 template = usersTheme.getTemplate("Weblog"); 169 170 } catch(ThemeNotFoundException tnfe) { 171 log.error(tnfe); 173 } 174 } 175 176 if(template == null) { 178 UserManager userMgr = RollerFactory.getRoller().getUserManager(); 179 template = userMgr.getPage(this.defaultPageId); 180 } 181 182 if(template != null) 183 log.debug("returning default template id ["+template.getId()+"]"); 184 185 return template; 186 } 187 188 189 192 public Template getPageById(String id) throws RollerException { 193 194 if(id == null) 195 return null; 196 197 Template template = null; 198 199 if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) { 202 203 String [] split = id.split(":", 2); 206 207 if(split.length == 2 && split[0].equals(this.editorTheme)) { 210 try { 211 ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager(); 212 Theme usersTheme = themeMgr.getTheme(this.editorTheme); 213 template = usersTheme.getTemplate(split[1]); 214 215 } catch(ThemeNotFoundException tnfe) { 216 log.error(tnfe); 218 } 219 } 220 221 } 222 223 if(template == null) { 225 UserManager userMgr = RollerFactory.getRoller().getUserManager(); 226 template = userMgr.getPageByName(this, name); 227 } 228 229 return template; 230 } 231 232 233 237 public Template getPageByName(String name) throws RollerException { 238 239 if(name == null) 240 return null; 241 242 log.debug("looking up template ["+name+"]"); 243 244 Template template = null; 245 246 if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) { 249 250 try { 251 ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager(); 252 Theme usersTheme = themeMgr.getTheme(this.editorTheme); 253 template = usersTheme.getTemplate(name); 254 255 } catch(ThemeNotFoundException tnfe) { 256 log.error(tnfe); 258 } 259 260 } 261 262 if(template == null) { 264 UserManager userMgr = RollerFactory.getRoller().getUserManager(); 265 template = userMgr.getPageByName(this, name); 266 } 267 268 if(template != null) 269 log.debug("returning template ["+template.getId()+"]"); 270 271 return template; 272 } 273 274 275 279 public Template getPageByLink(String link) throws RollerException { 280 281 if(link == null) 282 return null; 283 284 log.debug("looking up template ["+link+"]"); 285 286 Template template = null; 287 288 if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) { 291 292 try { 293 ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager(); 294 Theme usersTheme = themeMgr.getTheme(this.editorTheme); 295 template = usersTheme.getTemplateByLink(link); 296 297 } catch(ThemeNotFoundException tnfe) { 298 log.error(tnfe); 300 } 301 302 } 303 304 if(template == null) { 306 UserManager userMgr = RollerFactory.getRoller().getUserManager(); 307 template = userMgr.getPageByLink(this, link); 308 } 309 310 if(template != null) 311 log.debug("returning template ["+template.getId()+"]"); 312 313 return template; 314 } 315 316 317 321 public List getPages() { 322 323 Map pages = new TreeMap (); 324 325 try { 327 Template template = null; 328 UserManager userMgr = RollerFactory.getRoller().getUserManager(); 329 Iterator dbPages = userMgr.getPages(this).iterator(); 330 while(dbPages.hasNext()) { 331 template = (Template) dbPages.next(); 332 pages.put(template.getName(), template); 333 } 334 } catch(Exception e) { 335 log.error(e); 337 } 338 339 340 if (this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) { 342 try { 343 Template template = null; 344 ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager(); 345 Theme usersTheme = themeMgr.getTheme(this.editorTheme); 346 Iterator themePages = usersTheme.getTemplates().iterator(); 347 while(themePages.hasNext()) { 348 template = (Template) themePages.next(); 349 350 pages.put(template.getName(), template); 353 } 354 } catch(Exception e) { 355 log.error(e); 357 } 358 } 359 360 return new ArrayList (pages.values()); 361 } 362 363 364 372 public String getId() { 373 return this.id; 374 } 375 376 377 public void setId(String id) { 378 this.id = id; 379 } 380 381 387 public String getHandle() { 388 return this.handle; 389 } 390 391 392 public void setHandle(String handle) { 393 this.handle = handle; 394 } 395 396 403 public String getName() { 404 return this.name; 405 } 406 407 408 public void setName(String name) { 409 this.name = name; 410 } 411 412 419 public String getDescription() { 420 return this.description; 421 } 422 423 424 public void setDescription(String description) { 425 this.description = description; 426 } 427 428 435 public org.apache.roller.pojos.UserData getCreator() { 436 return creator; 437 } 438 439 440 public void setCreator( org.apache.roller.pojos.UserData ud ) { 441 creator = ud; 442 } 443 444 449 public String getDefaultPageId() { 450 return this.defaultPageId; 451 } 452 453 456 public void setDefaultPageId(String defaultPageId) { 457 this.defaultPageId = defaultPageId; 458 } 459 460 466 public String getWeblogDayPageId() { 467 return this.weblogDayPageId; 468 } 469 470 474 public void setWeblogDayPageId(String weblogDayPageId) { 475 this.weblogDayPageId = weblogDayPageId; 476 } 477 478 483 public Boolean getEnableBloggerApi() { 484 return this.enableBloggerApi; 485 } 486 487 488 public void setEnableBloggerApi(Boolean enableBloggerApi) { 489 this.enableBloggerApi = enableBloggerApi; 490 } 491 492 497 public WeblogCategoryData getBloggerCategory() { 498 return bloggerCategory; 499 } 500 501 502 public void setBloggerCategory(WeblogCategoryData bloggerCategory) { 503 this.bloggerCategory = bloggerCategory; 504 } 505 506 515 public WeblogCategoryData getDefaultCategory() { 516 return defaultCategory; 517 } 518 519 520 public void setDefaultCategory(WeblogCategoryData defaultCategory) { 521 this.defaultCategory = defaultCategory; 522 } 523 524 529 public String getEditorPage() { 530 return this.editorPage; 531 } 532 533 534 public void setEditorPage(String editorPage) { 535 this.editorPage = editorPage; 536 } 537 538 543 public String getBlacklist() { 544 return this.blacklist; 545 } 546 547 548 public void setBlacklist(String blacklist) { 549 this.blacklist = blacklist; 550 } 551 552 557 public Boolean getAllowComments() { 558 return this.allowComments; 559 } 560 561 562 public void setAllowComments(Boolean allowComments) { 563 this.allowComments = allowComments; 564 } 565 566 571 public Boolean getDefaultAllowComments() { 572 return defaultAllowComments; 573 } 574 575 576 public void setDefaultAllowComments(Boolean defaultAllowComments) { 577 this.defaultAllowComments = defaultAllowComments; 578 } 579 580 585 public int getDefaultCommentDays() { 586 return defaultCommentDays; 587 } 588 589 590 public void setDefaultCommentDays(int defaultCommentDays) { 591 this.defaultCommentDays = defaultCommentDays; 592 } 593 594 599 public Boolean getModerateComments() { 600 return moderateComments; 601 } 602 603 604 public void setModerateComments(Boolean moderateComments) { 605 this.moderateComments = moderateComments; 606 } 607 608 613 public Boolean getEmailComments() { 614 return this.emailComments; 615 } 616 617 618 public void setEmailComments(Boolean emailComments) { 619 this.emailComments = emailComments; 620 } 621 622 627 public String getEmailFromAddress() { 628 return this.emailFromAddress; 629 } 630 631 632 public void setEmailFromAddress(String emailFromAddress) { 633 this.emailFromAddress = emailFromAddress; 634 } 635 636 641 public String getEmailAddress() { 642 return this.emailAddress; 643 } 644 645 646 public void setEmailAddress(String emailAddress) { 647 this.emailAddress = emailAddress; 648 } 649 650 657 public String getEditorTheme() { 658 return this.editorTheme; 659 } 660 661 662 public void setEditorTheme(String editorTheme) { 663 this.editorTheme = editorTheme; 664 } 665 666 673 public String getLocale() { 674 return this.locale; 675 } 676 677 678 public void setLocale(String locale) { 679 this.locale = locale; 680 } 681 682 689 public String getTimeZone() { 690 return this.timeZone; 691 } 692 693 694 public void setTimeZone(String timeZone) { 695 this.timeZone = timeZone; 696 } 697 698 703 public Date getDateCreated() { 704 if (dateCreated == null) { 705 return null; 706 } else { 707 return (Date )dateCreated.clone(); 708 } 709 } 710 711 public void setDateCreated(final Date date) { 712 if (date != null) { 713 dateCreated = (Date )date.clone(); 714 } else { 715 dateCreated = null; 716 } 717 } 718 719 726 public String getDefaultPlugins() { 727 return defaultPlugins; 728 } 729 730 731 public void setDefaultPlugins(String string) { 732 defaultPlugins = string; 733 } 734 735 public String toString() { 736 StringBuffer str = new StringBuffer ("{"); 737 738 str.append("id=" + id + " " + "name=" + name + " " + "description=" + 739 description + " " + 740 "defaultPageId=" + defaultPageId + " " + 741 "weblogDayPageId=" + weblogDayPageId + " " + 742 "enableBloggerApi=" + enableBloggerApi + " " + 743 "bloggerCategory=" + bloggerCategory + " " + 744 "defaultCategory=" + defaultCategory + " " + 745 "editorPage=" + editorPage + " " + 746 "blacklist=" + blacklist + " " + 747 "allowComments=" + allowComments + " " + 748 "emailAddress=" + emailAddress + " " + 749 "emailComments=" + emailComments + " " + 750 "emailFromAddress=" + emailFromAddress + " " + 751 "editorTheme=" + editorTheme + " " + 752 "locale=" + locale + " " + 753 "timeZone=" + timeZone + " " + 754 "defaultPlugins=" + defaultPlugins); 755 str.append('}'); 756 757 return (str.toString()); 758 } 759 760 public boolean equals(Object pOther) { 761 if (pOther instanceof WebsiteData) { 762 WebsiteData lTest = (WebsiteData) pOther; 763 boolean lEquals = true; 764 lEquals = PojoUtil.equals(lEquals, this.getId(), lTest.getId()); 765 lEquals = PojoUtil.equals(lEquals, this.getName(), lTest.getName()); 766 lEquals = PojoUtil.equals(lEquals, this.getDescription(), lTest.getDescription()); 767 lEquals = PojoUtil.equals(lEquals, this.getCreator(), lTest.getCreator()); 768 lEquals = PojoUtil.equals(lEquals, this.getDefaultPageId(), lTest.getDefaultPageId()); 769 lEquals = PojoUtil.equals(lEquals, this.getWeblogDayPageId(), lTest.getWeblogDayPageId()); 770 lEquals = PojoUtil.equals(lEquals, this.getEnableBloggerApi(), lTest.getEnableBloggerApi()); 771 lEquals = PojoUtil.equals(lEquals, this.getBloggerCategory(), lTest.getBloggerCategory()); 772 lEquals = PojoUtil.equals(lEquals, this.getDefaultCategory(), lTest.getDefaultCategory()); 773 lEquals = PojoUtil.equals(lEquals, this.getEditorPage(), lTest.getEditorPage()); 774 lEquals = PojoUtil.equals(lEquals, this.getBlacklist(), lTest.getBlacklist()); 775 lEquals = PojoUtil.equals(lEquals, this.getAllowComments(), lTest.getAllowComments()); 776 lEquals = PojoUtil.equals(lEquals, this.getEmailComments(), lTest.getEmailComments()); 777 lEquals = PojoUtil.equals(lEquals, this.getEmailAddress(), lTest.getEmailAddress()); 778 lEquals = PojoUtil.equals(lEquals, this.getEmailFromAddress(), lTest.getEmailFromAddress()); 779 lEquals = PojoUtil.equals(lEquals, this.getEditorTheme(), lTest.getEditorTheme()); 780 lEquals = PojoUtil.equals(lEquals, this.getLocale(), lTest.getLocale()); 781 lEquals = PojoUtil.equals(lEquals, this.getTimeZone(), lTest.getTimeZone()); 782 lEquals = PojoUtil.equals(lEquals, this.getDefaultPlugins(), lTest.getDefaultPlugins()); 783 return lEquals; 784 } else { 785 return false; 786 } 787 } 788 789 public int hashCode() { 790 int result = 17; 791 result = PojoUtil.addHashCode(result, this.id); 792 result = PojoUtil.addHashCode(result, this.name); 793 result = PojoUtil.addHashCode(result, this.description); 794 result = PojoUtil.addHashCode(result, this.creator); 795 result = PojoUtil.addHashCode(result, this.defaultPageId); 796 result = PojoUtil.addHashCode(result, this.weblogDayPageId); 797 result = PojoUtil.addHashCode(result, this.enableBloggerApi); 798 result = PojoUtil.addHashCode(result, this.editorPage); 801 result = PojoUtil.addHashCode(result, this.blacklist); 802 result = PojoUtil.addHashCode(result, this.allowComments); 803 result = PojoUtil.addHashCode(result, this.emailComments); 804 result = PojoUtil.addHashCode(result, this.emailAddress); 805 result = PojoUtil.addHashCode(result, this.emailFromAddress); 806 result = PojoUtil.addHashCode(result, this.editorTheme); 807 result = PojoUtil.addHashCode(result, this.locale); 808 result = PojoUtil.addHashCode(result, this.timeZone); 809 result = PojoUtil.addHashCode(result, this.defaultPlugins); 810 811 return result; 812 } 813 814 817 public void setData(org.apache.roller.pojos.PersistentObject otherData) { 818 WebsiteData other = (WebsiteData)otherData; 819 820 this.id = other.getId(); 821 this.name = other.getName(); 822 this.handle = other.getHandle(); 823 this.description = other.getDescription(); 824 this.creator = other.getCreator(); 825 this.defaultPageId = other.getDefaultPageId(); 826 this.weblogDayPageId = other.getWeblogDayPageId(); 827 this.enableBloggerApi = other.getEnableBloggerApi(); 828 this.bloggerCategory = other.getBloggerCategory(); 829 this.defaultCategory = other.getDefaultCategory(); 830 this.editorPage = other.getEditorPage(); 831 this.blacklist = other.getBlacklist(); 832 this.allowComments = other.getAllowComments(); 833 this.emailComments = other.getEmailComments(); 834 this.emailAddress = other.getEmailAddress(); 835 this.emailFromAddress = other.getEmailFromAddress(); 836 this.editorTheme = other.getEditorTheme(); 837 this.locale = other.getLocale(); 838 this.timeZone = other.getTimeZone(); 839 this.defaultPlugins = other.getDefaultPlugins(); 840 this.enabled = other.getEnabled(); 841 this.dateCreated = other.getDateCreated(); 842 this.entryDisplayCount = other.getEntryDisplayCount(); 843 this.active = other.getActive(); 844 this.lastModified = other.getLastModified(); 845 } 846 847 854 public Locale getLocaleInstance() { 855 if (locale != null) { 856 String [] localeStr = StringUtils.split(locale,"_"); 857 if (localeStr.length == 1) { 858 if (localeStr[0] == null) localeStr[0] = ""; 859 return new Locale (localeStr[0]); 860 } else if (localeStr.length == 2) { 861 if (localeStr[0] == null) localeStr[0] = ""; 862 if (localeStr[1] == null) localeStr[1] = ""; 863 return new Locale (localeStr[0], localeStr[1]); 864 } else if (localeStr.length == 3) { 865 if (localeStr[0] == null) localeStr[0] = ""; 866 if (localeStr[1] == null) localeStr[1] = ""; 867 if (localeStr[2] == null) localeStr[2] = ""; 868 return new Locale (localeStr[0], localeStr[1], localeStr[2]); 869 } 870 } 871 return Locale.getDefault(); 872 } 873 874 881 public TimeZone getTimeZoneInstance() { 882 if (timeZone == null) { 883 if (TimeZone.getDefault() != null) { 884 this.setTimeZone( TimeZone.getDefault().getID() ); 885 } else { 886 this.setTimeZone("America/New_York"); 887 } 888 } 889 return TimeZone.getTimeZone(timeZone); 890 } 891 892 893 896 public boolean hasUserPermissions(UserData user, short mask) { 897 PermissionsData userPerms = null; 899 Iterator iter = getPermissions().iterator(); 900 while (iter.hasNext()) { 901 PermissionsData perms = (PermissionsData) iter.next(); 902 if (perms.getUser().getId().equals(user.getId())) { 903 userPerms = perms; 904 break; 905 } 906 } 907 if (userPerms != null && !userPerms.isPending()) { 909 if (userPerms != null && (userPerms.getPermissionMask() & mask) == mask) { 910 return true; 911 } 912 } 913 if (user != null && user.hasRole("admin")) return true; 915 return false; 916 } 917 918 919 public int getUserCount() { 920 return getPermissions().size(); 921 } 922 923 924 private int userCount = 0; 925 public void setUserCount(int userCount) { 926 } 928 929 public int getAdminUserCount() { 930 int count = 0; 931 PermissionsData userPerms = null; 932 Iterator iter = getPermissions().iterator(); 933 while (iter.hasNext()) { 934 PermissionsData perms = (PermissionsData) iter.next(); 935 if (perms.getPermissionMask() == PermissionsData.ADMIN) { 936 count++; 937 } 938 } 939 return count; 940 } 941 942 943 private int adminUserCount = 0; 944 public void setAdminUserCount(int adminUserCount) { 945 } 947 948 949 954 public int getEntryDisplayCount() { 955 return entryDisplayCount; 956 } 957 958 961 public void setEntryDisplayCount(int entryDisplayCount) { 962 this.entryDisplayCount = entryDisplayCount; 963 } 964 965 972 public Boolean getEnabled() { 973 return this.enabled; 974 } 975 976 977 public void setEnabled(Boolean enabled) { 978 this.enabled = enabled; 979 } 980 981 989 public Boolean getActive() { 990 return active; 991 } 992 993 public void setActive(Boolean active) { 994 this.active = active; 995 } 996 997 1000 public boolean getCommentModerationRequired() { 1001 return (getModerateComments().booleanValue() 1002 || RollerRuntimeConfig.getBooleanProperty("users.moderation.required")); 1003 } 1004 1005 1006 public void setCommentModerationRequired(boolean modRequired) {} 1007 1008 1009 1022 public Date getLastModified() { 1023 return lastModified; 1024 } 1025 1026 public void setLastModified(Date lastModified) { 1027 this.lastModified = lastModified; 1028 } 1029 1030 1031 1040 public boolean isEnableMultiLang() { 1041 return enableMultiLang; 1042 } 1043 1044 public void setEnableMultiLang(boolean enableMultiLang) { 1045 this.enableMultiLang = enableMultiLang; 1046 } 1047 1048 1049 1059 public boolean isShowAllLangs() { 1060 return showAllLangs; 1061 } 1062 1063 public void setShowAllLangs(boolean showAllLangs) { 1064 this.showAllLangs = showAllLangs; 1065 } 1066 1067 1068 1071 public String getURL() { 1072 String relPath = RollerRuntimeConfig.getRelativeContextURL(); 1074 return relPath + "/" + getHandle(); 1075 } 1077 public void setURL(String url) { 1078 } 1080 1081 1082 1085 public String getAbsoluteURL() { 1086 String relPath = RollerRuntimeConfig.getAbsoluteContextURL(); 1088 return relPath + "/" + getHandle(); 1089 } 1091 public void setAbsoluteURL(String url) { 1092 } 1094 1095 1096 1103 public String getPageModels() { 1104 return pageModels; 1105 } 1106 public void setPageModels(String pageModels) { 1107 this.pageModels = pageModels; 1108 } 1109 1110 1111 1114 public Map getInitializedPlugins() { 1115 if (initializedPlugins == null) { 1116 try { 1117 Roller roller = RollerFactory.getRoller(); 1118 PluginManager ppmgr = roller.getPagePluginManager(); 1119 initializedPlugins = ppmgr.getWeblogEntryPlugins(this); 1120 } catch (Exception e) { 1121 this.log.error("ERROR: initializing plugins"); 1122 } 1123 } 1124 return initializedPlugins; 1125 } 1126 1127 1128 1132 public List getWeblogCategories() { 1133 List ret = new ArrayList (); 1134 try { 1135 WeblogCategoryData category = this.getDefaultCategory(); 1136 ret = category.getWeblogCategories(); 1137 } catch (RollerException e) { 1138 log.error("ERROR: fetching categories", e); 1139 } 1140 return ret; 1141 } 1142 1143 1144 1147 public List getWeblogCategories(String categoryPath) { 1148 List ret = new ArrayList (); 1149 try { 1150 Roller roller = RollerFactory.getRoller(); 1151 WeblogManager wmgr = roller.getWeblogManager(); 1152 WeblogCategoryData category = null; 1153 if (categoryPath != null && !categoryPath.equals("nil")) { 1154 category = wmgr.getWeblogCategoryByPath(this, null, categoryPath); 1155 } else { 1156 category = this.getDefaultCategory(); 1157 } 1158 ret = category.getWeblogCategories(); 1159 } catch (RollerException e) { 1160 log.error("ERROR: fetching categories for path: " + categoryPath, e); 1161 } 1162 return ret; 1163 } 1164 1165 1166 1169 public WeblogCategoryData getWeblogCategory(String categoryPath) { 1170 WeblogCategoryData category = null; 1171 try { 1172 Roller roller = RollerFactory.getRoller(); 1173 WeblogManager wmgr = roller.getWeblogManager(); 1174 if (categoryPath != null && !categoryPath.equals("nil")) { 1175 category = wmgr.getWeblogCategoryByPath(this, null, categoryPath); 1176 } else { 1177 category = this.getDefaultCategory(); 1178 } 1179 } catch (RollerException e) { 1180 log.error("ERROR: fetching category at path: " + categoryPath, e); 1181 } 1182 return category; 1183 } 1184 1185 1186 1194 public List getRecentWeblogEntries(String cat, int length) { 1195 if (cat != null && "nil".equals(cat)) cat = null; 1196 if (length > 100) length = 100; 1197 List recentEntries = new ArrayList (); 1198 if (length < 1) return recentEntries; 1199 try { 1200 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 1201 recentEntries = wmgr.getWeblogEntries( 1202 this, 1203 null, null, new Date (), cat, WeblogEntryData.PUBLISHED, 1208 "pubTime", null, 1210 0, 1211 length); 1212 } catch (RollerException e) { 1213 log.error("ERROR: getting recent entries", e); 1214 } 1215 return recentEntries; 1216 } 1217 1218 1219 1226 public List getRecentComments(int length) { 1227 if (length > 100) length = 100; 1228 List recentComments = new ArrayList (); 1229 if (length < 1) return recentComments; 1230 try { 1231 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 1232 recentComments = wmgr.getComments( 1233 this, 1234 null, null, null, null, null, Boolean.TRUE, Boolean.FALSE, true, 0, length); } catch (RollerException e) { 1245 log.error("ERROR: getting recent comments", e); 1246 } 1247 return recentComments; 1248 } 1249 1250 1251 1258 public FolderData getBookmarkFolder(String folderName) { 1259 FolderData ret = null; 1260 try { 1261 Roller roller = RollerFactory.getRoller(); 1262 BookmarkManager bmgr = roller.getBookmarkManager(); 1263 if (folderName == null || folderName.equals("nil") || folderName.trim().equals("/")) { 1264 return bmgr.getRootFolder(this); 1265 } else { 1266 return bmgr.getFolder(this, folderName); 1267 } 1268 } catch (RollerException re) { 1269 log.error("ERROR: fetching folder for weblog", re); 1270 } 1271 return ret; 1272 } 1273 1274 1275 1279 public List getTodaysReferrers() { 1280 List referers = null; 1281 try { 1282 Roller roller = RollerFactory.getRoller(); 1283 RefererManager rmgr = roller.getRefererManager(); 1284 return rmgr.getTodaysReferers(this); 1285 1286 } catch (RollerException e) { 1287 log.error("PageModel getTodaysReferers()", e); 1288 } 1289 return (referers == null ? Collections.EMPTY_LIST : referers); 1290 } 1291 1292 1293 public void setTodaysReferrers(List ignored) {} 1294 1295 1299 public int getTodaysHits() { 1300 try { 1301 Roller roller = RollerFactory.getRoller(); 1302 RefererManager rmgr = roller.getRefererManager(); 1303 return rmgr.getDayHits(this); 1304 } catch (RollerException e) { 1305 log.error("PageModel getTotalHits()", e); 1306 } 1307 return 0; 1308 } 1309 1310 1311 public void setTodaysHits(int ignored) {} 1312} 1313 1314 | Popular Tags |