KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: Entry.java,v 1.10 2005/01/07 01:46:03 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.Serializable JavaDoc;
29 import java.text.SimpleDateFormat JavaDoc;
30 import java.util.Date JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.TreeSet JavaDoc;
34
35 import org.apache.commons.lang.StringUtils;
36
37 import net.sf.hibernate.Validatable;
38 import net.sf.hibernate.ValidationFailure;
39
40 import com.j2biz.blogunity.util.CategoryComparator;
41 import com.j2biz.blogunity.util.CommentComparator;
42
43 /**
44  * @hibernate.class table="ENTRIES" dynamic-insert = "true" dynamic-update =
45  * "true"
46  *
47  * @author michelson
48  * @version $$
49  * @since 0.1
50  *
51  *
52  */

53 public class Entry implements Validatable, Serializable JavaDoc {
54
55     /**
56      * Comment for <code>serialVersionUID</code>
57      */

58     private static final long serialVersionUID = 3618698608472373556L;
59
60     /** Public entry is accessable for public read. */
61     public static final int PUBLIC = 0;
62
63     /** Private entry is accessable for private read. */
64     public static final int PRIVATE = 1;
65
66     /** Draft entry is just a temporary saved entry. */
67     public static final int DRAFT = 2;
68
69     public static final SimpleDateFormat JavaDoc PERMALINK_FORMAT = new SimpleDateFormat JavaDoc("/yyyy/MM/dd/");
70
71     private Long JavaDoc id;
72
73     private String JavaDoc aliasname;
74
75     private String JavaDoc title;
76
77     private String JavaDoc rawTitle;
78
79     private String JavaDoc excerpt;
80
81     private String JavaDoc rawExcerpt;
82
83     private String JavaDoc body;
84
85     private String JavaDoc rawBody;
86
87     private Date JavaDoc createTime;
88
89     private User author;
90
91     private String JavaDoc authorIP = "127.0.0.1";
92
93     private Set JavaDoc /* <Category> */categories = new TreeSet JavaDoc(new CategoryComparator());
94
95     private Set JavaDoc /* <Comment> */comments = new TreeSet JavaDoc(new CommentComparator());
96
97     private Set JavaDoc /* <Trackback> */trackbacks = new TreeSet JavaDoc(); //TODO: implement
98

99     // comparator for
100
// trackbacks
101

102     private Blog blog;
103
104     private Userpic userpic;
105
106     private boolean trackbackAllowed = true;
107
108     private boolean commentingAllowed = true;
109
110     private boolean anonymousCommentingAllowed = true;
111
112     /** On of the three possible types: PUBLIC, PRIVATE, DRAFT */
113     private int type = PUBLIC;
114
115     /**
116      *
117      */

118     public Entry() {
119         super();
120     }
121
122     /**
123      * @hibernate.many-to-one column="BLOG_ID"
124      * class="com.j2biz.blogunity.pojo.Blog"
125      *
126      *
127      * @return Returns the blog.
128      */

129     public Blog getBlog() {
130         return blog;
131     }
132
133     /**
134      * @param blog
135      * The blog to set.
136      */

137     public void setBlog(Blog blog) {
138         this.blog = blog;
139     }
140
141     /**
142      * @hibernate.property name="aliasname" column="ALIASNAME" type="string"
143      * not-null="false" unique="false"
144      *
145      * @return
146      */

147     public String JavaDoc getAliasname() {
148         return aliasname;
149     }
150
151     /**
152      * @param aliasname
153      */

154     public void setAliasname(String JavaDoc aliasname) {
155         this.aliasname = aliasname;
156     }
157
158     /**
159      * @hibernate.property name="trackbackAllowed" column="TRACKBACK_ALLOWED"
160      * type="boolean" not-null="true" unique="false"
161      *
162      * @return Returns the trackbackAllowed
163      */

164     public boolean getTrackbackAllowed() {
165         return trackbackAllowed;
166     }
167
168     /**
169      * @return Returns the trackbackAllowed.
170      */

171     public void setTrackbackAllowed(boolean tbAllowed) {
172         this.trackbackAllowed = tbAllowed;
173     }
174
175     /**
176      * @return Returns the trackbackAllowed.
177      */

178     public boolean isTrackbackAllowed() {
179         return getTrackbackAllowed();
180     }
181
182     /**
183      * @hibernate.property name="anonymousCommentingAllowed"
184      * column="ANONYMOUS_COMMENTING_ALLOWED" type="boolean"
185      * not-null="true" unique="false"
186      *
187      * @return Returns the anonymousCommentingAllowed.
188      */

189     public boolean getAnonymousCommentingAllowed() {
190         return anonymousCommentingAllowed;
191     }
192
193     /**
194      * @return Returns the anonymousCommentingAllowed.
195      */

196     public boolean isAnonymousCommentingAllowed() {
197         return anonymousCommentingAllowed;
198     }
199
200     /**
201      * @param anonymousCommentingAllowed
202      * The anonymousCommentingAllowed to set.
203      */

204     public void setAnonymousCommentingAllowed(boolean anonymousCommentingAllowed) {
205         this.anonymousCommentingAllowed = anonymousCommentingAllowed;
206     }
207
208     /**
209      * @hibernate.many-to-one column="AUTHOR_ID"
210      * class="com.j2biz.blogunity.pojo.User"
211      *
212      *
213      * @return Returns the author.
214      */

215     public User getAuthor() {
216         return author;
217     }
218
219     /**
220      * @param author
221      * The author to set.
222      */

223     public void setAuthor(User author) {
224         this.author = author;
225     }
226
227     /**
228      * @hibernate.property name="body" column="BODY" type="text"
229      * not-null="false" unique="false"
230      *
231      * @return Returns the body.
232      */

233     public String JavaDoc getBody() {
234         return body;
235     }
236
237     /**
238      * @param body
239      * The body to set.
240      */

241     public void setBody(String JavaDoc body) {
242         this.body = body;
243     }
244
245     /**
246      * @hibernate.property name="rawBody" column="RAW_BODY" type="text"
247      * not-null="false" unique="false"
248      *
249      *
250      *
251      * @return Returns the rawBody.
252      */

253     public String JavaDoc getRawBody() {
254         return rawBody;
255     }
256
257     /**
258      * @param rawBody
259      * The rawBody to set.
260      */

261     public void setRawBody(String JavaDoc rawBody) {
262         this.rawBody = rawBody;
263     }
264
265     /**
266      * @hibernate.set name="categories" table="ENTRY_CATEGORIES"
267      * sort="com.j2biz.blogunity.util.CategoryComparator"
268      * cascade="none" inverse="false" lazy="true"
269      * @hibernate.collection-key column="ENTRY_ID"
270      * @hibernate.collection-many-to-many class="com.j2biz.blogunity.pojo.Category"
271      * column="CATEGORY_ID"
272      *
273      * @return Returns the categories.
274      */

275     public Set JavaDoc getCategories() {
276         return categories;
277     }
278
279     public void addCategory(Category category) {
280         categories.add(category);
281     }
282
283     public boolean containsCategory(Category category) {
284
285         Iterator JavaDoc it = getCategories().iterator();
286         while (it.hasNext()) {
287             Category c = (Category) it.next();
288             if (c.getId().longValue() == category.getId().longValue()) return true;
289         }
290
291         return false;
292     }
293
294     /**
295      * Returns global categories associated with given blog-entry.
296      *
297      * @return global categories associated with given blog-entry.
298      */

299     public Set JavaDoc getGlobalCategories() {
300
301         Set JavaDoc global = new TreeSet JavaDoc(new CategoryComparator());
302         Iterator JavaDoc it = categories.iterator();
303
304         while (it.hasNext()) {
305             Category c = (Category) it.next();
306             if (c.getType() == Category.GLOBAL) global.add(c);
307         }
308
309         return global;
310
311     }
312
313     /**
314      * Returns local categories associated with given blog-entry.
315      *
316      * @return local categories associated with given blog-entry.
317      */

318     public Set JavaDoc getLocalCategories() {
319         Set JavaDoc local = new TreeSet JavaDoc(new CategoryComparator());
320         Iterator JavaDoc it = categories.iterator();
321
322         while (it.hasNext()) {
323             Category c = (Category) it.next();
324             if (c.getType() == Category.LOCAL) local.add(c);
325         }
326
327         return local;
328     }
329
330     /**
331      * @param categories
332      * The categories to set.
333      */

334     public void setCategories(Set JavaDoc categories) {
335         this.categories = categories;
336     }
337
338     /**
339      * @hibernate.property name="commentingAllowed" column="COMMENTING_ALLOWED"
340      * type="boolean" not-null="true" unique="false"
341      *
342      * @return Returns the commentingAllowed.
343      */

344     public boolean getCommentingAllowed() {
345         return commentingAllowed;
346     }
347
348     /**
349      * @return Returns the commentingAllowed.
350      */

351     public boolean isCommentingAllowed() {
352         return commentingAllowed;
353     }
354
355     /**
356      * @param commentingAllowed
357      * The commentingAllowed to set.
358      */

359     public void setCommentingAllowed(boolean commentingAllowed) {
360         this.commentingAllowed = commentingAllowed;
361     }
362
363     /**
364      * @hibernate.set name="comments" inverse="true"
365      * sort="com.j2biz.blogunity.util.CommentComparator"
366      * cascade="delete" lazy="true"
367      *
368      * @hibernate.collection-key column="ENTRY_ID"
369      * @hibernate.collection-one-to-many class="com.j2biz.blogunity.pojo.Comment"
370      *
371      * @return Returns the comments.
372      */

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

381     public void setComments(Set JavaDoc comments) {
382         this.comments = comments;
383     }
384
385     public Set JavaDoc getFirstLevelComments() {
386
387         Set JavaDoc directAnswers = new TreeSet JavaDoc(new CommentComparator());
388
389         for (Iterator JavaDoc it = comments.iterator(); it.hasNext();) {
390             Comment c = (Comment) it.next();
391             if (c.getRepliedComment() == null) directAnswers.add(c);
392         }
393
394         return directAnswers;
395
396     }
397
398     /**
399      * @hibernate.property name="createTime" column="CREATE_TIME"
400      * type="timestamp" not-null="true" unique="false"
401      *
402      * @return Returns the createTime.
403      */

404     public Date JavaDoc getCreateTime() {
405         return createTime;
406     }
407
408     /**
409      * @param createTime
410      * The createTime to set.
411      */

412     public void setCreateTime(Date JavaDoc createTime) {
413         this.createTime = createTime;
414     }
415
416     /**
417      * @hibernate.property name="excerpt" column="EXCERPT" type="text"
418      * not-null="false" unique="false"
419      *
420      * @return Returns the excerpt.
421      */

422     public String JavaDoc getExcerpt() {
423         return excerpt;
424     }
425
426     /**
427      * @param excerpt
428      * The excerpt to set.
429      */

430     public void setExcerpt(String JavaDoc exrept) {
431         this.excerpt = exrept;
432     }
433
434     /**
435      * @hibernate.property name="rawExcerpt" column="RAW_EXCERPT" type="text"
436      * not-null="false" unique="false"
437      *
438      * @return Returns the rawExcerpt.
439      */

440     public String JavaDoc getRawExcerpt() {
441         return rawExcerpt;
442     }
443
444     /**
445      * @param rawExcerpt
446      * The rawExcerpt to set.
447      */

448     public void setRawExcerpt(String JavaDoc rawExcerpt) {
449         this.rawExcerpt = rawExcerpt;
450     }
451
452     /**
453      * @hibernate.id generator-class="increment" type="long" column="ID"
454      * unsaved-value="null"
455      *
456      * @return Returns the id.
457      */

458     public Long JavaDoc getId() {
459         return id;
460     }
461
462     /**
463      * @param id
464      * The id to set.
465      */

466     public void setId(Long JavaDoc id) {
467         this.id = id;
468     }
469
470     /**
471      * @hibernate.property name="title" column="TITLE" type="string"
472      * not-null="true" unique="false"
473      *
474      * @return Returns the title.
475      */

476     public String JavaDoc getTitle() {
477         return title;
478     }
479
480     /**
481      * @param title
482      * The title to set.
483      */

484     public void setTitle(String JavaDoc title) {
485         this.title = title;
486     }
487
488     /**
489      * @hibernate.property name="rawTitle" column="RAW_TITLE" type="string"
490      * not-null="true" unique="false"
491      *
492      *
493      * @return Returns the rawTitle.
494      */

495     public String JavaDoc getRawTitle() {
496         return rawTitle;
497     }
498
499     /**
500      * @param rawTitle
501      * The rawTitle to set.
502      */

503     public void setRawTitle(String JavaDoc rawTitle) {
504         this.rawTitle = rawTitle;
505     }
506
507     /**
508      * @hibernate.property name="type" column="TYPE" type="integer"
509      * not-null="true" unique="false"
510      *
511      * @return Returns the type.
512      */

513     public int getType() {
514         return type;
515     }
516
517     /**
518      * @param type
519      * The type to set.
520      */

521     public void setType(int type) {
522         this.type = type;
523     }
524
525     /**
526      * @hibernate.property name="authorIP" column="AUTHOR_IP" type="string"
527      * not-null="true" unique="false"
528      *
529      * @return Returns the authorIP.
530      */

531     public String JavaDoc getAuthorIP() {
532         return authorIP;
533     }
534
535     /**
536      * @param authorIP
537      * The authorIP to set.
538      */

539     public void setAuthorIP(String JavaDoc authorIP) {
540         this.authorIP = authorIP;
541     }
542
543     /**
544      * @hibernate.many-to-one column="USERPIC_ID"
545      * class="com.j2biz.blogunity.pojo.Userpic"
546      *
547      * @return Returns the userpic.
548      */

549     public Userpic getUserpic() {
550         return userpic;
551     }
552
553     /**
554      * @param userpic
555      * The userpic to set.
556      */

557     public void setUserpic(Userpic userpic) {
558         this.userpic = userpic;
559     }
560
561     /**
562      * @hibernate.set name="trackbacks" cascade="delete" lazy="true" sort="com.j2biz.blogunity.util.TrackBackComparator"
563      * inverse="true"
564      *
565      *
566      * @hibernate.collection-key column="REF_ENTRY_ID"
567      * @hibernate.collection-one-to-many class="com.j2biz.blogunity.pojo.Trackback"
568      *
569      * @return Returns the trackbacks.
570      */

571     public Set JavaDoc getTrackbacks() {
572         return trackbacks;
573     }
574
575     /**
576      * @param trackbacks
577      * The trackbacks to set.
578      */

579     public void setTrackbacks(Set JavaDoc trackbacks) {
580         this.trackbacks = trackbacks;
581     }
582
583     /*
584      * (non-Javadoc)
585      *
586      * @see net.sf.hibernate.Validatable#validate()
587      */

588     public void validate() throws ValidationFailure {
589         //TODO i don't know, if i should check this or not?
590

591         // if (categories != null && categories.size() == 0)
592
// throw new ValidationFailure(
593
// "Blog-entry should contain at least one category!");
594
}
595
596     /**
597      * Returns permalink-string to the current entry.
598      * Format of this permalink is: /yyyy/MM/dd/id
599      * or, if the aliasname exists: /yyyy/MM/dd/aliasname
600      *
601      * @return permalink for the given entry.
602      */

603     public String JavaDoc getPermalink() {
604
605         String JavaDoc permalink = PERMALINK_FORMAT.format(createTime);
606         if (StringUtils.isNotEmpty(aliasname)) { return permalink + aliasname; }
607
608         return permalink + id;
609
610     }
611
612 }
Popular Tags