File Source: Weblog.java
/*
P/P * Method: void readObject(ObjectInputStream)
*/
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18
19 package org.apache.roller.weblogger.pojos;
20
21 import java.io.Serializable;
22 import java.util.ArrayList;
23 import java.util.Calendar;
24 import java.util.Collections;
25 import java.util.Date;
26 import java.util.HashSet;
27 import java.util.Iterator;
28 import java.util.List;
29 import java.util.Locale;
30 import java.util.Map;
31 import java.util.Set;
32 import java.util.TimeZone;
33 import org.apache.commons.lang.StringUtils;
34 import org.apache.commons.lang.builder.EqualsBuilder;
35 import org.apache.commons.lang.builder.HashCodeBuilder;
36 import org.apache.roller.weblogger.WebloggerException;
37 import org.apache.roller.weblogger.business.referrers.RefererManager;
38 import org.apache.roller.weblogger.business.WebloggerFactory;
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41 import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
42 import org.apache.roller.weblogger.business.BookmarkManager;
43 import org.apache.roller.weblogger.business.plugins.PluginManager;
44 import org.apache.roller.weblogger.business.Weblogger;
45 import org.apache.roller.weblogger.business.themes.ThemeManager;
46 import org.apache.roller.weblogger.business.WeblogManager;
47 import org.apache.roller.util.UUIDGenerator;
48 import org.apache.roller.weblogger.util.I18nUtils;
49
50
51 /**
52 * Website has many-to-many association with users. Website has one-to-many and
53 * one-direction associations with weblog entries, weblog categories, folders and
54 * other objects. Use UserManager to create, fetch, update and retreive websites.
55 *
56 * @author David M Johnson
57 */
58 public class Weblog implements Serializable {
59
60 public static final long serialVersionUID = 206437645033737127L;
61
/*
P/P * Method: org.apache.roller.weblogger.pojos.Weblog__static_init
*/
62 private static Log log = LogFactory.getLog(Weblog.class);
63
64 // Simple properties
65 private String id = UUIDGenerator.generateUUID();
66 private String handle = null;
67 private String name = null;
68 private String description = null;
69 private String defaultPageId = "dummy";
70 private String weblogDayPageId = "dummy";
71 private Boolean enableBloggerApi = Boolean.TRUE;
72 private String editorPage = null;
73 private String blacklist = null;
74 private Boolean allowComments = Boolean.TRUE;
75 private Boolean emailComments = Boolean.FALSE;
76 private String emailFromAddress = null;
77 private String emailAddress = null;
78 private String editorTheme = null;
79 private String locale = null;
80 private String timeZone = null;
81 private String defaultPlugins = null;
82 private Boolean enabled = Boolean.TRUE;
83 private Boolean active = Boolean.TRUE;
84 private Date dateCreated = new java.util.Date();
85 private Boolean defaultAllowComments = Boolean.TRUE;
86 private int defaultCommentDays = 0;
87 private Boolean moderateComments = Boolean.FALSE;
88 private int entryDisplayCount = 15;
89 private Date lastModified = new Date();
90 private String pageModels = new String();
91 private boolean enableMultiLang = false;
92 private boolean showAllLangs = true;
93 private String customStylesheetPath = null;
94 private String iconPath = null;
95 private String about = null;
96
97
98 // Associated objects
99 private User creator = null;
100 private List permissions = new ArrayList();
101 private WeblogCategory bloggerCategory = null;
102 private WeblogCategory defaultCategory = null;
103
104 private Map initializedPlugins = null;
105
/*
P/P * Method: void org.apache.roller.weblogger.pojos.Weblog()
*/
106 public Weblog() {
107 }
108
109 public Weblog(
110 String handle,
111 User creator,
112 String name,
113 String desc,
114 String email,
115 String emailFrom,
116 String editorTheme,
117 String locale,
/*
P/P * Method: void org.apache.roller.weblogger.pojos.Weblog(String, User, String, String, String, String, String, String, String)
*/
118 String timeZone) {
119
120 this.handle = handle;
121 this.creator = creator;
122 this.name = name;
123 this.description = desc;
124 this.emailAddress = email;
125 this.emailFromAddress = emailFrom;
126 this.editorTheme = editorTheme;
127 this.locale = locale;
128 this.timeZone = timeZone;
129 }
130
131 //------------------------------------------------------- Good citizenship
132
133 public String toString() {
/*
P/P * Method: String toString()
*/
134 StringBuffer buf = new StringBuffer();
135 buf.append("{");
136 buf.append(this.id);
137 buf.append(", ").append(this.handle);
138 buf.append(", ").append(this.name);
139 buf.append(", ").append(this.emailAddress);
140 buf.append(", ").append(this.locale);
141 buf.append(", ").append(this.timeZone);
142 buf.append("}");
143 return buf.toString();
144 }
145
146 public boolean equals(Object other) {
/*
P/P * Method: bool equals(Object)
*/
147 if (other == this) return true;
148 if (other instanceof Weblog != true) return false;
149 Weblog o = (Weblog)other;
150 return new EqualsBuilder()
151 .append(getHandle(), o.getHandle())
152 .isEquals();
153 }
154
155 public int hashCode() {
/*
P/P * Method: int hashCode()
*/
156 return new HashCodeBuilder()
157 .append(getHandle())
158 .toHashCode();
159 }
160
161 /**
162 * @hibernate.bag lazy="true" inverse="true" cascade="delete"
163 * @hibernate.collection-key column="website_id"
164 * @hibernate.collection-one-to-many
165 * class="org.apache.roller.weblogger.pojos.WeblogPermission"
166 */
167 public List getPermissions() {
/*
P/P * Method: List pcgetPermissions()
*/
168 return permissions;
169 }
170 public void setPermissions(List perms) {
/*
P/P * Method: void pcsetPermissions(List)
*/
171 permissions = perms;
172 }
173 /**
174 * Remove permission from collection.
175 */
176 public void removePermission(WeblogPermission perms) {
/*
P/P * Method: void removePermission(WeblogPermission)
*/
177 permissions.remove(perms);
178 }
179
180
181 /**
182 * Get the Theme object in use by this weblog, or null if no theme selected.
183 */
184 public WeblogTheme getTheme() {
185 try {
186 // let the ThemeManager handle it
/*
P/P * Method: WeblogTheme getTheme()
*/
187 ThemeManager themeMgr = WebloggerFactory.getWeblogger().getThemeManager();
188 return themeMgr.getTheme(this);
189 } catch (WebloggerException ex) {
190 log.error("Error getting theme for weblog - "+getHandle(), ex);
191 }
192
193 // TODO: maybe we should return a default theme in this case?
194 return null;
195 }
196
197
198 /**
199 * Lookup the default page for this website.
200 */
201 public ThemeTemplate getDefaultPage() throws WebloggerException {
202
203 // look for the page in our Theme
/*
P/P * Method: ThemeTemplate getDefaultPage()
*/
204 Theme weblogTheme = getTheme();
205 if(weblogTheme != null) {
206 return weblogTheme.getDefaultTemplate();
207 }
208
209 return null;
210 }
211
212
213 /**
214 * Id of the Website.
215 *
216 * @roller.wrapPojoMethod type="simple"
217 * @ejb:persistent-field
218 * @hibernate.id column="id"
219 * generator-class="assigned"
220 */
221 public String getId() {
/*
P/P * Method: String pcgetId()
*/
222 return this.id;
223 }
224
225 /** @ejb:persistent-field */
226 public void setId(String id) {
/*
P/P * Method: void pcsetId(String)
*/
227 this.id = id;
228 }
229
230 /**
231 * Short URL safe string that uniquely identifies the website.
232 * @ejb:persistent-field
233 * @hibernate.property column="handle" non-null="true" unique="true"
234 * @roller.wrapPojoMethod type="simple"
235 */
236 public String getHandle() {
/*
P/P * Method: String pcgetHandle()
*/
237 return this.handle;
238 }
239
240 /** @ejb:persistent-field */
241 public void setHandle(String handle) {
/*
P/P * Method: void pcsetHandle(String)
*/
242 this.handle = handle;
243 }
244
245 /**
246 * Name of the Website.
247 *
248 * @roller.wrapPojoMethod type="simple"
249 * @ejb:persistent-field
250 * @hibernate.property column="name" non-null="true" unique="false"
251 */
252 public String getName() {
/*
P/P * Method: String pcgetName()
*/
253 return this.name;
254 }
255
256 /** @ejb:persistent-field */
257 public void setName(String name) {
/*
P/P * Method: void pcsetName(String)
*/
258 this.name = name;
259 }
260
261 /**
262 * Description
263 *
264 * @roller.wrapPojoMethod type="simple"
265 * @ejb:persistent-field
266 * @hibernate.property column="description" non-null="true" unique="false"
267 */
268 public String getDescription() {
/*
P/P * Method: String pcgetDescription()
*/
269 return this.description;
270 }
271
272 /** @ejb:persistent-field */
273 public void setDescription(String description) {
/*
P/P * Method: void pcsetDescription(String)
*/
274 this.description = description;
275 }
276
277 /**
278 * Original creator of website
279 *
280 * @roller.wrapPojoMethod type="pojo"
281 * @ejb:persistent-field
282 * @hibernate.many-to-one column="userid" cascade="none" not-null="true"
283 */
284 public org.apache.roller.weblogger.pojos.User getCreator() {
/*
P/P * Method: User pcgetCreator()
*/
285 return creator;
286 }
287
288 /** @ejb:persistent-field */
289 public void setCreator( org.apache.roller.weblogger.pojos.User ud ) {
/*
P/P * Method: void pcsetCreator(User)
*/
290 creator = ud;
291 }
292
293 /**
294 * @roller.wrapPojoMethod type="simple"
295 * @ejb:persistent-field
296 * @hibernate.property column="defaultpageid" non-null="true" unique="false"
297 */
298 public String getDefaultPageId() {
/*
P/P * Method: String pcgetDefaultPageId()
*/
299 return this.defaultPageId;
300 }
301
302 /**
303 * @ejb:persistent-field
304 */
305 public void setDefaultPageId(String defaultPageId) {
/*
P/P * Method: void pcsetDefaultPageId(String)
*/
306 this.defaultPageId = defaultPageId;
307 }
308
309 /**
310 * @roller.wrapPojoMethod type="simple"
311 * @deprecated
312 * @ejb:persistent-field
313 * @hibernate.property column="weblogdayid" non-null="true" unique="false"
314 */
315 public String getWeblogDayPageId() {
/*
P/P * Method: String pcgetWeblogDayPageId()
*/
316 return this.weblogDayPageId;
317 }
318
319 /**
320 * @deprecated
321 * @ejb:persistent-field
322 */
323 public void setWeblogDayPageId(String weblogDayPageId) {
/*
P/P * Method: void pcsetWeblogDayPageId(String)
*/
324 this.weblogDayPageId = weblogDayPageId;
325 }
326
327 /**
328 * @roller.wrapPojoMethod type="simple"
329 * @ejb:persistent-field
330 * @hibernate.property column="enablebloggerapi" non-null="true" unique="false"
331 */
332 public Boolean getEnableBloggerApi() {
/*
P/P * Method: Boolean pcgetEnableBloggerApi()
*/
333 return this.enableBloggerApi;
334 }
335
336 /** @ejb:persistent-field */
337 public void setEnableBloggerApi(Boolean enableBloggerApi) {
/*
P/P * Method: void pcsetEnableBloggerApi(Boolean)
*/
338 this.enableBloggerApi = enableBloggerApi;
339 }
340
341 /**
342 * @roller.wrapPojoMethod type="simple"
343 * @ejb:persistent-field
344 * @hibernate.many-to-one column="bloggercatid" non-null="false" cascade="none"
345 */
346 public WeblogCategory getBloggerCategory() {
/*
P/P * Method: WeblogCategory pcgetBloggerCategory()
*/
347 return bloggerCategory;
348 }
349
350 /** @ejb:persistent-field */
351 public void setBloggerCategory(WeblogCategory bloggerCategory) {
/*
P/P * Method: void pcsetBloggerCategory(WeblogCategory)
*/
352 this.bloggerCategory = bloggerCategory;
353 }
354
355 /**
356 * By default,the default category for a weblog is the root and all macros
357 * work with the top level categories that are immediately under the root.
358 * Setting a different default category allows you to partition your weblog.
359 *
360 * @roller.wrapPojoMethod type="pojo"
361 * @ejb:persistent-field
362 * @hibernate.many-to-one column="defaultcatid" non-null="false" cascade="none"
363 */
364 public WeblogCategory getDefaultCategory() {
/*
P/P * Method: WeblogCategory pcgetDefaultCategory()
*/
365 return defaultCategory;
366 }
367
368 /** @ejb:persistent-field */
369 public void setDefaultCategory(WeblogCategory defaultCategory) {
/*
P/P * Method: void pcsetDefaultCategory(WeblogCategory)
*/
370 this.defaultCategory = defaultCategory;
371 }
372
373 /**
374 * @roller.wrapPojoMethod type="simple"
375 * @ejb:persistent-field
376 * @hibernate.property column="editorpage" non-null="true" unique="false"
377 */
378 public String getEditorPage() {
/*
P/P * Method: String pcgetEditorPage()
*/
379 return this.editorPage;
380 }
381
382 /** @ejb:persistent-field */
383 public void setEditorPage(String editorPage) {
/*
P/P * Method: void pcsetEditorPage(String)
*/
384 this.editorPage = editorPage;
385 }
386
387 /**
388 * @roller.wrapPojoMethod type="simple"
389 * @ejb:persistent-field
390 * @hibernate.property column="blacklist" non-null="true" unique="false"
391 */
392 public String getBlacklist() {
/*
P/P * Method: String pcgetBlacklist()
*/
393 return this.blacklist;
394 }
395
396 /** @ejb:persistent-field */
397 public void setBlacklist(String blacklist) {
/*
P/P * Method: void pcsetBlacklist(String)
*/
398 this.blacklist = blacklist;
399 }
400
401 /**
402 * @roller.wrapPojoMethod type="simple"
403 * @ejb:persistent-field
404 * @hibernate.property column="allowcomments" non-null="true" unique="false"
405 */
406 public Boolean getAllowComments() {
/*
P/P * Method: Boolean pcgetAllowComments()
*/
407 return this.allowComments;
408 }
409
410 /** @ejb:persistent-field */
411 public void setAllowComments(Boolean allowComments) {
/*
P/P * Method: void pcsetAllowComments(Boolean)
*/
412 this.allowComments = allowComments;
413 }
414
415 /**
416 * @roller.wrapPojoMethod type="simple"
417 * @ejb:persistent-field
418 * @hibernate.property column="defaultallowcomments" non-null="true" unique="false"
419 */
420 public Boolean getDefaultAllowComments() {
/*
P/P * Method: Boolean pcgetDefaultAllowComments()
*/
421 return defaultAllowComments;
422 }
423
424 /** @ejb:persistent-field */
425 public void setDefaultAllowComments(Boolean defaultAllowComments) {
/*
P/P * Method: void pcsetDefaultAllowComments(Boolean)
*/
426 this.defaultAllowComments = defaultAllowComments;
427 }
428
429 /**
430 * @roller.wrapPojoMethod type="simple"
431 * @ejb:persistent-field
432 * @hibernate.property column="defaultcommentdays" non-null="true" unique="false"
433 */
434 public int getDefaultCommentDays() {
/*
P/P * Method: int pcgetDefaultCommentDays()
*/
435 return defaultCommentDays;
436 }
437
438 /** @ejb:persistent-field */
439 public void setDefaultCommentDays(int defaultCommentDays) {
/*
P/P * Method: void pcsetDefaultCommentDays(int)
*/
440 this.defaultCommentDays = defaultCommentDays;
441 }
442
443 /**
444 * @roller.wrapPojoMethod type="simple"
445 * @ejb:persistent-field
446 * @hibernate.property column="commentmod" non-null="true" unique="false"
447 */
448 public Boolean getModerateComments() {
/*
P/P * Method: Boolean pcgetModerateComments()
*/
449 return moderateComments;
450 }
451
452 /** @ejb:persistent-field */
453 public void setModerateComments(Boolean moderateComments) {
/*
P/P * Method: void pcsetModerateComments(Boolean)
*/
454 this.moderateComments = moderateComments;
455 }
456
457 /**
458 * @roller.wrapPojoMethod type="simple"
459 * @ejb:persistent-field
460 * @hibernate.property column="emailcomments" non-null="true" unique="false"
461 */
462 public Boolean getEmailComments() {
/*
P/P * Method: Boolean pcgetEmailComments()
*/
463 return this.emailComments;
464 }
465
466 /** @ejb:persistent-field */
467 public void setEmailComments(Boolean emailComments) {
/*
P/P * Method: void pcsetEmailComments(Boolean)
*/
468 this.emailComments = emailComments;
469 }
470
471 /**
472 * @roller.wrapPojoMethod type="simple"
473 * @ejb:persistent-field
474 * @hibernate.property column="emailfromaddress" non-null="true" unique="false"
475 */
476 public String getEmailFromAddress() {
/*
P/P * Method: String pcgetEmailFromAddress()
*/
477 return this.emailFromAddress;
478 }
479
480 /** @ejb:persistent-field */
481 public void setEmailFromAddress(String emailFromAddress) {
/*
P/P * Method: void pcsetEmailFromAddress(String)
*/
482 this.emailFromAddress = emailFromAddress;
483 }
484
485 /**
486 * @ejb:persistent-field
487 * @roller.wrapPojoMethod type="simple"
488 * @hibernate.property column="emailaddress" non-null="true" unique="false"
489 */
490 public String getEmailAddress() {
/*
P/P * Method: String pcgetEmailAddress()
*/
491 return this.emailAddress;
492 }
493
494 /** @ejb:persistent-field */
495 public void setEmailAddress(String emailAddress) {
/*
P/P * Method: void pcsetEmailAddress(String)
*/
496 this.emailAddress = emailAddress;
497 }
498
499 /**
500 * EditorTheme of the Website.
501 *
502 * @roller.wrapPojoMethod type="simple"
503 * @ejb:persistent-field
504 * @hibernate.property column="editortheme" non-null="true" unique="false"
505 */
506 public String getEditorTheme() {
/*
P/P * Method: String pcgetEditorTheme()
*/
507 return this.editorTheme;
508 }
509
510 /** @ejb:persistent-field */
511 public void setEditorTheme(String editorTheme) {
/*
P/P * Method: void pcsetEditorTheme(String)
*/
512 this.editorTheme = editorTheme;
513 }
514
515 /**
516 * Locale of the Website.
517 *
518 * @roller.wrapPojoMethod type="simple"
519 * @ejb:persistent-field
520 * @hibernate.property column="locale" non-null="true" unique="false"
521 */
522 public String getLocale() {
/*
P/P * Method: String pcgetLocale()
*/
523 return this.locale;
524 }
525
526 /** @ejb:persistent-field */
527 public void setLocale(String locale) {
/*
P/P * Method: void pcsetLocale(String)
*/
528 this.locale = locale;
529 }
530
531 /**
532 * Timezone of the Website.
533 *
534 * @roller.wrapPojoMethod type="simple"
535 * @ejb:persistent-field
536 * @hibernate.property column="timeZone" non-null="true" unique="false"
537 */
538 public String getTimeZone() {
/*
P/P * Method: String pcgetTimeZone()
*/
539 return this.timeZone;
540 }
541
542 /** @ejb:persistent-field */
543 public void setTimeZone(String timeZone) {
/*
P/P * Method: void pcsetTimeZone(String)
*/
544 this.timeZone = timeZone;
545 }
546
547 /**
548 * @ejb:persistent-field
549 * @hibernate.property column="datecreated" non-null="true" unique="false"
550 * @roller.wrapPojoMethod type="simple"
551 */
552 public Date getDateCreated() {
/*
P/P * Method: Date pcgetDateCreated()
*/
553 if (dateCreated == null) {
554 return null;
555 } else {
556 return (Date)dateCreated.clone();
557 }
558 }
559 /** @ejb:persistent-field */
560 public void setDateCreated(final Date date) {
/*
P/P * Method: void pcsetDateCreated(Date)
*/
561 if (date != null) {
562 dateCreated = (Date)date.clone();
563 } else {
564 dateCreated = null;
565 }
566 }
567
568 /**
569 * Comma-delimited list of user's default Plugins.
570 *
571 * @roller.wrapPojoMethod type="simple"
572 * @ejb:persistent-field
573 * @hibernate.property column="defaultplugins" non-null="false" unique="false"
574 */
575 public String getDefaultPlugins() {
/*
P/P * Method: String pcgetDefaultPlugins()
*/
576 return defaultPlugins;
577 }
578
579 /** @ejb:persistent-field */
580 public void setDefaultPlugins(String string) {
/*
P/P * Method: void pcsetDefaultPlugins(String)
*/
581 defaultPlugins = string;
582 }
583
584
585 /**
586 * Set bean properties based on other bean.
587 */
588 public void setData(Weblog other) {
589
/*
P/P * Method: void setData(Weblog)
*/
590 this.id = other.getId();
591 this.name = other.getName();
592 this.handle = other.getHandle();
593 this.description = other.getDescription();
594 this.creator = other.getCreator();
595 this.defaultPageId = other.getDefaultPageId();
596 this.weblogDayPageId = other.getWeblogDayPageId();
597 this.enableBloggerApi = other.getEnableBloggerApi();
598 this.bloggerCategory = other.getBloggerCategory();
599 this.defaultCategory = other.getDefaultCategory();
600 this.editorPage = other.getEditorPage();
601 this.blacklist = other.getBlacklist();
602 this.allowComments = other.getAllowComments();
603 this.emailComments = other.getEmailComments();
604 this.emailAddress = other.getEmailAddress();
605 this.emailFromAddress = other.getEmailFromAddress();
606 this.editorTheme = other.getEditorTheme();
607 this.locale = other.getLocale();
608 this.timeZone = other.getTimeZone();
609 this.defaultPlugins = other.getDefaultPlugins();
610 this.enabled = other.getEnabled();
611 this.dateCreated = other.getDateCreated();
612 this.entryDisplayCount = other.getEntryDisplayCount();
613 this.active = other.getActive();
614 this.lastModified = other.getLastModified();
615 }
616
617
618 /**
619 * Parse locale value and instantiate a Locale object,
620 * otherwise return default Locale.
621 *
622 * @return Locale
623 */
624 public Locale getLocaleInstance() {
/*
P/P * Method: Locale getLocaleInstance()
*/
625 return I18nUtils.toLocale(getLocale());
626 }
627
628
629 /**
630 * Return TimeZone instance for value of timeZone,
631 * otherwise return system default instance.
632 *
633 * @roller.wrapPojoMethod type="simple"
634 * @return TimeZone
635 */
636 public TimeZone getTimeZoneInstance() {
/*
P/P * Method: TimeZone getTimeZoneInstance()
*/
637 if (timeZone == null) {
638 if (TimeZone.getDefault() != null) {
639 this.setTimeZone( TimeZone.getDefault().getID() );
640 } else {
641 this.setTimeZone("America/New_York");
642 }
643 }
644 return TimeZone.getTimeZone(timeZone);
645 }
646
647
648 /**
649 * Returns true if user has all permissions specified by mask.
650 */
651 public boolean hasUserPermissions(User user, short mask) {
652 // look for user in website's permissions
/*
P/P * Method: bool hasUserPermissions(User, short)
*/
653 WeblogPermission userPerms = null;
654 Iterator iter = getPermissions().iterator();
655 while (iter.hasNext()) {
656 WeblogPermission perms = (WeblogPermission) iter.next();
657 if (perms.getUser().getId().equals(user.getId())) {
658 userPerms = perms;
659 break;
660 }
661 }
662 // if we found one, does it satisfy the mask?
663 if (userPerms != null && !userPerms.isPending()) {
664 if (userPerms != null && (userPerms.getPermissionMask() & mask) == mask) {
665 return true;
666 }
667 }
668 // otherwise, check to see if user is a global admin
669 if (user != null && user.hasRole("admin")) return true;
670 return false;
671 }
672
673 /** Get number of users associated with website */
674 public int getUserCount() {
/*
P/P * Method: int getUserCount()
*/
675 return getPermissions().size();
676 }
677
678 /** No-op needed to please XDoclet generated code */
679 private int userCount = 0;
680 public void setUserCount(int userCount) {
681 // no-op
/*
P/P * Method: void setUserCount(int)
*/
682 }
683
684 public int getAdminUserCount() {
/*
P/P * Method: int getAdminUserCount()
*/
685 int count = 0;
686 WeblogPermission userPerms = null;
687 Iterator iter = getPermissions().iterator();
688 while (iter.hasNext()) {
689 WeblogPermission perms = (WeblogPermission) iter.next();
690 if (perms.getPermissionMask() == WeblogPermission.ADMIN) {
691 count++;
692 }
693 }
694 return count;
695 }
696
697 /** No-op needed to please XDoclet generated code */
698 private int adminUserCount = 0;
699 public void setAdminUserCount(int adminUserCount) {
700 // no-op
/*
P/P * Method: void setAdminUserCount(int)
*/
701 }
702
703
704 /**
705 * @roller.wrapPojoMethod type="simple"
706 * @ejb:persistent-field
707 * @hibernate.property column="displaycnt" not-null="true"
708 */
709 public int getEntryDisplayCount() {
/*
P/P * Method: int pcgetEntryDisplayCount()
*/
710 return entryDisplayCount;
711 }
712
713 /**
714 * @ejb:persistent-field
715 */
716 public void setEntryDisplayCount(int entryDisplayCount) {
/*
P/P * Method: void pcsetEntryDisplayCount(int)
*/
717 this.entryDisplayCount = entryDisplayCount;
718 }
719
720 /**
721 * Set to FALSE to completely disable and hide this weblog from public view.
722 *
723 * @roller.wrapPojoMethod type="simple"
724 * @ejb:persistent-field
725 * @hibernate.property column="isenabled" non-null="true" unique="false"
726 */
727 public Boolean getEnabled() {
/*
P/P * Method: Boolean pcgetEnabled()
*/
728 return this.enabled;
729 }
730
731 /** @ejb:persistent-field */
732 public void setEnabled(Boolean enabled) {
/*
P/P * Method: void pcsetEnabled(Boolean)
*/
733 this.enabled = enabled;
734 }
735
736 /**
737 * Set to FALSE to exclude this weblog from community areas such as the
738 * front page and the planet page.
739 *
740 * @roller.wrapPojoMethod type="simple"
741 * @ejb:persistent-field
742 * @hibernate.property column="isactive" not-null="true"
743 */
744 public Boolean getActive() {
/*
P/P * Method: Boolean pcgetActive()
*/
745 return active;
746 }
747
748 public void setActive(Boolean active) {
/*
P/P * Method: void pcsetActive(Boolean)
*/
749 this.active = active;
750 }
751
752 /**
753 * Returns true if comment moderation is required by website or config.
754 */
755 public boolean getCommentModerationRequired() {
/*
P/P * Method: bool getCommentModerationRequired()
*/
756 return (getModerateComments().booleanValue()
757 || WebloggerRuntimeConfig.getBooleanProperty("users.moderation.required"));
758 }
759
760 /** No-op */
/*
P/P * Method: void setCommentModerationRequired(bool)
*/
761 public void setCommentModerationRequired(boolean modRequired) {}
762
763
764 /**
765 * The last time any visible part of this weblog was modified.
766 * This includes a change to weblog settings, entries, themes, templates,
767 * comments, categories, bookmarks, folders, etc.
768 *
769 * Pings and Referrers are explicitly not included because pings to not
770 * affect visible changes to a weblog, and referrers change so often that
771 * it would diminish the usefulness of the attribute.
772 *
773 * @roller.wrapPojoMethod type="simple"
774 * @ejb:persistent-field
775 * @hibernate.property column="lastmodified" not-null="true"
776 */
777 public Date getLastModified() {
/*
P/P * Method: Date pcgetLastModified()
*/
778 return lastModified;
779 }
780
781 public void setLastModified(Date lastModified) {
/*
P/P * Method: void pcsetLastModified(Date)
*/
782 this.lastModified = lastModified;
783 }
784
785
786 /**
787 * Is multi-language blog support enabled for this weblog?
788 *
789 * If false then urls with various locale restrictions should fail.
790 *
791 * @roller.wrapPojoMethod type="simple"
792 * @ejb:persistent-field
793 * @hibernate.property column="enablemultilang" not-null="true"
794 */
795 public boolean isEnableMultiLang() {
/*
P/P * Method: bool pcisEnableMultiLang()
*/
796 return enableMultiLang;
797 }
798
799 public void setEnableMultiLang(boolean enableMultiLang) {
/*
P/P * Method: void pcsetEnableMultiLang(bool)
*/
800 this.enableMultiLang = enableMultiLang;
801 }
802
803
804 /**
805 * Should the default weblog view show entries from all languages?
806 *
807 * If false then the default weblog view only shows entry from the
808 * default locale chosen for this weblog.
809 *
810 * @roller.wrapPojoMethod type="simple"
811 * @ejb:persistent-field
812 * @hibernate.property column="showalllangs" not-null="true"
813 */
814 public boolean isShowAllLangs() {
/*
P/P * Method: bool pcisShowAllLangs()
*/
815 return showAllLangs;
816 }
817
818 public void setShowAllLangs(boolean showAllLangs) {
/*
P/P * Method: void pcsetShowAllLangs(bool)
*/
819 this.showAllLangs = showAllLangs;
820 }
821
822
823 /**
824 * @roller.wrapPojoMethod type="simple"
825 */
826 public String getURL() {
827 // TODO: ATLAS reconcile entry.getPermaLink() with new URLs
/*
P/P * Method: String getURL()
*/
828 String relPath = WebloggerRuntimeConfig.getRelativeContextURL();
829 return relPath + "/" + getHandle();
830 //return URLUtilities.getWeblogURL(this, null, false);
831 }
832 public void setURL(String url) {
833 // noop
/*
P/P * Method: void setURL(String)
*/
834 }
835
836
837 /**
838 * @roller.wrapPojoMethod type="simple"
839 */
840 public String getAbsoluteURL() {
841 // TODO: ATLAS reconcile entry.getPermaLink() with new URLs
/*
P/P * Method: String getAbsoluteURL()
*/
842 String relPath = WebloggerRuntimeConfig.getAbsoluteContextURL();
843 return relPath + "/" + getHandle();
844 //return URLUtilities.getWeblogURL(this, null, true);
845 }
846 public void setAbsoluteURL(String url) {
847 // noop
/*
P/P * Method: void setAbsoluteURL(String)
*/
848 }
849
850
851 /**
852 * Comma-separated list of additional page models to be created when this
853 * weblog is rendered.
854 *
855 * @ejb:persistent-field
856 * @hibernate.property column="pagemodels" not-null="false"
857 */
858 public String getPageModels() {
/*
P/P * Method: String pcgetPageModels()
*/
859 return pageModels;
860 }
861 public void setPageModels(String pageModels) {
/*
P/P * Method: void pcsetPageModels(String)
*/
862 this.pageModels = pageModels;
863 }
864
865
866 /**
867 * The path under the weblog's resources to a stylesheet override.
868 *
869 * @hibernate.property column="customstylesheet" not-null="false"
870 */
871 public String getCustomStylesheetPath() {
/*
P/P * Method: String pcgetCustomStylesheetPath()
*/
872 return customStylesheetPath;
873 }
874
875 public void setCustomStylesheetPath(String customStylesheetPath) {
/*
P/P * Method: void pcsetCustomStylesheetPath(String)
*/
876 this.customStylesheetPath = customStylesheetPath;
877 }
878
879
880 /**
881 * The path under the weblog's resources to an icon image.
882 *
883 * @hibernate.property column="icon" not-null="false"
884 */
885 public String getIconPath() {
/*
P/P * Method: String pcgetIconPath()
*/
886 return iconPath;
887 }
888
889 public void setIconPath(String iconPath) {
/*
P/P * Method: void pcsetIconPath(String)
*/
890 this.iconPath = iconPath;
891 }
892
893
894 /**
895 * A short description about the weblog.
896 *
897 * This field difers from the 'description' attribute in the sense that the
898 * description is meant to hold more of a tagline, while this attribute is
899 * more of a full paragraph (or two) about section.
900 *
901 * @hibernate.property column="about" not-null="false"
902 */
903 public String getAbout() {
/*
P/P * Method: String pcgetAbout()
*/
904 return about;
905 }
906
907 public void setAbout(String about) {
/*
P/P * Method: void pcsetAbout(String)
*/
908 this.about = about;
909 }
910
911
912 /**
913 * Get initialized plugins for use during rendering process.
914 */
915 public Map getInitializedPlugins() {
/*
P/P * Method: Map getInitializedPlugins()
*/
916 if (initializedPlugins == null) {
917 try {
918 Weblogger roller = WebloggerFactory.getWeblogger();
919 PluginManager ppmgr = roller.getPluginManager();
920 initializedPlugins = ppmgr.getWeblogEntryPlugins(this);
921 } catch (Exception e) {
922 this.log.error("ERROR: initializing plugins");
923 }
924 }
925 return initializedPlugins;
926 }
927
928 /**
929 * Get weblog entry specified by anchor or null if no such entry exists.
930 * @param anchor Weblog entry anchor
931 * @return Weblog entry specified by anchor
932 * @roller.wrapPojoMethod type="simple"
933 */
934 public WeblogEntry getWeblogEntry(String anchor) {
/*
P/P * Method: WeblogEntry getWeblogEntry(String)
*/
935 WeblogEntry entry = null;
936 try {
937 Weblogger roller = WebloggerFactory.getWeblogger();
938 WeblogManager wmgr = roller.getWeblogManager();
939 entry = wmgr.getWeblogEntryByAnchor(this, anchor);
940 } catch (WebloggerException e) {
941 this.log.error("ERROR: getting entry by anchor");
942 }
943 return entry;
944 }
945
946 /**
947 * Returns categories under the default category of the weblog.
948 *
949 * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojos.WeblogCategory"
950 */
951 public Set getWeblogCategories() {
/*
P/P * Method: Set getWeblogCategories()
*/
952 Set ret = new HashSet();
953 // try {
954 WeblogCategory category = this.getDefaultCategory();
955 ret = category.getWeblogCategories();
956 // } catch (WebloggerException e) {
957 // log.error("ERROR: fetching categories", e);
958 // }
959 return ret;
960 }
961
962
963 /**
964 *
965 *
966 * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojosWeblogCategorya"
967 */
968 public Set getWeblogCategories(String categoryPath) {
/*
P/P * Method: Set getWeblogCategories(String)
*/
969 Set ret = new HashSet();
970 try {
971 Weblogger roller = WebloggerFactory.getWeblogger();
972 WeblogManager wmgr = roller.getWeblogManager();
973 WeblogCategory category = null;
974 if (categoryPath != null && !categoryPath.equals("nil")) {
975 category = wmgr.getWeblogCategoryByPath(this, categoryPath);
976 } else {
977 category = this.getDefaultCategory();
978 }
979 ret = category.getWeblogCategories();
980 } catch (WebloggerException e) {
981 log.error("ERROR: fetching categories for path: " + categoryPath, e);
982 }
983 return ret;
984 }
985
986
987 /**
988 *
989 *
990 * @roller.wrapPojoMethod type="pojo" class="org.apache.roller.weblogger.pojosWeblogCategorya"
991 */
992 public WeblogCategory getWeblogCategory(String categoryPath) {
/*
P/P * Method: WeblogCategory getWeblogCategory(String)
*/
993 WeblogCategory category = null;
994 try {
995 Weblogger roller = WebloggerFactory.getWeblogger();
996 WeblogManager wmgr = roller.getWeblogManager();
997 if (categoryPath != null && !categoryPath.equals("nil")) {
998 category = wmgr.getWeblogCategoryByPath(this, categoryPath);
999 } else {
1000 category = this.getDefaultCategory();
1001 }
1002 } catch (WebloggerException e) {
1003 log.error("ERROR: fetching category at path: " + categoryPath, e);
1004 }
1005 return category;
1006 }
1007
1008
1009 /**
1010 * Get up to 100 most recent published entries in weblog.
1011 * @param cat Category path or null for no category restriction
1012 * @param length Max entries to return (1-100)
1013 * @return List of weblog entry objects.
1014 *
1015 * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojos.WeblogEntryData"
1016 */
1017 public List getRecentWeblogEntries(String cat, int length) {
/*
P/P * Method: List getRecentWeblogEntries(String, int)
*/
1018 if (cat != null && "nil".equals(cat)) cat = null;
1019 if (length > 100) length = 100;
1020 List recentEntries = new ArrayList();
1021 if (length < 1) return recentEntries;
1022 try {
1023 WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
1024 recentEntries = wmgr.getWeblogEntries(
1025
1026 this,
1027 null, // user
1028 null, // startDate
1029 null, // endDate
1030 cat, // cat or null
1031 null,WeblogEntry.PUBLISHED,
1032 null, // text
1033 "pubTime", // sortby
1034 null,
1035 null,
1036 0,
1037 length);
1038 } catch (WebloggerException e) {
1039 log.error("ERROR: getting recent entries", e);
1040 }
1041 return recentEntries;
1042 }
1043
1044 /**
1045 * Get up to 100 most recent published entries in weblog.
1046 * @param cat Category path or null for no category restriction
1047 * @param length Max entries to return (1-100)
1048 * @return List of weblog entry objects.
1049 *
1050 * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojos.WeblogEntryData"
1051 */
1052 public List getRecentWeblogEntriesByTag(String tag, int length) {
/*
P/P * Method: List getRecentWeblogEntriesByTag(String, int)
*/
1053 if (tag != null && "nil".equals(tag)) tag = null;
1054 if (length > 100) length = 100;
1055 List recentEntries = new ArrayList();
1056 List tags = new ArrayList();
1057 if (tag != null) {
1058 tags.add(tag);
1059 }
1060 if (length < 1) return recentEntries;
1061 try {
1062 WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
1063 recentEntries = wmgr.getWeblogEntries(
1064
1065 this,
1066 null, // user
1067 null, // startDate
1068 null, // endDate
1069 null, // cat or null
1070 tags,WeblogEntry.PUBLISHED,
1071 null, // text
1072 "pubTime", // sortby
1073 null,
1074 null,
1075 0,
1076 length);
1077 } catch (WebloggerException e) {
1078 log.error("ERROR: getting recent entries", e);
1079 }
1080 return recentEntries;
1081 }
1082
1083 /**
1084 * Get up to 100 most recent approved and non-spam comments in weblog.
1085 * @param length Max entries to return (1-100)
1086 * @return List of comment objects.
1087 *
1088 * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojos.WeblogEntryComment"
1089 */
1090 public List getRecentComments(int length) {
/*
P/P * Method: List getRecentComments(int)
*/
1091 if (length > 100) length = 100;
1092 List recentComments = new ArrayList();
1093 if (length < 1) return recentComments;
1094 try {
1095 WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
1096 recentComments = wmgr.getComments(
1097
1098 this,
1099 null, // weblog entry
1100 null, // search String
1101 null, // startDate
1102 null,WeblogEntryComment.APPROVED, // approved comments only
1103 true, // we want reverse chrono order
1104 0, // offset
1105 length); // length
1106 } catch (WebloggerException e) {
1107 log.error("ERROR: getting recent comments", e);
1108 }
1109 return recentComments;
1110 }
1111
1112
1113 /**
1114 * Get bookmark folder by name.
1115 * @param folderName Name or path of bookmark folder to be returned (null for root)
1116 * @return Folder object requested.
1117 *
1118 * @roller.wrapPojoMethod type="pojo" class="org.apache.roller.weblogger.pojos.WeblogBookmarkFolder"
1119 */
1120 public WeblogBookmarkFolder getBookmarkFolder(String folderName) {
/*
P/P * Method: WeblogBookmarkFolder getBookmarkFolder(String)
*/
1121 WeblogBookmarkFolder ret = null;
1122 try {
1123 Weblogger roller = WebloggerFactory.getWeblogger();
1124 BookmarkManager bmgr = roller.getBookmarkManager();
1125 if (folderName == null || folderName.equals("nil") || folderName.trim().equals("/")) {
1126 return bmgr.getRootFolder(this);
1127 } else {
1128 return bmgr.getFolder(this, folderName);
1129 }
1130 } catch (WebloggerException re) {
1131 log.error("ERROR: fetching folder for weblog", re);
1132 }
1133 return ret;
1134 }
1135
1136
1137 /**
1138 * Return collection of referrers for current day.
1139 * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojos.WeblogReferrer"
1140 */
1141 public List getTodaysReferrers() {
/*
P/P * Method: List getTodaysReferrers()
*/
1142 List referers = null;
1143 try {
1144 Weblogger roller = WebloggerFactory.getWeblogger();
1145 RefererManager rmgr = roller.getRefererManager();
1146 return rmgr.getTodaysReferers(this);
1147
1148 } catch (WebloggerException e) {
1149 log.error("PageModel getTodaysReferers()", e);
1150 }
1151 return (referers == null ? Collections.EMPTY_LIST : referers);
1152 }
1153
1154 /** No-op method to please XDoclet */
/*
P/P * Method: void setTodaysReferrers(List)
*/
1155 public void setTodaysReferrers(List ignored) {}
1156
1157 /**
1158 * Get number of hits counted today.
1159 * @roller.wrapPojoMethod type="simple"
1160 */
1161 public int getTodaysHits() {
1162 try {
/*
P/P * Method: int getTodaysHits()
*/
1163 Weblogger roller = WebloggerFactory.getWeblogger();
1164 WeblogManager mgr = roller.getWeblogManager();
1165 WeblogHitCount hitCount = mgr.getHitCountByWeblog(this);
1166
1167 return (hitCount != null) ? hitCount.getDailyHits() : 0;
1168
1169 } catch (WebloggerException e) {
1170 log.error("Error getting weblog hit count", e);
1171 }
1172 return 0;
1173 }
1174
1175 /** No-op method to please XDoclet */
/*
P/P * Method: void setTodaysHits(int)
*/
1176 public void setTodaysHits(int ignored) {}
1177
1178
1179 /**
1180 * Get a list of TagStats objects for the most popular tags
1181 *
1182 * @param sinceDays Number of days into past (or -1 for all days)
1183 * @param length Max number of tags to return.
1184 * @return Collection of WeblogEntryTag objects
1185 *
1186 * @roller.wrapPojoMethod type="simple"
1187 */
1188 public List getPopularTags(int sinceDays, int length) {
/*
P/P * Method: List getPopularTags(int, int)
*/
1189 List results = new ArrayList();
1190 Date startDate = null;
1191 if(sinceDays > 0) {
1192 Calendar cal = Calendar.getInstance();
1193 cal.setTime(new Date());
1194 cal.add(Calendar.DATE, -1 * sinceDays);
1195 startDate = cal.getTime();
1196 }
1197 try {
1198 Weblogger roller = WebloggerFactory.getWeblogger();
1199 WeblogManager wmgr = roller.getWeblogManager();
1200 results = wmgr.getPopularTags(this, startDate, length);
1201 } catch (Exception e) {
1202 log.error("ERROR: fetching popular tags for weblog " + this.getName(), e);
1203 }
1204 return results;
1205 }
1206
1207 /**
1208 * @roller.wrapPojoMethod type="simple"
1209 */
1210 public long getCommentCount() {
/*
P/P * Method: long getCommentCount()
*/
1211 long count = 0;
1212 try {
1213 Weblogger roller = WebloggerFactory.getWeblogger();
1214 WeblogManager mgr = roller.getWeblogManager();
1215 count = mgr.getCommentCount(this);
1216 } catch (WebloggerException e) {
1217 log.error("Error getting comment count for weblog " + this.getName(), e);
1218 }
1219 return count;
1220 }
1221
1222 /** No-op method to please XDoclet */
/*
P/P * Method: void setCommentCount(int)
*/
1223 public void setCommentCount(int ignored) {}
1224
1225 /**
1226 * @roller.wrapPojoMethod type="simple"
1227 */
1228 public long getEntryCount() {
/*
P/P * Method: long getEntryCount()
*/
1229 long count = 0;
1230 try {
1231 Weblogger roller = WebloggerFactory.getWeblogger();
1232 WeblogManager mgr = roller.getWeblogManager();
1233 count = mgr.getEntryCount(this);
1234 } catch (WebloggerException e) {
1235 log.error("Error getting entry count for weblog " + this.getName(), e);
1236 }
1237 return count;
1238 }
1239
1240 /** No-op method to please XDoclet */
/*
P/P * Method: void setEntryCount(int)
*/
1241 public void setEntryCount(int ignored) {}
1242
1243 }
SofCheck Inspector Build Version : 2.18479
| Weblog.java |
2009-Jan-02 14:24:58 |
| Weblog.class |
2009-Sep-04 03:12:37 |