KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mvnforum > phpbb2mvnforum > db > ForumBean


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/phpbb2mvnforum/db/ForumBean.java,v 1.2 2006/04/15 03:57:15 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.2 $
5  * $Date: 2006/04/15 03:57:15 $
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 org.mvnforum.phpbb2mvnforum.db;
42
43 import java.sql.Timestamp JavaDoc;
44 import java.util.Collection JavaDoc;
45 import java.util.Iterator JavaDoc;
46
47 import org.w3c.dom.Document JavaDoc;
48 import org.w3c.dom.Element JavaDoc;
49 import org.w3c.dom.Node JavaDoc;
50
51 import net.myvietnam.mvncore.util.StringUtil;
52 import net.myvietnam.mvncore.exception.BadInputException;
53 import com.mvnforum.MVNForumConfig;
54
55 /*
56  * Included columns: ForumID, CategoryID, LastPostMemberName, ForumName, ForumDesc,
57  * ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType,
58  * ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword,
59  * ForumThreadCount, ForumPostCount
60  * Excluded columns:
61  */

62 public class ForumBean {
63     /*************************************************************************
64      * NOTE: below constants MUST NOT be changed IN ALL CASES,
65      * or it will break the compatibility
66      *************************************************************************/

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

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

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