KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > pojo > Blog


1 /*
2  * $Id: Blog.java,v 1.10 2005/01/09 19:02:00 michelson Exp $
3  *
4  * Copyright (c) 2004 j2biz Group, http://www.j2biz.com
5  * Koeln / Duesseldorf , Germany
6  *
7  * @author Max Kalina
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */

25
26 package com.j2biz.blogunity.pojo;
27
28 import java.io.File JavaDoc;
29 import java.io.Serializable JavaDoc;
30 import java.util.Date JavaDoc;
31 import java.util.HashSet JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.Set JavaDoc;
34 import java.util.TreeSet JavaDoc;
35
36 import net.sf.hibernate.Validatable;
37 import net.sf.hibernate.ValidationFailure;
38
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41
42 import com.j2biz.blogunity.BlogunityManager;
43 import com.j2biz.blogunity.util.BlogUtils;
44 import com.j2biz.blogunity.util.CategoryComparator;
45 import com.j2biz.blogunity.util.EntryComparator;
46 import com.j2biz.blogunity.util.LinkComparator;
47 import com.j2biz.blogunity.util.RefererComparator;
48 import com.j2biz.blogunity.util.UserComparator;
49 import com.j2biz.blogunity.util.VisitedPageComparator;
50
51 /**
52  * @hibernate.class table="BLOGS" dynamic-insert = "true" dynamic-update =
53  * "true"
54  *
55  * @author michelson
56  * @version $$
57  * @since 0.1
58  *
59  *
60  */

61 public class Blog implements Validatable, Serializable JavaDoc {
62     /**
63      * Comment for <code>serialVersionUID</code>
64      */

65     private static final long serialVersionUID = 3546084648699312176L;
66
67     /**
68      * Logger for this class
69      */

70     private static final Log log = LogFactory.getLog(Blog.class);
71
72     public static final int INDIVIDUAL_BLOG = 0;
73
74     public static final int COMMUNITY_BLOG = 1;
75
76     public static final int PUBLIC_COMMUNTIY = 0;
77
78     public static final int PRIVATE_COMMUNTIY = 1;
79
80     private Long JavaDoc id;
81
82     private String JavaDoc urlName;
83
84     private String JavaDoc fullName;
85
86     private String JavaDoc description;
87
88     private String JavaDoc keywords;
89
90     private Date JavaDoc createTime = new Date JavaDoc();
91
92     private Date JavaDoc lastModified = new Date JavaDoc();
93
94     private User founder;
95
96     private Set JavaDoc /* <User> */contributors = new TreeSet JavaDoc(new UserComparator());
97
98     private Set JavaDoc /* <User> */waitingForAcceptanceUsers = new TreeSet JavaDoc(new UserComparator());
99
100     private Set JavaDoc /* <Entry> */entries = new TreeSet JavaDoc(new EntryComparator());
101
102     private Set JavaDoc calendarEntries = new HashSet JavaDoc();
103
104     private Set JavaDoc /* <Category> */categories = new TreeSet JavaDoc(new CategoryComparator());
105
106     private Set JavaDoc /* <Link> */links = new TreeSet JavaDoc(new LinkComparator());
107
108     private int type = INDIVIDUAL_BLOG;
109
110     private int communityType;
111
112     private Set JavaDoc /* <VisitedPage> */todayVisitedPages = new TreeSet JavaDoc(new VisitedPageComparator());
113
114     private Set JavaDoc /* <Referer> */todayReferers = new TreeSet JavaDoc(new RefererComparator());
115
116     private transient File JavaDoc mainDataDirectory;
117
118     private transient File JavaDoc themeDirectory;
119
120     private transient File JavaDoc indexesDirectory;
121
122     private transient File JavaDoc imagesDirectory;
123
124     private transient File JavaDoc filesDirectory;
125
126     private transient File JavaDoc logsDirectory;
127
128     /**
129      *
130      */

131     public Blog() {
132         super();
133     }
134
135     /**
136      * @hibernate.set name="categories" table="BLOG_CATEGORIES"
137      * sort="com.j2biz.blogunity.util.CategoryComparator"
138      * cascade="delete" inverse="false" lazy="true"
139      * @hibernate.collection-key column="BLOG_ID"
140      * @hibernate.collection-many-to-many class="com.j2biz.blogunity.pojo.Category"
141      * column="CATEGORY_ID"
142      *
143      *
144      * @return Returns the categories.
145      */

146     public Set JavaDoc getCategories() {
147         return categories;
148     }
149
150     /**
151      * @param categories
152      * The categories to set.
153      */

154     public void setCategories(Set JavaDoc categories) {
155         this.categories = categories;
156     }
157
158     public void addCategory(Category category) {
159         categories.add(category);
160     }
161
162     /**
163      * Returns global categories associated with the given blog.
164      *
165      * @return global categories associated with the given blog.
166      */

167     public Set JavaDoc getGlobalCategories() {
168
169         Set JavaDoc global = new TreeSet JavaDoc(new CategoryComparator());
170         Iterator JavaDoc it = categories.iterator();
171
172         while (it.hasNext()) {
173             Category c = (Category) it.next();
174             if (c.getType() == Category.GLOBAL) global.add(c);
175         }
176
177         return global;
178
179     }
180
181     /**
182      * Returns local categories associated with the given blog.
183      *
184      * @return local categories associated with the given blog.
185      */

186     public Set JavaDoc getLocalCategories() {
187         Set JavaDoc local = new TreeSet JavaDoc(new CategoryComparator());
188         Iterator JavaDoc it = categories.iterator();
189
190         while (it.hasNext()) {
191             Category c = (Category) it.next();
192             if (c.getType() == Category.LOCAL) local.add(c);
193         }
194
195         return local;
196     }
197
198     /**
199      * @hibernate.set name="contributors" table="BLOG_CONTRIBUTORS" cascade
200      * ="none" sort="com.j2biz.blogunity.util.UserComparator"
201      * inverse="true" lazy="true"
202      * @hibernate.collection-key column="BLOG_ID"
203      * @hibernate.collection-many-to-many class="com.j2biz.blogunity.pojo.User"
204      * column="CONTRIBUTOR_ID"
205      *
206      * @return Returns the contributors.
207      */

208     public Set JavaDoc getContributors() {
209         return contributors;
210     }
211
212     /**
213      * @param contributors
214      * The contributors to set.
215      */

216     public void setContributors(Set JavaDoc contributors) {
217         this.contributors = contributors;
218     }
219
220     public void addContributor(User contributor) {
221         contributors.add(contributor);
222     }
223
224     /**
225      * @hibernate.set name="waitingForAcceptanceUsers"
226      * table="BLOG_WAITING_ACCEPTANCE_USERS" cascade ="none"
227      * sort="com.j2biz.blogunity.util.UserComparator"
228      * inverse="true" lazy="true"
229      * @hibernate.collection-key column="BLOG_ID"
230      * @hibernate.collection-many-to-many class="com.j2biz.blogunity.pojo.User"
231      * column="CONTRIBUTOR_ID"
232      *
233      * @return Returns the waitingForAcceptanceUsers.
234      */

235     public Set JavaDoc getWaitingForAcceptanceUsers() {
236         return waitingForAcceptanceUsers;
237     }
238
239     /**
240      * @param waitingForAcceptanceUsers
241      * The waitingForAcceptanceUsers to set.
242      */

243     public void setWaitingForAcceptanceUsers(Set JavaDoc waitingForAcceptanceUsers) {
244         this.waitingForAcceptanceUsers = waitingForAcceptanceUsers;
245     }
246
247     public void addWaitingForAcceptanceUser(User user) {
248         waitingForAcceptanceUsers.add(user);
249     }
250
251     /**
252      * @hibernate.property name="createTime" column="CREATE_TIME"
253      * type="timestamp" not-null="true" unique="false"
254      *
255      * @return Returns the createTime.
256      */

257     public Date JavaDoc getCreateTime() {
258         return createTime;
259     }
260
261     /**
262      * @param createTime
263      * The createTime to set.
264      */

265     public void setCreateTime(Date JavaDoc createTime) {
266         this.createTime = createTime;
267     }
268
269     /**
270      * @hibernate.property name="lastModified" column="LAST_MODIFIED"
271      * type="timestamp" not-null="true" unique="false"
272      *
273      * @return Returns the lastModified.
274      */

275     public Date JavaDoc getLastModified() {
276         return lastModified;
277     }
278
279     /**
280      * @param lastModified
281      * The lastModified to set.
282      */

283     public void setLastModified(Date JavaDoc lastModified) {
284         this.lastModified = lastModified;
285     }
286
287     /**
288      * @hibernate.property name="description" column="DESCRIPTION" type="text"
289      * not-null="false" unique="false"
290      *
291      * @return Returns the description.
292      */

293     public String JavaDoc getDescription() {
294         return description;
295     }
296
297     /**
298      * @param description
299      * The description to set.
300      */

301     public void setDescription(String JavaDoc description) {
302         this.description = description;
303     }
304
305     /**
306      * @hibernate.property name="keywords" column="KEYWORDS" type="text"
307      * not-null="false" unique="false"
308      *
309      * @return Returns the keywords.
310      */

311     public String JavaDoc getKeywords() {
312         return keywords;
313     }
314
315     /**
316      * @param keywords
317      * The keywords to set.
318      */

319     public void setKeywords(String JavaDoc keywords) {
320         this.keywords = keywords;
321     }
322
323     /**
324      * @hibernate.set name="entries" inverse="true"
325      * sort="com.j2biz.blogunity.util.EntryComparator"
326      * cascade="delete" lazy="true"
327      * @hibernate.collection-key column="BLOG_ID"
328      * @hibernate.collection-one-to-many class="com.j2biz.blogunity.pojo.Entry"
329      *
330      *
331      * @return Returns the entries.
332      */

333     public Set JavaDoc getEntries() {
334         return entries;
335     }
336
337     /**
338      * @param entries
339      * The entries to set.
340      */

341     public void setEntries(Set JavaDoc entries) {
342         this.entries = entries;
343     }
344
345     public void addEntry(Entry entry) {
346         entries.add(entry);
347     }
348
349     /**
350      * @hibernate.id generator-class="increment" type="long" column="ID"
351      * unsaved-value="null"
352      *
353      * @return Returns the id.
354      */

355     public Long JavaDoc getId() {
356         return id;
357     }
358
359     /**
360      * @param id
361      * The id to set.
362      */

363     public void setId(Long JavaDoc id) {
364         this.id = id;
365     }
366
367     /**
368      * @hibernate.property name="urlName" column="URL_NAME" type="string"
369      * not-null="true" unique="true" length="20"
370      *
371      * @return Returns the urlName.
372      */

373     public String JavaDoc getUrlName() {
374         return urlName;
375     }
376
377     /**
378      * @param urlName
379      * The urlName to set.
380      */

381     public void setUrlName(String JavaDoc name) {
382         this.urlName = name;
383     }
384
385     /**
386      * @hibernate.property name="fullName" column="FULL_NAME" type="string"
387      * not-null="true" unique="false" length="50"
388      *
389      * @return
390      */

391     public String JavaDoc getFullName() {
392         return fullName;
393     }
394
395     /**
396      * @param fullName
397      */

398     public void setFullName(String JavaDoc fullName) {
399         this.fullName = fullName;
400     }
401
402     /**
403      * @hibernate.many-to-one column="FOUNDER_ID"
404      * class="com.j2biz.blogunity.pojo.User"
405      *
406      * @return Returns the founder.
407      */

408     public User getFounder() {
409         return founder;
410     }
411
412     /**
413      * @param founder
414      * The founder to set.
415      */

416     public void setFounder(User founder) {
417         this.founder = founder;
418     }
419
420     /**
421      * @hibernate.set name="links" inverse="true"
422      * sort="com.j2biz.blogunity.util.LinkComparator"
423      * cascade="delete" lazy="true"
424      *
425      * @hibernate.collection-key column="BLOG_ID"
426      * @hibernate.collection-one-to-many class="com.j2biz.blogunity.pojo.Link"
427      *
428      *
429      * @return Returns the links.
430      */

431     public Set JavaDoc getLinks() {
432
433         return links;
434     }
435
436     /**
437      * @param links
438      * The links to set.
439      */

440     public void setLinks(Set JavaDoc links) {
441         this.links = links;
442     }
443
444     /**
445      * @hibernate.set name="calendarEntries" inverse="true" cascade="delete"
446      * lazy="true"
447      *
448      * @hibernate.collection-key column="BLOG_ID"
449      * @hibernate.collection-one-to-many class="com.j2biz.blogunity.pojo.CalendarEntry"
450      *
451      *
452      * @return Returns the calendarEntries.
453      */

454     public Set JavaDoc getCalendarEntries() {
455         return calendarEntries;
456     }
457
458     /**
459      * @param calendarEntries
460      * The calendarEntries to set.
461      */

462     public void setCalendarEntries(Set JavaDoc calendarEntries) {
463         this.calendarEntries = calendarEntries;
464     }
465
466     public void addLink(Link link) {
467         links.add(link);
468     }
469
470     /**
471      * @hibernate.property name="type" column="TYPE" type="integer"
472      * not-null="true" unique="false"
473      *
474      * @return Returns the type.
475      */

476     public int getType() {
477         return type;
478     }
479
480     /**
481      * @param type
482      * The type to set.
483      */

484     public void setType(int type) {
485         this.type = type;
486     }
487
488     /**
489      * @hibernate.property name="communityType" column="COMMUNITY_TYPE"
490      * type="integer" not-null="false" unique="false"
491      *
492      * @return Returns the communityType.
493      */

494     public int getCommunityType() {
495         return communityType;
496     }
497
498     /**
499      * @param communityType
500      * The communityType to set.
501      */

502     public void setCommunityType(int communityType) {
503         this.communityType = communityType;
504     }
505
506     public boolean containsCategory(Category c) {
507
508         Iterator JavaDoc it = getCategories().iterator();
509         while (it.hasNext()) {
510             Category bc = (Category) it.next();
511             if (bc.getId().longValue() == c.getId().longValue()) return true;
512
513         }
514
515         return false;
516     }
517
518     public boolean containsLink(Link link) {
519
520         Iterator JavaDoc it = getLinks().iterator();
521         while (it.hasNext()) {
522             Link bc = (Link) it.next();
523             if (bc.getId().longValue() == link.getId().longValue()) return true;
524
525         }
526
527         return false;
528     }
529
530     /**
531      * @return
532      */

533     public int getMaximalLinkOrder() {
534         int order = 0;
535
536         for (Iterator JavaDoc it = links.iterator(); it.hasNext();) {
537             Link l = (Link) it.next();
538             if (l.getOrder() > order) order = l.getOrder();
539         }
540
541         return order;
542     }
543
544     /**
545      *
546      * @hibernate.set name="todayReferers" inverse="true"
547      * sort="com.j2biz.blogunity.util.RefererComparator"
548      * cascade="delete" lazy="true"
549      * @hibernate.collection-key column="BLOG_ID"
550      * @hibernate.collection-one-to-many class="com.j2biz.blogunity.pojo.Referer"
551      *
552      * @return
553      */

554     public Set JavaDoc getTodayReferers() {
555         return todayReferers;
556     }
557
558     /**
559      * @param todayReferers
560      */

561     public void setTodayReferers(Set JavaDoc todayReferers) {
562         this.todayReferers = todayReferers;
563     }
564
565     /**
566      * @param referer
567      */

568     public void addTodayReferer(Referer referer) {
569         todayReferers.add(referer);
570     }
571
572     /**
573      * @hibernate.set name="todayVisitedPages" inverse="true"
574      * sort="com.j2biz.blogunity.util.VisitedPageComparator"
575      * cascade="delete" lazy="true"
576      * @hibernate.collection-key column="BLOG_ID"
577      * @hibernate.collection-one-to-many class="com.j2biz.blogunity.pojo.VisitedPage"
578      *
579      * @return
580      */

581     public Set JavaDoc getTodayVisitedPages() {
582         return todayVisitedPages;
583     }
584
585     /**
586      * @param todayVisitedPages
587      */

588     public void setTodayVisitedPages(Set JavaDoc todayVisitedPages) {
589         this.todayVisitedPages = todayVisitedPages;
590     }
591
592     /**
593      * @param page
594      */

595     public void addTodayVisitedPage(VisitedPage page) {
596         todayVisitedPages.add(page);
597     }
598
599     public File JavaDoc getMainDataDirectory() {
600
601         if (mainDataDirectory == null)
602                 mainDataDirectory = new File JavaDoc(BlogunityManager.getSystemConfiguration()
603                         .getBlogsDirectory(), getUrlName());
604         return mainDataDirectory;
605
606     }
607
608     public File JavaDoc getThemeDirectory() {
609         if (themeDirectory == null) themeDirectory = new File JavaDoc(getMainDataDirectory(), "theme");
610         return themeDirectory;
611     }
612
613     public File JavaDoc getLogsDirectory() {
614         if (logsDirectory == null) logsDirectory = new File JavaDoc(getMainDataDirectory(), "logs");
615         return logsDirectory;
616     }
617
618     public File JavaDoc getIndexesDirectory() {
619         if (indexesDirectory == null) indexesDirectory = new File JavaDoc(getMainDataDirectory(), "indexes");
620         return indexesDirectory;
621     }
622
623     public File JavaDoc getImagesDirectory() {
624         if (imagesDirectory == null) imagesDirectory = new File JavaDoc(getMainDataDirectory(), "images");
625         return imagesDirectory;
626     }
627
628     public File JavaDoc getFilesDirectory() {
629         if (filesDirectory == null) filesDirectory = new File JavaDoc(getMainDataDirectory(), "files");
630         return filesDirectory;
631     }
632
633     /*
634      * (non-Javadoc)
635      *
636      * @see net.sf.hibernate.Validatable#validate()
637      */

638     public void validate() throws ValidationFailure {
639
640         if (!BlogUtils.getInstance().isValidBlogname(urlName))
641                 throw new ValidationFailure("Blog urlName is not valid!");
642
643         if (type == INDIVIDUAL_BLOG) {
644             if (contributors != null && contributors.size() > 0) { throw new ValidationFailure(
645                     "Individual blog can not contains contributors other than founder!"); }
646         }
647     }
648
649 }
Popular Tags