KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.roller.pojos;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.roller.RollerException;
5 import org.roller.model.Roller;
6 import org.roller.model.RollerFactory;
7 import org.roller.util.PojoUtil;
8
9 import java.util.Locale JavaDoc;
10 import java.util.TimeZone JavaDoc;
11 /**
12  * A user's website is a weweblog, newsfeed channels and bookmarks.
13  * @author David M Johnson
14  *
15  * @ejb:bean name="WebsiteData"
16  * @struts.form include-all="true"
17  * @hibernate.class table="website"
18  * hibernate.jcs-cache usage="read-write"
19  */

20 public class WebsiteData extends org.roller.pojos.PersistentObject
21     implements java.io.Serializable JavaDoc
22 {
23     static final long serialVersionUID = 206437645033737127L;
24     protected java.lang.String JavaDoc id;
25     protected java.lang.String JavaDoc name;
26     protected java.lang.String JavaDoc description;
27     protected java.lang.String JavaDoc defaultPageId;
28     protected java.lang.String JavaDoc weblogDayPageId;
29     protected java.lang.Boolean JavaDoc enableBloggerApi;
30     protected WeblogCategoryData bloggerCategory;
31     protected WeblogCategoryData defaultCategory;
32     protected java.lang.String JavaDoc editorPage;
33     protected java.lang.String JavaDoc ignoreWords;
34     protected java.lang.Boolean JavaDoc allowComments;
35     protected java.lang.Boolean JavaDoc emailComments;
36     protected java.lang.String JavaDoc emailFromAddress;
37     protected java.lang.String JavaDoc editorTheme;
38     protected java.lang.String JavaDoc locale;
39     protected java.lang.String JavaDoc timezone;
40     protected java.lang.String JavaDoc mDefaultPlugins;
41     protected java.lang.Boolean JavaDoc isEnabled;
42
43     protected UserData mUser = null;
44
45     public WebsiteData()
46     {
47     }
48
49     public WebsiteData(final java.lang.String JavaDoc id,
50                        final java.lang.String JavaDoc name,
51                        final java.lang.String JavaDoc description,
52                        final UserData user,
53                        final java.lang.String JavaDoc defaultPageId,
54                        final java.lang.String JavaDoc weblogDayPageId,
55                        final java.lang.Boolean JavaDoc enableBloggerApi,
56                        final WeblogCategoryData bloggerCategory,
57                        final WeblogCategoryData defaultCategory,
58                        final java.lang.String JavaDoc editorPage,
59                        final java.lang.String JavaDoc ignoreWords,
60                        final java.lang.Boolean JavaDoc allowComments,
61                        final java.lang.Boolean JavaDoc emailComments,
62                        final java.lang.String JavaDoc emailFromAddress,
63                        final java.lang.Boolean JavaDoc isEnabled)
64     {
65         this.id = id;
66         this.name = name;
67         this.description = description;
68         this.mUser = user;
69         this.defaultPageId = defaultPageId;
70         this.weblogDayPageId = weblogDayPageId;
71         this.enableBloggerApi = enableBloggerApi;
72         this.bloggerCategory = bloggerCategory;
73         this.defaultCategory = defaultCategory;
74         this.editorPage = editorPage;
75         this.ignoreWords = ignoreWords;
76         this.allowComments = allowComments;
77         this.emailComments = emailComments;
78         this.emailFromAddress = emailFromAddress;
79         this.isEnabled = isEnabled;
80     }
81
82     public WebsiteData(WebsiteData otherData)
83     {
84         this.setData(otherData);
85     }
86
87     /**
88      * Id of the Website.
89      * @ejb:persistent-field
90      * @hibernate.id column="id" type="string"
91      * generator-class="uuid.hex" unsaved-value="null"
92      */

93     public java.lang.String JavaDoc getId()
94     {
95         return this.id;
96     }
97
98     /** @ejb:persistent-field */
99     public void setId(java.lang.String JavaDoc id)
100     {
101         this.id = id;
102     }
103
104     /**
105      * Name of the Website.
106      * @ejb:persistent-field
107      * @hibernate.property column="name" non-null="true" unique="false"
108      */

109     public java.lang.String JavaDoc getName()
110     {
111         return this.name;
112     }
113
114     /** @ejb:persistent-field */
115     public void setName(java.lang.String JavaDoc name)
116     {
117         this.name = name;
118     }
119
120     /**
121      * Description
122      * @ejb:persistent-field
123      * @hibernate.property column="description" non-null="true" unique="false"
124      */

125     public java.lang.String JavaDoc getDescription()
126     {
127         return this.description;
128     }
129
130     /** @ejb:persistent-field */
131     public void setDescription(java.lang.String JavaDoc description)
132     {
133         this.description = description;
134     }
135
136     /**
137      * Id of owner.
138      * @ejb:persistent-field
139      * @hibernate.many-to-one column="userid" cascade="none" not-null="true"
140      */

141     public org.roller.pojos.UserData getUser()
142     {
143         return mUser;
144     }
145
146     /** @ejb:persistent-field */
147     public void setUser( org.roller.pojos.UserData ud )
148     {
149         mUser = ud;
150     }
151
152     /**
153      * @ejb:persistent-field
154      * @hibernate.property column="defaultpageid" non-null="true" unique="false"
155      */

156     public java.lang.String JavaDoc getDefaultPageId()
157     {
158         return this.defaultPageId;
159     }
160
161     /**
162      * @ejb:persistent-field
163      */

164     public void setDefaultPageId(java.lang.String JavaDoc defaultPageId)
165     {
166         this.defaultPageId = defaultPageId;
167     }
168
169     /**
170      * @deprecated
171      * @ejb:persistent-field
172      * @hibernate.property column="weblogdayid" non-null="true" unique="false"
173      */

174     public java.lang.String JavaDoc getWeblogDayPageId()
175     {
176         return this.weblogDayPageId;
177     }
178
179     /**
180      * @deprecated
181      * @ejb:persistent-field
182      */

183     public void setWeblogDayPageId(java.lang.String JavaDoc weblogDayPageId)
184     {
185         this.weblogDayPageId = weblogDayPageId;
186     }
187
188     /**
189      * @ejb:persistent-field
190      * @hibernate.property column="enablebloggerapi" non-null="true" unique="false"
191      */

192     public java.lang.Boolean JavaDoc getEnableBloggerApi()
193     {
194         return this.enableBloggerApi;
195     }
196
197     /** @ejb:persistent-field */
198     public void setEnableBloggerApi(java.lang.Boolean JavaDoc enableBloggerApi)
199     {
200         this.enableBloggerApi = enableBloggerApi;
201     }
202
203     /**
204      * @ejb:persistent-field
205      *
206      * @hibernate.many-to-one column="bloggercatid" non-null="false"
207      */

208     public WeblogCategoryData getBloggerCategory()
209     {
210         return bloggerCategory;
211     }
212
213     /** @ejb:persistent-field */
214     public void setBloggerCategory(WeblogCategoryData bloggerCategory)
215     {
216         this.bloggerCategory = bloggerCategory;
217     }
218
219     /**
220      * By default,the default category for a weblog is the root and all macros
221      * work with the top level categories that are immediately under the root.
222      * Setting a different default category allows you to partition your weblog.
223      *
224      * @ejb:persistent-field
225      *
226      * @hibernate.many-to-one column="defaultcatid" non-null="false"
227      */

228     public WeblogCategoryData getDefaultCategory()
229     {
230         return defaultCategory;
231     }
232
233     /** @ejb:persistent-field */
234     public void setDefaultCategory(WeblogCategoryData defaultCategory)
235     {
236         this.defaultCategory = defaultCategory;
237     }
238
239     /**
240      * @ejb:persistent-field
241      * @hibernate.property column="editorpage" non-null="true" unique="false"
242      */

243     public java.lang.String JavaDoc getEditorPage()
244     {
245         return this.editorPage;
246     }
247
248     /** @ejb:persistent-field */
249     public void setEditorPage(java.lang.String JavaDoc editorPage)
250     {
251         this.editorPage = editorPage;
252     }
253
254     /**
255      * @ejb:persistent-field
256      * @hibernate.property column="ignorewords" non-null="true" unique="false"
257      */

258     public java.lang.String JavaDoc getIgnoreWords()
259     {
260         return this.ignoreWords;
261     }
262
263     /** @ejb:persistent-field */
264     public void setIgnoreWords(java.lang.String JavaDoc ignoreWords)
265     {
266         this.ignoreWords = ignoreWords;
267     }
268
269     /**
270      * @ejb:persistent-field
271      * @hibernate.property column="allowcomments" non-null="true" unique="false"
272      */

273     public java.lang.Boolean JavaDoc getAllowComments()
274     {
275         return this.allowComments;
276     }
277
278     /** @ejb:persistent-field */
279     public void setAllowComments(java.lang.Boolean JavaDoc allowComments)
280     {
281         this.allowComments = allowComments;
282     }
283
284     /**
285      * @ejb:persistent-field
286      * @hibernate.property column="emailcomments" non-null="true" unique="false"
287      */

288     public java.lang.Boolean JavaDoc getEmailComments()
289     {
290         return this.emailComments;
291     }
292
293     /** @ejb:persistent-field */
294     public void setEmailComments(java.lang.Boolean JavaDoc emailComments)
295     {
296         this.emailComments = emailComments;
297     }
298     
299     /**
300      * @ejb:persistent-field
301      * @hibernate.property column="emailfromaddress" non-null="true" unique="false"
302      */

303     public java.lang.String JavaDoc getEmailFromAddress()
304     {
305         return this.emailFromAddress;
306     }
307
308     /** @ejb:persistent-field */
309     public void setEmailFromAddress(java.lang.String JavaDoc emailFromAddress)
310     {
311         this.emailFromAddress = emailFromAddress;
312     }
313     
314     /**
315      * EditorTheme of the Website.
316      * @ejb:persistent-field
317      * @hibernate.property column="editortheme" non-null="true" unique="false"
318      */

319     public java.lang.String JavaDoc getEditorTheme()
320     {
321         return this.editorTheme;
322     }
323
324     /** @ejb:persistent-field */
325     public void setEditorTheme(java.lang.String JavaDoc editorTheme)
326     {
327         this.editorTheme = editorTheme;
328     }
329
330     /**
331      * Locale of the Website.
332      * @ejb:persistent-field
333      * @hibernate.property column="locale" non-null="true" unique="false"
334      */

335     public java.lang.String JavaDoc getLocale()
336     {
337         return this.locale;
338     }
339
340     /** @ejb:persistent-field */
341     public void setLocale(java.lang.String JavaDoc locale)
342     {
343         this.locale = locale;
344     }
345
346     /**
347      * Timezone of the Website.
348      * @ejb:persistent-field
349      * @hibernate.property column="timezone" non-null="true" unique="false"
350      */

351     public java.lang.String JavaDoc getTimezone()
352     {
353         return this.timezone;
354     }
355
356     /** @ejb:persistent-field */
357     public void setTimezone(java.lang.String JavaDoc timezone)
358     {
359         this.timezone = timezone;
360     }
361
362     /**
363      * Comma-delimited list of user's default Plugins.
364      * @ejb:persistent-field
365      * @hibernate.property column="defaultplugins" non-null="false" unique="false"
366      */

367     public java.lang.String JavaDoc getDefaultPlugins()
368     {
369         return mDefaultPlugins;
370     }
371
372     /** @ejb:persistent-field */
373     public void setDefaultPlugins(java.lang.String JavaDoc string)
374     {
375         mDefaultPlugins = string;
376     }
377
378     /**
379      * @ejb:persistent-field
380      * @hibernate.property column="isenabled" non-null="true" unique="false"
381      */

382     public java.lang.Boolean JavaDoc getIsEnabled()
383     {
384         return this.isEnabled;
385     }
386     
387     /** @ejb:persistent-field */
388     public void setIsEnabled(java.lang.Boolean JavaDoc isEnabled)
389     {
390         this.isEnabled = isEnabled;
391     }
392
393     public String JavaDoc toString()
394     {
395         StringBuffer JavaDoc str = new StringBuffer JavaDoc("{");
396
397         str.append("id=" + id + " " + "name=" + name + " " + "description=" +
398                    description + " " +
399                    "defaultPageId=" + defaultPageId + " " +
400                    "weblogDayPageId=" + weblogDayPageId + " " +
401                    "enableBloggerApi=" + enableBloggerApi + " " +
402                    "bloggerCategory=" + bloggerCategory + " " +
403                    "defaultCategory=" + defaultCategory + " " +
404                    "editorPage=" + editorPage + " " +
405                    "ignoreWords=" + ignoreWords + " " +
406                    "allowComments=" + allowComments + " " +
407                    "emailComments=" + emailComments + " " +
408                    "emailFromAddress=" + emailFromAddress + " " +
409                    "editorTheme=" + editorTheme + " " +
410                    "locale=" + locale + " " +
411                    "timezone=" + timezone + " " +
412                    "defaultPlugins=" + mDefaultPlugins);
413         str.append('}');
414
415         return (str.toString());
416     }
417
418     public boolean equals(Object JavaDoc pOther)
419     {
420         if (pOther instanceof WebsiteData)
421         {
422             WebsiteData lTest = (WebsiteData) pOther;
423             boolean lEquals = true;
424
425             lEquals = PojoUtil.equals(lEquals, this.id, lTest.id);
426
427             lEquals = PojoUtil.equals(lEquals, this.name, lTest.name);
428
429             lEquals = PojoUtil.equals(lEquals, this.description, lTest.description);
430
431             lEquals = PojoUtil.equals(lEquals, this.mUser, lTest.mUser);
432
433             lEquals = PojoUtil.equals(lEquals, this.defaultPageId, lTest.defaultPageId);
434
435             lEquals = PojoUtil.equals(lEquals, this.weblogDayPageId, lTest.weblogDayPageId);
436
437             lEquals = PojoUtil.equals(lEquals, this.enableBloggerApi, lTest.enableBloggerApi);
438
439             lEquals = PojoUtil.equals(lEquals, this.bloggerCategory.getId(), lTest.bloggerCategory.getId());
440
441             lEquals = PojoUtil.equals(lEquals, this.defaultCategory.getId(), lTest.defaultCategory.getId());
442
443             lEquals = PojoUtil.equals(lEquals, this.editorPage, lTest.editorPage);
444
445             lEquals = PojoUtil.equals(lEquals, this.ignoreWords, lTest.ignoreWords);
446
447             lEquals = PojoUtil.equals(lEquals, this.allowComments, lTest.allowComments);
448             
449             lEquals = PojoUtil.equals(lEquals, this.emailComments, lTest.emailComments);
450             
451             lEquals = PojoUtil.equals(lEquals, this.emailFromAddress, lTest.emailFromAddress);
452
453             lEquals = PojoUtil.equals(lEquals, this.editorTheme, lTest.editorTheme);
454
455             lEquals = PojoUtil.equals(lEquals, this.locale, lTest.locale);
456
457             lEquals = PojoUtil.equals(lEquals, this.timezone, lTest.timezone);
458
459             lEquals = PojoUtil.equals(lEquals, this.mDefaultPlugins, lTest.mDefaultPlugins);
460             
461             return lEquals;
462         }
463         else
464         {
465             return false;
466         }
467     }
468
469     public int hashCode()
470     {
471         int result = 17;
472         result = PojoUtil.addHashCode(result, this.id);
473         result = PojoUtil.addHashCode(result, this.name);
474         result = PojoUtil.addHashCode(result, this.description);
475         result = PojoUtil.addHashCode(result, this.mUser);
476         result = PojoUtil.addHashCode(result, this.defaultPageId);
477         result = PojoUtil.addHashCode(result, this.weblogDayPageId);
478         result = PojoUtil.addHashCode(result, this.enableBloggerApi);
479         //result = PojoUtil.addHashCode(result, this.bloggerCategory);
480
//result = PojoUtil.addHashCode(result, this.defaultCategory);
481
result = PojoUtil.addHashCode(result, this.editorPage);
482         result = PojoUtil.addHashCode(result, this.ignoreWords);
483         result = PojoUtil.addHashCode(result, this.allowComments);
484         result = PojoUtil.addHashCode(result, this.emailComments);
485         result = PojoUtil.addHashCode(result, this.emailFromAddress);
486         result = PojoUtil.addHashCode(result, this.editorTheme);
487         result = PojoUtil.addHashCode(result, this.locale);
488         result = PojoUtil.addHashCode(result, this.timezone);
489         result = PojoUtil.addHashCode(result, this.mDefaultPlugins);
490
491         return result;
492     }
493
494     /**
495      * Setter is needed in RollerImpl.storePersistentObject()
496      */

497     public void setData(org.roller.pojos.PersistentObject otherData)
498     {
499         WebsiteData other = (WebsiteData)otherData;
500
501         this.id = other.id;
502         this.name = other.name;
503         this.description = other.description;
504         this.mUser = other.mUser;
505         this.defaultPageId = other.defaultPageId;
506         this.weblogDayPageId = other.weblogDayPageId;
507         this.enableBloggerApi = other.enableBloggerApi;
508         this.bloggerCategory = other.bloggerCategory;
509         this.defaultCategory = other.defaultCategory;
510         this.editorPage = other.editorPage;
511         this.ignoreWords = other.ignoreWords;
512         this.allowComments = other.allowComments;
513         this.emailComments = other.emailComments;
514         this.emailFromAddress = other.emailFromAddress;
515         this.editorTheme = other.editorTheme;
516         this.locale = other.locale;
517         this.timezone = other.timezone;
518         this.mDefaultPlugins = other.mDefaultPlugins;
519         this.isEnabled = other.isEnabled;
520     }
521     
522     /**
523      * Parse locale value and instantiate a Locale object,
524      * otherwise return default Locale.
525      * @return Locale
526      */

527     public Locale JavaDoc getLocaleInstance()
528     {
529         if (locale != null)
530         {
531             String JavaDoc[] localeStr = StringUtils.split(locale,"_");
532             if (localeStr.length == 1)
533             {
534                 if (localeStr[0] == null) localeStr[0] = "";
535                 return new Locale JavaDoc(localeStr[0]);
536             }
537             else if (localeStr.length == 2)
538             {
539                 if (localeStr[0] == null) localeStr[0] = "";
540                 if (localeStr[1] == null) localeStr[1] = "";
541                 return new Locale JavaDoc(localeStr[0], localeStr[1]);
542             }
543             else if (localeStr.length == 3)
544             {
545                 if (localeStr[0] == null) localeStr[0] = "";
546                 if (localeStr[1] == null) localeStr[1] = "";
547                 if (localeStr[2] == null) localeStr[2] = "";
548                 return new Locale JavaDoc(localeStr[0], localeStr[1], localeStr[2]);
549             }
550         }
551         return Locale.getDefault();
552     }
553     
554     /**
555      * Return TimeZone instance for value of timezone,
556      * otherwise return system default instance.
557      * @return TimeZone
558      */

559     public TimeZone JavaDoc getTimeZoneInstance()
560     {
561         if (timezone == null)
562         {
563             if (TimeZone.getDefault() != null)
564             {
565                 this.setTimezone( TimeZone.getDefault().getID() );
566             }
567             else
568             {
569                 this.setTimezone("America/New_York");
570             }
571         }
572         return TimeZone.getTimeZone(timezone);
573     }
574     
575     /**
576      * @see org.roller.pojos.PersistentObject#remove()
577      */

578     public void remove() throws RollerException
579     {
580         RollerFactory.getRoller().getUserManager().removeWebsiteContents(this);
581         super.remove();
582     }
583
584     public boolean canSave() throws RollerException
585     {
586         Roller roller = RollerFactory.getRoller();
587         if (roller.getUser().equals(UserData.SYSTEM_USER))
588         {
589             return true;
590         }
591         if (roller.getUser().equals(getUser()))
592         {
593             return true;
594         }
595         return false;
596     }
597
598 }
Popular Tags