KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > db > ForumBean


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/db/ForumBean.java,v 1.16 2006/04/14 17:05:26 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.16 $
5  * $Date: 2006/04/14 17:05:26 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Minh Nguyen
39  * @author: Mai Nguyen
40  */

41 package com.mvnforum.db;
42
43 import java.sql.Timestamp JavaDoc;
44 import java.util.Collection JavaDoc;
45 import java.util.Iterator JavaDoc;
46
47 import net.myvietnam.mvncore.util.StringUtil;
48 import net.myvietnam.mvncore.exception.BadInputException;
49 import com.mvnforum.MVNForumConfig;
50
51 /*
52  * Included columns: ForumID, CategoryID, LastPostMemberName, ForumName, ForumDesc,
53  * ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType,
54  * ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword,
55  * ForumThreadCount, ForumPostCount
56  * Excluded columns:
57  */

58 public class ForumBean {
59     /*************************************************************************
60      * NOTE: below constants MUST NOT be changed IN ALL CASES,
61      * or it will break the compatibility
62      *************************************************************************/

63
64     /** The default value mean forum is enable and normal */
65     public final static int FORUM_STATUS_DEFAULT = 0;
66
67     /** The disabled value mean forum is disabled */
68     public final static int FORUM_STATUS_DISABLED = 1;
69
70     /**
71      * No changes (edit, attach, reply) could be maded, moderator
72      * have to change this status before making any changes is possible
73      */

74     public final static int FORUM_STATUS_LOCKED = 2;
75
76     /** Noone can reply, but moderator can change it */
77     public final static int FORUM_STATUS_CLOSED = 3;
78
79
80     /** */
81     public final static int FORUM_TYPE_DEFAULT = 0;
82
83     /** */
84     public final static int FORUM_TYPE_PRIVATE = 1;
85
86
87     /** */
88     public final static int FORUM_MODERATION_MODE_SYSTEM_DEFAULT = 0;
89
90     /** */
91     public final static int FORUM_MODERATION_MODE_NO_MODERATION = 1;
92
93     /** */
94     public final static int FORUM_MODERATION_MODE_THREAD_AND_POST = 2;
95
96     /** */
97     public final static int FORUM_MODERATION_MODE_THREAD_ONLY = 3;
98
99     /** */
100     public final static int FORUM_MODERATION_MODE_POST_ONLY = 4;
101
102     public final static String JavaDoc TYPE_NAMES[] = {"Default", "Private"};
103
104     public final static String JavaDoc MODE_NAMES[] = {"System Default", "No Moderation", "Thread and Post Moderation", "Thread Only Moderation", "Post Only Moderation"};
105
106     private int forumID;
107     private int categoryID;
108     private String JavaDoc lastPostMemberName;
109     private String JavaDoc forumName;
110     private String JavaDoc forumDesc;
111     private Timestamp JavaDoc forumCreationDate;
112     private Timestamp JavaDoc forumModifiedDate;
113     private Timestamp JavaDoc forumLastPostDate;
114     private int forumOrder;
115     private int forumType;
116     private int forumFormatOption;
117     private int forumOption;
118     private int forumStatus;
119     private int forumModerationMode;
120     private String JavaDoc forumPassword;
121     private int forumThreadCount;
122     private int forumPostCount;
123
124     public int getForumID() {
125         return forumID;
126     }
127     public void setForumID(int forumID) {
128         this.forumID = forumID;
129     }
130
131     public int getCategoryID() {
132         return categoryID;
133     }
134     public void setCategoryID(int categoryID) {
135         this.categoryID = categoryID;
136     }
137
138     public String JavaDoc getLastPostMemberName() {
139         return lastPostMemberName;
140     }
141     public void setLastPostMemberName(String JavaDoc lastPostMemberName) {
142         this.lastPostMemberName = StringUtil.getEmptyStringIfNull(lastPostMemberName);
143     }
144
145     public String JavaDoc getForumName() {
146         return forumName;
147     }
148     public void setForumName(String JavaDoc forumName) {
149         this.forumName = forumName;
150     }
151
152     public String JavaDoc getForumDesc() {
153         return forumDesc;
154     }
155     public void setForumDesc(String JavaDoc forumDesc) {
156         this.forumDesc = StringUtil.getEmptyStringIfNull(forumDesc);
157     }
158
159     public Timestamp JavaDoc getForumCreationDate() {
160         return forumCreationDate;
161     }
162     public void setForumCreationDate(Timestamp JavaDoc forumCreationDate) {
163         this.forumCreationDate = forumCreationDate;
164     }
165
166     public Timestamp JavaDoc getForumModifiedDate() {
167         return forumModifiedDate;
168     }
169     public void setForumModifiedDate(Timestamp JavaDoc forumModifiedDate) {
170         this.forumModifiedDate = forumModifiedDate;
171     }
172
173     public Timestamp JavaDoc getForumLastPostDate() {
174         return forumLastPostDate;
175     }
176     public void setForumLastPostDate(Timestamp JavaDoc forumLastPostDate) {
177         this.forumLastPostDate = forumLastPostDate;
178     }
179
180     public int getForumOrder() {
181         return forumOrder;
182     }
183     public void setForumOrder(int forumOrder) {
184         this.forumOrder = forumOrder;
185     }
186
187     public int getForumType() {
188         return forumType;
189     }
190     public void setForumType(int forumType) {
191         this.forumType = forumType;
192     }
193
194     public int getForumFormatOption() {
195         return forumFormatOption;
196     }
197     public void setForumFormatOption(int forumFormatOption) {
198         this.forumFormatOption = forumFormatOption;
199     }
200
201     public int getForumOption() {
202         return forumOption;
203     }
204     public void setForumOption(int forumOption) {
205         this.forumOption = forumOption;
206     }
207
208     public int getForumStatus() {
209         return forumStatus;
210     }
211     public void setForumStatus(int forumStatus) {
212         this.forumStatus = forumStatus;
213     }
214
215     public int getForumModerationMode() {
216         return forumModerationMode;
217     }
218     public void setForumModerationMode(int forumModerationMode) {
219         this.forumModerationMode = forumModerationMode;
220     }
221
222     public String JavaDoc getForumPassword() {
223         return forumPassword;
224     }
225     public void setForumPassword(String JavaDoc forumPassword) {
226         this.forumPassword = StringUtil.getEmptyStringIfNull(forumPassword);
227     }
228
229     public int getForumThreadCount() {
230         return forumThreadCount;
231     }
232     public void setForumThreadCount(int forumThreadCount) {
233         this.forumThreadCount = forumThreadCount;
234     }
235
236     public int getForumPostCount() {
237         return forumPostCount;
238     }
239     public void setForumPostCount(int forumPostCount) {
240         this.forumPostCount = forumPostCount;
241     }
242
243     public String JavaDoc getXMLTag() {
244         StringBuffer JavaDoc xml = new StringBuffer JavaDoc(1024);
245         xml.append("<Forum");
246         xml.append(" forumID=\"").append(String.valueOf(forumID)).append("\"");
247         xml.append(" categoryID=\"").append(String.valueOf(categoryID)).append("\"");
248         xml.append(" lastPostMemberName=\"").append(String.valueOf(lastPostMemberName)).append("\"");
249         xml.append(" forumName=\"").append(String.valueOf(forumName)).append("\"");
250         xml.append(" forumDesc=\"").append(String.valueOf(forumDesc)).append("\"");
251         xml.append(" forumCreationDate=\"").append(String.valueOf(forumCreationDate)).append("\"");
252         xml.append(" forumModifiedDate=\"").append(String.valueOf(forumModifiedDate)).append("\"");
253         xml.append(" forumLastPostDate=\"").append(String.valueOf(forumLastPostDate)).append("\"");
254         xml.append(" forumOrder=\"").append(String.valueOf(forumOrder)).append("\"");
255         xml.append(" forumType=\"").append(String.valueOf(forumType)).append("\"");
256         xml.append(" forumFormatOption=\"").append(String.valueOf(forumFormatOption)).append("\"");
257         xml.append(" forumOption=\"").append(String.valueOf(forumOption)).append("\"");
258         xml.append(" forumStatus=\"").append(String.valueOf(forumStatus)).append("\"");
259         xml.append(" forumModerationMode=\"").append(String.valueOf(forumModerationMode)).append("\"");
260         xml.append(" forumPassword=\"").append(String.valueOf(forumPassword)).append("\"");
261         xml.append(" forumThreadCount=\"").append(String.valueOf(forumThreadCount)).append("\"");
262         xml.append(" forumPostCount=\"").append(String.valueOf(forumPostCount)).append("\"");
263         xml.append(">");
264         return xml.toString();
265     }
266
267     public String JavaDoc getXML() {
268         StringBuffer JavaDoc xml = new StringBuffer JavaDoc(1024);
269         xml.append("<ForumSection>\n");
270         xml.append(" <Rows>\n");
271         xml.append(" <Row>\n");
272         xml.append(" <Column>\n");
273         xml.append(" <Name>ForumID</Name>\n");
274         xml.append(" <Value>").append(String.valueOf(forumID)).append("</Value>\n");
275         xml.append(" </Column>\n");
276         xml.append(" <Column>\n");
277         xml.append(" <Name>CategoryID</Name>\n");
278         xml.append(" <Value>").append(String.valueOf(categoryID)).append("</Value>\n");
279         xml.append(" </Column>\n");
280         xml.append(" <Column>\n");
281         xml.append(" <Name>LastPostMemberName</Name>\n");
282         xml.append(" <Value>").append(String.valueOf(lastPostMemberName)).append("</Value>\n");
283         xml.append(" </Column>\n");
284         xml.append(" <Column>\n");
285         xml.append(" <Name>ForumName</Name>\n");
286         xml.append(" <Value>").append(String.valueOf(forumName)).append("</Value>\n");
287         xml.append(" </Column>\n");
288         xml.append(" <Column>\n");
289         xml.append(" <Name>ForumDesc</Name>\n");
290         xml.append(" <Value>").append(String.valueOf(forumDesc)).append("</Value>\n");
291         xml.append(" </Column>\n");
292         xml.append(" <Column>\n");
293         xml.append(" <Name>ForumCreationDate</Name>\n");
294         xml.append(" <Value>").append(String.valueOf(forumCreationDate)).append("</Value>\n");
295         xml.append(" </Column>\n");
296         xml.append(" <Column>\n");
297         xml.append(" <Name>ForumModifiedDate</Name>\n");
298         xml.append(" <Value>").append(String.valueOf(forumModifiedDate)).append("</Value>\n");
299         xml.append(" </Column>\n");
300         xml.append(" <Column>\n");
301         xml.append(" <Name>ForumLastPostDate</Name>\n");
302         xml.append(" <Value>").append(String.valueOf(forumLastPostDate)).append("</Value>\n");
303         xml.append(" </Column>\n");
304         xml.append(" <Column>\n");
305         xml.append(" <Name>ForumOrder</Name>\n");
306         xml.append(" <Value>").append(String.valueOf(forumOrder)).append("</Value>\n");
307         xml.append(" </Column>\n");
308         xml.append(" <Column>\n");
309         xml.append(" <Name>ForumType</Name>\n");
310         xml.append(" <Value>").append(String.valueOf(forumType)).append("</Value>\n");
311         xml.append(" </Column>\n");
312         xml.append(" <Column>\n");
313         xml.append(" <Name>ForumFormatOption</Name>\n");
314         xml.append(" <Value>").append(String.valueOf(forumFormatOption)).append("</Value>\n");
315         xml.append(" </Column>\n");
316         xml.append(" <Column>\n");
317         xml.append(" <Name>ForumOption</Name>\n");
318         xml.append(" <Value>").append(String.valueOf(forumOption)).append("</Value>\n");
319         xml.append(" </Column>\n");
320         xml.append(" <Column>\n");
321         xml.append(" <Name>ForumStatus</Name>\n");
322         xml.append(" <Value>").append(String.valueOf(forumStatus)).append("</Value>\n");
323         xml.append(" </Column>\n");
324         xml.append(" <Column>\n");
325         xml.append(" <Name>ForumModerationMode</Name>\n");
326         xml.append(" <Value>").append(String.valueOf(forumModerationMode)).append("</Value>\n");
327         xml.append(" </Column>\n");
328         xml.append(" <Column>\n");
329         xml.append(" <Name>ForumPassword</Name>\n");
330         xml.append(" <Value>").append(String.valueOf(forumPassword)).append("</Value>\n");
331         xml.append(" </Column>\n");
332         xml.append(" <Column>\n");
333         xml.append(" <Name>ForumThreadCount</Name>\n");
334         xml.append(" <Value>").append(String.valueOf(forumThreadCount)).append("</Value>\n");
335         xml.append(" </Column>\n");
336         xml.append(" <Column>\n");
337         xml.append(" <Name>ForumPostCount</Name>\n");
338         xml.append(" <Value>").append(String.valueOf(forumPostCount)).append("</Value>\n");
339         xml.append(" </Column>\n");
340         xml.append(" </Row>\n");
341         xml.append(" </Rows>\n");
342         xml.append("</ForumSection>\n");
343         return xml.toString();
344     }
345
346     public static String JavaDoc getXML(Collection JavaDoc objForumBeans) {
347         StringBuffer JavaDoc xml = new StringBuffer JavaDoc(1024);
348         Iterator JavaDoc iterator = objForumBeans.iterator();
349         xml.append("<ForumSection>\n");
350         xml.append(" <Rows>\n");
351         while (iterator.hasNext()) {
352             ForumBean objForumBean = (ForumBean)iterator.next();
353             xml.append(" <Row>\n");
354             xml.append(" <Column>\n");
355             xml.append(" <Name>ForumID</Name>\n");
356             xml.append(" <Value>").append(String.valueOf(objForumBean.forumID)).append("</Value>\n");
357             xml.append(" </Column>\n");
358             xml.append(" <Column>\n");
359             xml.append(" <Name>CategoryID</Name>\n");
360             xml.append(" <Value>").append(String.valueOf(objForumBean.categoryID)).append("</Value>\n");
361             xml.append(" </Column>\n");
362             xml.append(" <Column>\n");
363             xml.append(" <Name>LastPostMemberName</Name>\n");
364             xml.append(" <Value>").append(String.valueOf(objForumBean.lastPostMemberName)).append("</Value>\n");
365             xml.append(" </Column>\n");
366             xml.append(" <Column>\n");
367             xml.append(" <Name>ForumName</Name>\n");
368             xml.append(" <Value>").append(String.valueOf(objForumBean.forumName)).append("</Value>\n");
369             xml.append(" </Column>\n");
370             xml.append(" <Column>\n");
371             xml.append(" <Name>ForumDesc</Name>\n");
372             xml.append(" <Value>").append(String.valueOf(objForumBean.forumDesc)).append("</Value>\n");
373             xml.append(" </Column>\n");
374             xml.append(" <Column>\n");
375             xml.append(" <Name>ForumCreationDate</Name>\n");
376             xml.append(" <Value>").append(String.valueOf(objForumBean.forumCreationDate)).append("</Value>\n");
377             xml.append(" </Column>\n");
378             xml.append(" <Column>\n");
379             xml.append(" <Name>ForumModifiedDate</Name>\n");
380             xml.append(" <Value>").append(String.valueOf(objForumBean.forumModifiedDate)).append("</Value>\n");
381             xml.append(" </Column>\n");
382             xml.append(" <Column>\n");
383             xml.append(" <Name>ForumLastPostDate</Name>\n");
384             xml.append(" <Value>").append(String.valueOf(objForumBean.forumLastPostDate)).append("</Value>\n");
385             xml.append(" </Column>\n");
386             xml.append(" <Column>\n");
387             xml.append(" <Name>ForumOrder</Name>\n");
388             xml.append(" <Value>").append(String.valueOf(objForumBean.forumOrder)).append("</Value>\n");
389             xml.append(" </Column>\n");
390             xml.append(" <Column>\n");
391             xml.append(" <Name>ForumType</Name>\n");
392             xml.append(" <Value>").append(String.valueOf(objForumBean.forumType)).append("</Value>\n");
393             xml.append(" </Column>\n");
394             xml.append(" <Column>\n");
395             xml.append(" <Name>ForumFormatOption</Name>\n");
396             xml.append(" <Value>").append(String.valueOf(objForumBean.forumFormatOption)).append("</Value>\n");
397             xml.append(" </Column>\n");
398             xml.append(" <Column>\n");
399             xml.append(" <Name>ForumOption</Name>\n");
400             xml.append(" <Value>").append(String.valueOf(objForumBean.forumOption)).append("</Value>\n");
401             xml.append(" </Column>\n");
402             xml.append(" <Column>\n");
403             xml.append(" <Name>ForumStatus</Name>\n");
404             xml.append(" <Value>").append(String.valueOf(objForumBean.forumStatus)).append("</Value>\n");
405             xml.append(" </Column>\n");
406             xml.append(" <Column>\n");
407             xml.append(" <Name>ForumModerationMode</Name>\n");
408             xml.append(" <Value>").append(String.valueOf(objForumBean.forumModerationMode)).append("</Value>\n");
409             xml.append(" </Column>\n");
410             xml.append(" <Column>\n");
411             xml.append(" <Name>ForumPassword</Name>\n");
412             xml.append(" <Value>").append(String.valueOf(objForumBean.forumPassword)).append("</Value>\n");
413             xml.append(" </Column>\n");
414             xml.append(" <Column>\n");
415             xml.append(" <Name>ForumThreadCount</Name>\n");
416             xml.append(" <Value>").append(String.valueOf(objForumBean.forumThreadCount)).append("</Value>\n");
417             xml.append(" </Column>\n");
418             xml.append(" <Column>\n");
419             xml.append(" <Name>ForumPostCount</Name>\n");
420             xml.append(" <Value>").append(String.valueOf(objForumBean.forumPostCount)).append("</Value>\n");
421             xml.append(" </Column>\n");
422             xml.append(" </Row>\n");
423         }//while
424
xml.append(" </Rows>\n");
425         xml.append("</ForumSection>\n");
426         return xml.toString();
427     }
428
429     /************************************************
430      * Customized methods come below
431      ************************************************/

432     private int pendingThreadCount = 0;
433     private int threadsWithPendingPostsCount = 0;
434     private int pendingPostCount = 0;
435
436     public int getPendingPostCount() {
437         return pendingPostCount;
438     }
439     public void setPendingPostCount(int pendingPostCount) {
440         this.pendingPostCount = pendingPostCount;
441     }
442
443     public int getPendingThreadCount() {
444         return pendingThreadCount;
445     }
446     public void setPendingThreadCount(int pendingThreadCount) {
447         this.pendingThreadCount = pendingThreadCount;
448     }
449
450     public int getThreadsWithPendingPostsCount() {
451         return threadsWithPendingPostsCount;
452     }
453     public void setThreadsWithPendingPostsCount(int threadsWithPendingPostsCount) {
454         this.threadsWithPendingPostsCount = threadsWithPendingPostsCount;
455     }
456
457     static public void validateForumType(int type) throws IllegalArgumentException JavaDoc {
458         if ((type < 0) || (type > FORUM_TYPE_PRIVATE)) {
459             throw new IllegalArgumentException JavaDoc("Invalid ForumType = " + type);
460         }
461     }
462
463     static public void validateForumModerationMode(int moderationMod) throws IllegalArgumentException JavaDoc {
464         if ((moderationMod < 0) || (moderationMod > FORUM_MODERATION_MODE_POST_ONLY)) {
465             throw new IllegalArgumentException JavaDoc("Invalid ForumModerationMod = " + moderationMod);
466         }
467     }
468
469     static public void validateForumStatus(int status) throws IllegalArgumentException JavaDoc {
470         if ((status < 0) || (status > FORUM_STATUS_CLOSED)) {
471             throw new IllegalArgumentException JavaDoc("Invalid ForumStatus = " + status);
472         }
473     }
474
475     static public void validateForumOption(int option) throws IllegalArgumentException JavaDoc {
476         if ((option < 0) || (option > 0)) {
477             throw new IllegalArgumentException JavaDoc("Invalid ForumOption = " + option);
478         }
479     }
480
481     static public void validateForumFormatOption(int option) throws IllegalArgumentException JavaDoc {
482         if ((option < 0) || (option > 0)) {
483             throw new IllegalArgumentException JavaDoc("Invalid ForumFormatOption = " + option);
484         }
485     }
486
487     public void ensureNotDisabledForum() throws BadInputException {
488         if (forumStatus == ForumBean.FORUM_STATUS_DISABLED) {
489             throw new BadInputException("Cannot process this action in a disabled forum.");//@todo : localize me
490
}
491     }
492
493     public void ensureNotLockedForum() throws BadInputException {
494         if (forumStatus == ForumBean.FORUM_STATUS_LOCKED) {
495             throw new BadInputException("Cannot process this action in a locked forum.");//@todo : localize me
496
}
497     }
498
499     public void ensureNotClosedForum() throws BadInputException {
500         if (forumStatus == ForumBean.FORUM_STATUS_CLOSED) {
501             throw new BadInputException("Cannot process this action in a closed forum.");//@todo : localize me
502
}
503     }
504
505     public boolean shouldModeratePost() {
506         int mode = forumModerationMode;
507         if (mode == FORUM_MODERATION_MODE_SYSTEM_DEFAULT) {
508             mode = MVNForumConfig.getDefaultModerationOption();
509         }
510         if ((mode == FORUM_MODERATION_MODE_POST_ONLY) || (mode == FORUM_MODERATION_MODE_THREAD_AND_POST)) {
511             return true;
512         }
513         return false;
514     }
515
516     public boolean shouldModerateThread() {
517         int mode = forumModerationMode;
518         if (mode == FORUM_MODERATION_MODE_SYSTEM_DEFAULT) {
519             mode = MVNForumConfig.getDefaultModerationOption();
520         }
521         if ((mode == FORUM_MODERATION_MODE_THREAD_ONLY) || (mode == FORUM_MODERATION_MODE_THREAD_AND_POST)) {
522             return true;
523         }
524         return false;
525     }
526
527     public String JavaDoc getForumModeName() {
528         return MODE_NAMES[this.forumModerationMode];
529     }
530
531     public String JavaDoc getForumTypeName() {
532         return TYPE_NAMES[this.forumType];
533     }
534
535
536 } //end of class ForumBean
537
Popular Tags