KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > pojos > WebsiteData


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.pojos;
20
21 import java.io.Serializable JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Locale JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.TimeZone JavaDoc;
30 import java.util.TreeMap JavaDoc;
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 /**
48  * Website has many-to-many association with users. Website has one-to-many and
49  * one-direction associations with weblog entries, weblog categories, folders and
50  * other objects. Use UserManager to create, fetch, update and retreive websites.
51  *
52  * @author David M Johnson
53  *
54  * @ejb:bean name="WebsiteData"
55  * @struts.form include-all="true"
56  * @hibernate.class lazy="false" table="website"
57  * @hibernate.cache usage="read-write"
58  */

59 public class WebsiteData extends org.apache.roller.pojos.PersistentObject
60         implements Serializable JavaDoc {
61     public static final long serialVersionUID = 206437645033737127L;
62     
63     private static Log log = LogFactory.getLog(WebsiteData.class);
64     
65     // Simple properties
66
private String JavaDoc id = null;
67     private String JavaDoc handle = null;
68     private String JavaDoc name = null;
69     private String JavaDoc description = null;
70     private String JavaDoc defaultPageId = "dummy";
71     private String JavaDoc weblogDayPageId = "dummy";
72     private Boolean JavaDoc enableBloggerApi = Boolean.TRUE;
73     private String JavaDoc editorPage = null;
74     private String JavaDoc blacklist = null;
75     private Boolean JavaDoc allowComments = Boolean.TRUE;
76     private Boolean JavaDoc emailComments = Boolean.FALSE;
77     private String JavaDoc emailFromAddress = null;
78     private String JavaDoc emailAddress = null;
79     private String JavaDoc editorTheme = null;
80     private String JavaDoc locale = null;
81     private String JavaDoc timeZone = null;
82     private String JavaDoc defaultPlugins = null;
83     private Boolean JavaDoc enabled = Boolean.TRUE;
84     private Boolean JavaDoc active = Boolean.TRUE;
85     private Date JavaDoc dateCreated = new java.util.Date JavaDoc();
86     private Boolean JavaDoc defaultAllowComments = Boolean.TRUE;
87     private int defaultCommentDays = 0;
88     private Boolean JavaDoc moderateComments = Boolean.FALSE;
89     private int entryDisplayCount = 15;
90     private Date JavaDoc lastModified = new Date JavaDoc();
91     private String JavaDoc pageModels = new String JavaDoc();
92     private boolean enableMultiLang = false;
93     private boolean showAllLangs = true;
94     
95     
96     // Associated objects
97
private UserData creator = null;
98     private List JavaDoc permissions = new ArrayList JavaDoc();
99     private WeblogCategoryData bloggerCategory = null;
100     private WeblogCategoryData defaultCategory = null;
101     
102     private Map JavaDoc initializedPlugins = null;
103     
104     public WebsiteData() {
105     }
106     
107     public WebsiteData(
108             String JavaDoc handle,
109             UserData creator,
110             String JavaDoc name,
111             String JavaDoc desc,
112             String JavaDoc email,
113             String JavaDoc emailFrom,
114             String JavaDoc editorTheme,
115             String JavaDoc locale,
116             String JavaDoc 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     /**
134      * @hibernate.bag lazy="true" inverse="true" cascade="delete"
135      * @hibernate.collection-key column="website_id"
136      * @hibernate.collection-one-to-many
137      * class="org.apache.roller.pojos.PermissionsData"
138      */

139     public List JavaDoc getPermissions() {
140         return permissions;
141     }
142     public void setPermissions(List JavaDoc perms) {
143         permissions = perms;
144     }
145     /**
146      * Remove permission from collection.
147      */

148     public void removePermission(PermissionsData perms) {
149         permissions.remove(perms);
150     }
151     
152     /**
153      * Lookup the default page for this website.
154      */

155     public Template getDefaultPage() throws RollerException {
156         
157         Template template = null;
158         
159         // first check if this user has selected a theme
160
// if so then return the themes Weblog template
161
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                 // this is a bit iffy :/
167
// we assume that all theme use "Weblog" for a default template
168
template = usersTheme.getTemplate("Weblog");
169                 
170             } catch(ThemeNotFoundException tnfe) {
171                 // i sure hope not!
172
log.error(tnfe);
173             }
174         }
175         
176         // if we didn't get the Template from a theme then look in the db
177
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     /**
190      * Lookup a Template for this website by id.
191      */

192     public Template getPageById(String JavaDoc id) throws RollerException {
193         
194         if(id == null)
195             return null;
196         
197         Template template = null;
198         
199         // first check if this user has selected a theme
200
// if so then return the proper theme template
201
if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
202             
203             // we don't actually expect to get lookups for theme pages by id
204
// but we have to be thorough and check anyways
205
String JavaDoc[] split = id.split(":", 2);
206             
207             // only continue if this looks like a theme id
208
// and the theme name matches this users current theme
209
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                     // i sure hope not!
217
log.error(tnfe);
218                 }
219             }
220             
221         }
222         
223         // if we didn't get the Template from a theme then look in the db
224
if(template == null) {
225             UserManager userMgr = RollerFactory.getRoller().getUserManager();
226             template = userMgr.getPageByName(this, name);
227         }
228         
229         return template;
230     }
231     
232     
233     /**
234      * Lookup a Template for this website by name.
235      * @roller.wrapPojoMethod type="pojo"
236      */

237     public Template getPageByName(String JavaDoc 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         // first check if this user has selected a theme
247
// if so then return the proper theme template
248
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                 // i sure hope not!
257
log.error(tnfe);
258             }
259             
260         }
261         
262         // if we didn't get the Template from a theme then look in the db
263
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     /**
276      * Lookup a template for this website by link.
277      * @roller.wrapPojoMethod type="pojo"
278      */

279     public Template getPageByLink(String JavaDoc 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         // first check if this user has selected a theme
289
// if so then return the proper theme template
290
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                 // i sure hope not!
299
log.error(tnfe);
300             }
301             
302         }
303         
304         // if we didn't get the Template from a theme then look in the db
305
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     /**
318      * Get a list of all pages that are part of this website.
319      * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.Template"
320      */

321     public List JavaDoc getPages() {
322         
323         Map JavaDoc pages = new TreeMap JavaDoc();
324         
325         // first get the pages from the db
326
try {
327             Template template = null;
328             UserManager userMgr = RollerFactory.getRoller().getUserManager();
329             Iterator JavaDoc dbPages = userMgr.getPages(this).iterator();
330             while(dbPages.hasNext()) {
331                 template = (Template) dbPages.next();
332                 pages.put(template.getName(), template);
333             }
334         } catch(Exception JavaDoc e) {
335             // db error
336
log.error(e);
337         }
338         
339         
340         // now get theme pages if needed and put them in place of db pages
341
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 JavaDoc themePages = usersTheme.getTemplates().iterator();
347                 while(themePages.hasNext()) {
348                     template = (Template) themePages.next();
349                     
350                     // note that this will put theme pages over custom
351
// pages in the pages list, which is what we want
352
pages.put(template.getName(), template);
353                 }
354             } catch(Exception JavaDoc e) {
355                 // how??
356
log.error(e);
357             }
358         }
359         
360         return new ArrayList JavaDoc(pages.values());
361     }
362     
363     
364     /**
365      * Id of the Website.
366      *
367      * @roller.wrapPojoMethod type="simple"
368      * @ejb:persistent-field
369      * @hibernate.id column="id"
370      * generator-class="uuid.hex" unsaved-value="null"
371      */

372     public String JavaDoc getId() {
373         return this.id;
374     }
375     
376     /** @ejb:persistent-field */
377     public void setId(String JavaDoc id) {
378         this.id = id;
379     }
380     
381     /**
382      * Short URL safe string that uniquely identifies the website.
383      * @ejb:persistent-field
384      * @hibernate.property column="handle" non-null="true" unique="true"
385      * @roller.wrapPojoMethod type="simple"
386      */

387     public String JavaDoc getHandle() {
388         return this.handle;
389     }
390     
391     /** @ejb:persistent-field */
392     public void setHandle(String JavaDoc handle) {
393         this.handle = handle;
394     }
395     
396     /**
397      * Name of the Website.
398      *
399      * @roller.wrapPojoMethod type="simple"
400      * @ejb:persistent-field
401      * @hibernate.property column="name" non-null="true" unique="false"
402      */

403     public String JavaDoc getName() {
404         return this.name;
405     }
406     
407     /** @ejb:persistent-field */
408     public void setName(String JavaDoc name) {
409         this.name = name;
410     }
411     
412     /**
413      * Description
414      *
415      * @roller.wrapPojoMethod type="simple"
416      * @ejb:persistent-field
417      * @hibernate.property column="description" non-null="true" unique="false"
418      */

419     public String JavaDoc getDescription() {
420         return this.description;
421     }
422     
423     /** @ejb:persistent-field */
424     public void setDescription(String JavaDoc description) {
425         this.description = description;
426     }
427     
428     /**
429      * Original creator of website
430      *
431      * @roller.wrapPojoMethod type="pojo"
432      * @ejb:persistent-field
433      * @hibernate.many-to-one column="userid" cascade="none" not-null="true"
434      */

435     public org.apache.roller.pojos.UserData getCreator() {
436         return creator;
437     }
438     
439     /** @ejb:persistent-field */
440     public void setCreator( org.apache.roller.pojos.UserData ud ) {
441         creator = ud;
442     }
443     
444     /**
445      * @roller.wrapPojoMethod type="simple"
446      * @ejb:persistent-field
447      * @hibernate.property column="defaultpageid" non-null="true" unique="false"
448      */

449     public String JavaDoc getDefaultPageId() {
450         return this.defaultPageId;
451     }
452     
453     /**
454      * @ejb:persistent-field
455      */

456     public void setDefaultPageId(String JavaDoc defaultPageId) {
457         this.defaultPageId = defaultPageId;
458     }
459     
460     /**
461      * @roller.wrapPojoMethod type="simple"
462      * @deprecated
463      * @ejb:persistent-field
464      * @hibernate.property column="weblogdayid" non-null="true" unique="false"
465      */

466     public String JavaDoc getWeblogDayPageId() {
467         return this.weblogDayPageId;
468     }
469     
470     /**
471      * @deprecated
472      * @ejb:persistent-field
473      */

474     public void setWeblogDayPageId(String JavaDoc weblogDayPageId) {
475         this.weblogDayPageId = weblogDayPageId;
476     }
477     
478     /**
479      * @roller.wrapPojoMethod type="simple"
480      * @ejb:persistent-field
481      * @hibernate.property column="enablebloggerapi" non-null="true" unique="false"
482      */

483     public Boolean JavaDoc getEnableBloggerApi() {
484         return this.enableBloggerApi;
485     }
486     
487     /** @ejb:persistent-field */
488     public void setEnableBloggerApi(Boolean JavaDoc enableBloggerApi) {
489         this.enableBloggerApi = enableBloggerApi;
490     }
491     
492     /**
493      * @roller.wrapPojoMethod type="simple"
494      * @ejb:persistent-field
495      * @hibernate.many-to-one column="bloggercatid" non-null="false"
496      */

497     public WeblogCategoryData getBloggerCategory() {
498         return bloggerCategory;
499     }
500     
501     /** @ejb:persistent-field */
502     public void setBloggerCategory(WeblogCategoryData bloggerCategory) {
503         this.bloggerCategory = bloggerCategory;
504     }
505     
506     /**
507      * By default,the default category for a weblog is the root and all macros
508      * work with the top level categories that are immediately under the root.
509      * Setting a different default category allows you to partition your weblog.
510      *
511      * @roller.wrapPojoMethod type="pojo"
512      * @ejb:persistent-field
513      * @hibernate.many-to-one column="defaultcatid" non-null="false"
514      */

515     public WeblogCategoryData getDefaultCategory() {
516         return defaultCategory;
517     }
518     
519     /** @ejb:persistent-field */
520     public void setDefaultCategory(WeblogCategoryData defaultCategory) {
521         this.defaultCategory = defaultCategory;
522     }
523     
524     /**
525      * @roller.wrapPojoMethod type="simple"
526      * @ejb:persistent-field
527      * @hibernate.property column="editorpage" non-null="true" unique="false"
528      */

529     public String JavaDoc getEditorPage() {
530         return this.editorPage;
531     }
532     
533     /** @ejb:persistent-field */
534     public void setEditorPage(String JavaDoc editorPage) {
535         this.editorPage = editorPage;
536     }
537     
538     /**
539      * @roller.wrapPojoMethod type="simple"
540      * @ejb:persistent-field
541      * @hibernate.property column="blacklist" non-null="true" unique="false"
542      */

543     public String JavaDoc getBlacklist() {
544         return this.blacklist;
545     }
546     
547     /** @ejb:persistent-field */
548     public void setBlacklist(String JavaDoc blacklist) {
549         this.blacklist = blacklist;
550     }
551     
552     /**
553      * @roller.wrapPojoMethod type="simple"
554      * @ejb:persistent-field
555      * @hibernate.property column="allowcomments" non-null="true" unique="false"
556      */

557     public Boolean JavaDoc getAllowComments() {
558         return this.allowComments;
559     }
560     
561     /** @ejb:persistent-field */
562     public void setAllowComments(Boolean JavaDoc allowComments) {
563         this.allowComments = allowComments;
564     }
565     
566     /**
567      * @roller.wrapPojoMethod type="simple"
568      * @ejb:persistent-field
569      * @hibernate.property column="defaultallowcomments" non-null="true" unique="false"
570      */

571     public Boolean JavaDoc getDefaultAllowComments() {
572         return defaultAllowComments;
573     }
574     
575     /** @ejb:persistent-field */
576     public void setDefaultAllowComments(Boolean JavaDoc defaultAllowComments) {
577         this.defaultAllowComments = defaultAllowComments;
578     }
579     
580     /**
581      * @roller.wrapPojoMethod type="simple"
582      * @ejb:persistent-field
583      * @hibernate.property column="defaultcommentdays" non-null="true" unique="false"
584      */

585     public int getDefaultCommentDays() {
586         return defaultCommentDays;
587     }
588     
589     /** @ejb:persistent-field */
590     public void setDefaultCommentDays(int defaultCommentDays) {
591         this.defaultCommentDays = defaultCommentDays;
592     }
593     
594     /**
595      * @roller.wrapPojoMethod type="simple"
596      * @ejb:persistent-field
597      * @hibernate.property column="commentmod" non-null="true" unique="false"
598      */

599     public Boolean JavaDoc getModerateComments() {
600         return moderateComments;
601     }
602     
603     /** @ejb:persistent-field */
604     public void setModerateComments(Boolean JavaDoc moderateComments) {
605         this.moderateComments = moderateComments;
606     }
607     
608     /**
609      * @roller.wrapPojoMethod type="simple"
610      * @ejb:persistent-field
611      * @hibernate.property column="emailcomments" non-null="true" unique="false"
612      */

613     public Boolean JavaDoc getEmailComments() {
614         return this.emailComments;
615     }
616     
617     /** @ejb:persistent-field */
618     public void setEmailComments(Boolean JavaDoc emailComments) {
619         this.emailComments = emailComments;
620     }
621     
622     /**
623      * @roller.wrapPojoMethod type="simple"
624      * @ejb:persistent-field
625      * @hibernate.property column="emailfromaddress" non-null="true" unique="false"
626      */

627     public String JavaDoc getEmailFromAddress() {
628         return this.emailFromAddress;
629     }
630     
631     /** @ejb:persistent-field */
632     public void setEmailFromAddress(String JavaDoc emailFromAddress) {
633         this.emailFromAddress = emailFromAddress;
634     }
635     
636     /**
637      * @ejb:persistent-field
638      * @roller.wrapPojoMethod type="simple"
639      * @hibernate.property column="emailaddress" non-null="true" unique="false"
640      */

641     public String JavaDoc getEmailAddress() {
642         return this.emailAddress;
643     }
644     
645     /** @ejb:persistent-field */
646     public void setEmailAddress(String JavaDoc emailAddress) {
647         this.emailAddress = emailAddress;
648     }
649     
650     /**
651      * EditorTheme of the Website.
652      *
653      * @roller.wrapPojoMethod type="simple"
654      * @ejb:persistent-field
655      * @hibernate.property column="editortheme" non-null="true" unique="false"
656      */

657     public String JavaDoc getEditorTheme() {
658         return this.editorTheme;
659     }
660     
661     /** @ejb:persistent-field */
662     public void setEditorTheme(String JavaDoc editorTheme) {
663         this.editorTheme = editorTheme;
664     }
665     
666     /**
667      * Locale of the Website.
668      *
669      * @roller.wrapPojoMethod type="simple"
670      * @ejb:persistent-field
671      * @hibernate.property column="locale" non-null="true" unique="false"
672      */

673     public String JavaDoc getLocale() {
674         return this.locale;
675     }
676     
677     /** @ejb:persistent-field */
678     public void setLocale(String JavaDoc locale) {
679         this.locale = locale;
680     }
681     
682     /**
683      * Timezone of the Website.
684      *
685      * @roller.wrapPojoMethod type="simple"
686      * @ejb:persistent-field
687      * @hibernate.property column="timeZone" non-null="true" unique="false"
688      */

689     public String JavaDoc getTimeZone() {
690         return this.timeZone;
691     }
692     
693     /** @ejb:persistent-field */
694     public void setTimeZone(String JavaDoc timeZone) {
695         this.timeZone = timeZone;
696     }
697     
698     /**
699      * @ejb:persistent-field
700      * @hibernate.property column="datecreated" non-null="true" unique="false"
701      * @roller.wrapPojoMethod type="simple"
702      */

703     public Date JavaDoc getDateCreated() {
704         if (dateCreated == null) {
705             return null;
706         } else {
707             return (Date JavaDoc)dateCreated.clone();
708         }
709     }
710     /** @ejb:persistent-field */
711     public void setDateCreated(final Date JavaDoc date) {
712         if (date != null) {
713             dateCreated = (Date JavaDoc)date.clone();
714         } else {
715             dateCreated = null;
716         }
717     }
718     
719     /**
720      * Comma-delimited list of user's default Plugins.
721      *
722      * @roller.wrapPojoMethod type="simple"
723      * @ejb:persistent-field
724      * @hibernate.property column="defaultplugins" non-null="false" unique="false"
725      */

726     public String JavaDoc getDefaultPlugins() {
727         return defaultPlugins;
728     }
729     
730     /** @ejb:persistent-field */
731     public void setDefaultPlugins(String JavaDoc string) {
732         defaultPlugins = string;
733     }
734     
735     public String JavaDoc toString() {
736         StringBuffer JavaDoc str = new StringBuffer JavaDoc("{");
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 JavaDoc 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.bloggerCategory);
799
//result = PojoUtil.addHashCode(result, this.defaultCategory);
800
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     /**
815      * Setter is needed in RollerImpl.storePersistentObject()
816      */

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     /**
848      * Parse locale value and instantiate a Locale object,
849      * otherwise return default Locale.
850      *
851      * @roller.wrapPojoMethod type="simple"
852      * @return Locale
853      */

854     public Locale JavaDoc getLocaleInstance() {
855         if (locale != null) {
856             String JavaDoc[] localeStr = StringUtils.split(locale,"_");
857             if (localeStr.length == 1) {
858                 if (localeStr[0] == null) localeStr[0] = "";
859                 return new Locale JavaDoc(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 JavaDoc(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 JavaDoc(localeStr[0], localeStr[1], localeStr[2]);
869             }
870         }
871         return Locale.getDefault();
872     }
873     
874     /**
875      * Return TimeZone instance for value of timeZone,
876      * otherwise return system default instance.
877      *
878      * @roller.wrapPojoMethod type="simple"
879      * @return TimeZone
880      */

881     public TimeZone JavaDoc 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     /**
894      * Returns true if user has all permissions specified by mask.
895      */

896     public boolean hasUserPermissions(UserData user, short mask) {
897         // look for user in website's permissions
898
PermissionsData userPerms = null;
899         Iterator JavaDoc 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 we found one, does it satisfy the mask?
908
if (userPerms != null && !userPerms.isPending()) {
909             if (userPerms != null && (userPerms.getPermissionMask() & mask) == mask) {
910                 return true;
911             }
912         }
913         // otherwise, check to see if user is a global admin
914
if (user != null && user.hasRole("admin")) return true;
915         return false;
916     }
917     
918     /** Get number of users associated with website */
919     public int getUserCount() {
920         return getPermissions().size();
921     }
922     
923     /** No-op needed to please XDoclet generated code */
924     private int userCount = 0;
925     public void setUserCount(int userCount) {
926         // no-op
927
}
928     
929     public int getAdminUserCount() {
930         int count = 0;
931         PermissionsData userPerms = null;
932         Iterator JavaDoc 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     /** No-op needed to please XDoclet generated code */
943     private int adminUserCount = 0;
944     public void setAdminUserCount(int adminUserCount) {
945         // no-op
946
}
947     
948     
949     /**
950      * @roller.wrapPojoMethod type="simple"
951      * @ejb:persistent-field
952      * @hibernate.property column="displaycnt" not-null="true"
953      */

954     public int getEntryDisplayCount() {
955         return entryDisplayCount;
956     }
957     
958     /**
959      * @ejb:persistent-field
960      */

961     public void setEntryDisplayCount(int entryDisplayCount) {
962         this.entryDisplayCount = entryDisplayCount;
963     }
964     
965     /**
966      * Set to FALSE to completely disable and hide this weblog from public view.
967      *
968      * @roller.wrapPojoMethod type="simple"
969      * @ejb:persistent-field
970      * @hibernate.property column="isenabled" non-null="true" unique="false"
971      */

972     public Boolean JavaDoc getEnabled() {
973         return this.enabled;
974     }
975     
976     /** @ejb:persistent-field */
977     public void setEnabled(Boolean JavaDoc enabled) {
978         this.enabled = enabled;
979     }
980     
981     /**
982      * Set to FALSE to exclude this weblog from community areas such as the
983      * front page and the planet page.
984      *
985      * @roller.wrapPojoMethod type="simple"
986      * @ejb:persistent-field
987      * @hibernate.property column="isactive" not-null="true"
988      */

989     public Boolean JavaDoc getActive() {
990         return active;
991     }
992     
993     public void setActive(Boolean JavaDoc active) {
994         this.active = active;
995     }
996     
997     /**
998      * Returns true if comment moderation is required by website or config.
999      */

1000    public boolean getCommentModerationRequired() {
1001        return (getModerateComments().booleanValue()
1002         || RollerRuntimeConfig.getBooleanProperty("users.moderation.required"));
1003    }
1004    
1005    /** No-op */
1006    public void setCommentModerationRequired(boolean modRequired) {}
1007
1008    
1009    /**
1010     * The last time any visible part of this weblog was modified.
1011     * This includes a change to weblog settings, entries, themes, templates,
1012     * comments, categories, bookmarks, folders, etc.
1013     *
1014     * Pings and Referrers are explicitly not included because pings to not
1015     * affect visible changes to a weblog, and referrers change so often that
1016     * it would diminish the usefulness of the attribute.
1017     *
1018     * @roller.wrapPojoMethod type="simple"
1019     * @ejb:persistent-field
1020     * @hibernate.property column="lastmodified" not-null="true"
1021     */

1022    public Date JavaDoc getLastModified() {
1023        return lastModified;
1024    }
1025
1026    public void setLastModified(Date JavaDoc lastModified) {
1027        this.lastModified = lastModified;
1028    }
1029  
1030    
1031    /**
1032     * Is multi-language blog support enabled for this weblog?
1033     *
1034     * If false then urls with various locale restrictions should fail.
1035     *
1036     * @roller.wrapPojoMethod type="simple"
1037     * @ejb:persistent-field
1038     * @hibernate.property column="enablemultilang" not-null="true"
1039     */

1040    public boolean isEnableMultiLang() {
1041        return enableMultiLang;
1042    }
1043
1044    public void setEnableMultiLang(boolean enableMultiLang) {
1045        this.enableMultiLang = enableMultiLang;
1046    }
1047    
1048    
1049    /**
1050     * Should the default weblog view show entries from all languages?
1051     *
1052     * If false then the default weblog view only shows entry from the
1053     * default locale chosen for this weblog.
1054     *
1055     * @roller.wrapPojoMethod type="simple"
1056     * @ejb:persistent-field
1057     * @hibernate.property column="showalllangs" not-null="true"
1058     */

1059    public boolean isShowAllLangs() {
1060        return showAllLangs;
1061    }
1062
1063    public void setShowAllLangs(boolean showAllLangs) {
1064        this.showAllLangs = showAllLangs;
1065    }
1066    
1067    
1068    /**
1069     * @roller.wrapPojoMethod type="simple"
1070     */

1071    public String JavaDoc getURL() {
1072        // TODO: ATLAS reconcile entry.getPermaLink() with new URLs
1073
String JavaDoc relPath = RollerRuntimeConfig.getRelativeContextURL();
1074        return relPath + "/" + getHandle();
1075        //return URLUtilities.getWeblogURL(this, null, false);
1076
}
1077    public void setURL(String JavaDoc url) {
1078        // noop
1079
}
1080    
1081    
1082    /**
1083     * @roller.wrapPojoMethod type="simple"
1084     */

1085    public String JavaDoc getAbsoluteURL() {
1086        // TODO: ATLAS reconcile entry.getPermaLink() with new URLs
1087
String JavaDoc relPath = RollerRuntimeConfig.getAbsoluteContextURL();
1088        return relPath + "/" + getHandle();
1089        //return URLUtilities.getWeblogURL(this, null, true);
1090
}
1091    public void setAbsoluteURL(String JavaDoc url) {
1092        // noop
1093
}
1094    
1095    
1096    /**
1097     * Comma-separated list of additional page models to be created when this
1098     * weblog is rendered.
1099     *
1100     * @ejb:persistent-field
1101     * @hibernate.property column="pagemodels" not-null="false"
1102     */

1103    public String JavaDoc getPageModels() {
1104        return pageModels;
1105    }
1106    public void setPageModels(String JavaDoc pageModels) {
1107        this.pageModels = pageModels;
1108    }
1109
1110    
1111    /**
1112     * Get initialized plugins for use during rendering process.
1113     */

1114    public Map JavaDoc 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 JavaDoc e) {
1121                this.log.error("ERROR: initializing plugins");
1122            }
1123        }
1124        return initializedPlugins;
1125    }
1126    
1127    
1128    /**
1129     * Returns categories under the default category of the weblog.
1130     * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.WeblogCategoryData"
1131     */

1132    public List JavaDoc getWeblogCategories() {
1133        List JavaDoc ret = new ArrayList JavaDoc();
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    /**
1145     * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.WeblogCategoryData"
1146     */

1147    public List JavaDoc getWeblogCategories(String JavaDoc categoryPath) {
1148        List JavaDoc ret = new ArrayList JavaDoc();
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    /**
1167     * @roller.wrapPojoMethod type="pojo" class="org.apache.roller.pojos.WeblogCategoryData"
1168     */

1169    public WeblogCategoryData getWeblogCategory(String JavaDoc 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    /**
1187     * Get up to 100 most recent published entries in weblog.
1188     * @param cat Category path or null for no category restriction
1189     * @param length Max entries to return (1-100)
1190     * @return List of weblog entry objects.
1191     *
1192     * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.WeblogEntryData"
1193     */

1194    public List JavaDoc getRecentWeblogEntries(String JavaDoc cat, int length) {
1195        if (cat != null && "nil".equals(cat)) cat = null;
1196        if (length > 100) length = 100;
1197        List JavaDoc recentEntries = new ArrayList JavaDoc();
1198        if (length < 1) return recentEntries;
1199        try {
1200            WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
1201            recentEntries = wmgr.getWeblogEntries(
1202                    this,
1203                    null, // user
1204
null, // startDate
1205
new Date JavaDoc(), // endDate
1206
cat, // cat or null
1207
WeblogEntryData.PUBLISHED,
1208                    "pubTime", // sortby
1209
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    /**
1220     * Get up to 100 most recent approved and non-spam comments in weblog.
1221     * @param length Max entries to return (1-100)
1222     * @return List of comment objects.
1223     *
1224     * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.CommentData"
1225     */

1226    public List JavaDoc getRecentComments(int length) {
1227        if (length > 100) length = 100;
1228        List JavaDoc recentComments = new ArrayList JavaDoc();
1229        if (length < 1) return recentComments;
1230        try {
1231            WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
1232            recentComments = wmgr.getComments(
1233                    this,
1234                    null, // weblog entry
1235
null, // search String
1236
null, // startDate
1237
null, // endDate
1238
null, // pending
1239
Boolean.TRUE, // approved only
1240
Boolean.FALSE, // no spam
1241
true, // we want reverse chrono order
1242
0, // offset
1243
length); // length
1244
} catch (RollerException e) {
1245            log.error("ERROR: getting recent comments", e);
1246        }
1247        return recentComments;
1248    }
1249
1250    
1251    /**
1252     * Get bookmark folder by name.
1253     * @param folderName Name or path of bookmark folder to be returned (null for root)
1254     * @return Folder object requested.
1255     *
1256     * @roller.wrapPojoMethod type="pojo" class="org.apache.roller.pojos.FolderData"
1257     */

1258    public FolderData getBookmarkFolder(String JavaDoc 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    /**
1276     * Return collection of referrers for current day.
1277     * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.pojos.RefererData"
1278     */

1279    public List JavaDoc getTodaysReferrers() {
1280        List JavaDoc 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    /** No-op method to please XDoclet */
1293    public void setTodaysReferrers(List JavaDoc ignored) {}
1294    
1295    /**
1296     * Get number of hits counted today.
1297     * @roller.wrapPojoMethod type="simple"
1298     */

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    /** No-op method to please XDoclet */
1311    public void setTodaysHits(int ignored) {}
1312}
1313
1314
Popular Tags