KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/db/ThreadBean.java,v 1.17 2006/04/14 17:05:26 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.17 $
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
49 /*
50  * Included columns: ThreadID, ForumID, MemberName, LastPostMemberName, ThreadTopic,
51  * ThreadBody, ThreadVoteCount, ThreadVoteTotalStars, ThreadCreationDate, ThreadLastPostDate,
52  * ThreadType, ThreadOption, ThreadStatus, ThreadHasPoll, ThreadViewCount,
53  * ThreadReplyCount, ThreadIcon, ThreadDuration
54  * Excluded columns:
55  */

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

61     /**
62      * The default value mean thread is enable and normal
63      */

64     public final static int THREAD_STATUS_DEFAULT = 0;
65
66     /**
67      * The disable thread is invisible for normal user and visible to moderator
68      */

69     public final static int THREAD_STATUS_DISABLED = 1;
70
71     /**
72      * No changes (edit, attach, reply) could be maded, moderator
73      * have to change this status before making any changes is possible
74      */

75     public final static int THREAD_STATUS_LOCKED = 2;
76
77     /**
78      * Noone can reply, but moderator can change it.
79      */

80     public final static int THREAD_STATUS_CLOSED = 3;
81
82     /**
83      * Thread type is traditional
84      */

85     public final static int THREAD_TYPE_DEFAULT = 0;
86
87     public final static int THREAD_TYPE_STICKY = 1;
88
89     public final static int THREAD_TYPE_FORUM_ANNOUNCEMENT = 2;
90
91     public final static int THREAD_TYPE_GLOBAL_ANNOUNCEMENT = 3;
92
93     private int threadID;
94     private int forumID;
95     private String JavaDoc memberName;
96     private String JavaDoc lastPostMemberName;
97     private String JavaDoc threadTopic;
98     private String JavaDoc threadBody;
99     private int threadVoteCount;
100     private int threadVoteTotalStars;
101     private Timestamp JavaDoc threadCreationDate;
102     private Timestamp JavaDoc threadLastPostDate;
103     private int threadType;
104     private int threadOption;
105     private int threadStatus;
106     private int threadHasPoll;
107     private int threadViewCount;
108     private int threadReplyCount;
109     private String JavaDoc threadIcon;
110     private int threadDuration;
111     private int threadAttachCount;
112
113     public int getThreadID() {
114         return threadID;
115     }
116     public void setThreadID(int threadID) {
117         this.threadID = threadID;
118     }
119
120     public int getForumID() {
121         return forumID;
122     }
123     public void setForumID(int forumID) {
124         this.forumID = forumID;
125     }
126
127     public String JavaDoc getMemberName() {
128         return memberName;
129     }
130     public void setMemberName(String JavaDoc memberName) {
131         this.memberName = memberName;
132     }
133
134     public String JavaDoc getLastPostMemberName() {
135         return lastPostMemberName;
136     }
137     public void setLastPostMemberName(String JavaDoc lastPostMemberName) {
138         this.lastPostMemberName = lastPostMemberName;
139     }
140
141     public String JavaDoc getThreadTopic() {
142         return threadTopic;
143     }
144     public void setThreadTopic(String JavaDoc threadTopic) {
145         this.threadTopic = threadTopic;
146     }
147
148     public String JavaDoc getThreadBody() {
149         return threadBody;
150     }
151     public void setThreadBody(String JavaDoc threadBody) {
152         this.threadBody = threadBody;
153     }
154
155     public int getThreadVoteCount() {
156         return threadVoteCount;
157     }
158     public void setThreadVoteCount(int threadVoteCount) {
159         this.threadVoteCount = threadVoteCount;
160     }
161
162     public int getThreadVoteTotalStars() {
163         return threadVoteTotalStars;
164     }
165     public void setThreadVoteTotalStars(int threadVoteTotalStars) {
166         this.threadVoteTotalStars = threadVoteTotalStars;
167     }
168
169     public Timestamp JavaDoc getThreadCreationDate() {
170         return threadCreationDate;
171     }
172     public void setThreadCreationDate(Timestamp JavaDoc threadCreationDate) {
173         this.threadCreationDate = threadCreationDate;
174     }
175
176     public Timestamp JavaDoc getThreadLastPostDate() {
177         return threadLastPostDate;
178     }
179     public void setThreadLastPostDate(Timestamp JavaDoc threadLastPostDate) {
180         this.threadLastPostDate = threadLastPostDate;
181     }
182
183     public int getThreadType() {
184         return threadType;
185     }
186     public void setThreadType(int threadType) {
187         this.threadType = threadType;
188     }
189
190     public int getThreadOption() {
191         return threadOption;
192     }
193     public void setThreadOption(int threadOption) {
194         this.threadOption = threadOption;
195     }
196
197     public int getThreadStatus() {
198         return threadStatus;
199     }
200     public void setThreadStatus(int threadStatus) {
201         this.threadStatus = threadStatus;
202     }
203
204     public int getThreadHasPoll() {
205         return threadHasPoll;
206     }
207     public void setThreadHasPoll(int threadHasPoll) {
208         this.threadHasPoll = threadHasPoll;
209     }
210
211     public int getThreadViewCount() {
212         return threadViewCount;
213     }
214     public void setThreadViewCount(int threadViewCount) {
215         this.threadViewCount = threadViewCount;
216     }
217
218     public int getThreadReplyCount() {
219         return threadReplyCount;
220     }
221     public void setThreadReplyCount(int threadReplyCount) {
222         this.threadReplyCount = threadReplyCount;
223     }
224
225     public String JavaDoc getThreadIcon() {
226         return threadIcon;
227     }
228     public void setThreadIcon(String JavaDoc threadIcon) {
229         this.threadIcon = StringUtil.getEmptyStringIfNull(threadIcon);
230     }
231
232     public int getThreadDuration() {
233         return threadDuration;
234     }
235     public void setThreadDuration(int threadDuration) {
236         this.threadDuration = threadDuration;
237     }
238
239     public int getThreadAttachCount() {
240         return this.threadAttachCount;
241     }
242     public void setThreadAttachCount(int attachCount) {
243         this.threadAttachCount = attachCount;
244     }
245
246     public String JavaDoc getXMLTag() {
247         StringBuffer JavaDoc xml = new StringBuffer JavaDoc(1024);
248         xml.append("<Thread");
249         xml.append(" threadID=\"").append(String.valueOf(threadID)).append("\"");
250         xml.append(" forumID=\"").append(String.valueOf(forumID)).append("\"");
251         xml.append(" memberName=\"").append(String.valueOf(memberName)).append("\"");
252         xml.append(" lastPostMemberName=\"").append(String.valueOf(lastPostMemberName)).append("\"");
253         xml.append(" threadTopic=\"").append(String.valueOf(threadTopic)).append("\"");
254         xml.append(" threadBody=\"").append(String.valueOf(threadBody)).append("\"");
255         xml.append(" threadVoteCount=\"").append(String.valueOf(threadVoteCount)).append("\"");
256         xml.append(" threadVoteTotalStars=\"").append(String.valueOf(threadVoteTotalStars)).append("\"");
257         xml.append(" threadCreationDate=\"").append(String.valueOf(threadCreationDate)).append("\"");
258         xml.append(" threadLastPostDate=\"").append(String.valueOf(threadLastPostDate)).append("\"");
259         xml.append(" threadType=\"").append(String.valueOf(threadType)).append("\"");
260         xml.append(" threadOption=\"").append(String.valueOf(threadOption)).append("\"");
261         xml.append(" threadStatus=\"").append(String.valueOf(threadStatus)).append("\"");
262         xml.append(" threadHasPoll=\"").append(String.valueOf(threadHasPoll)).append("\"");
263         xml.append(" threadViewCount=\"").append(String.valueOf(threadViewCount)).append("\"");
264         xml.append(" threadReplyCount=\"").append(String.valueOf(threadReplyCount)).append("\"");
265         xml.append(" threadIcon=\"").append(String.valueOf(threadIcon)).append("\"");
266         xml.append(" threadDuration=\"").append(String.valueOf(threadDuration)).append("\"");
267         xml.append(" threadAttachCount=\"").append(String.valueOf(threadAttachCount)).append("\"");
268         xml.append(">");
269         return xml.toString();
270     }
271
272     public String JavaDoc getXML() {
273         StringBuffer JavaDoc xml = new StringBuffer JavaDoc(1024);
274         xml.append("<ThreadSection>\n");
275         xml.append(" <Rows>\n");
276         xml.append(" <Row>\n");
277         xml.append(" <Column>\n");
278         xml.append(" <Name>ThreadID</Name>\n");
279         xml.append(" <Value>").append(String.valueOf(threadID)).append("</Value>\n");
280         xml.append(" </Column>\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>MemberName</Name>\n");
287         xml.append(" <Value>").append(String.valueOf(memberName)).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>ThreadTopic</Name>\n");
295         xml.append(" <Value>").append(String.valueOf(threadTopic)).append("</Value>\n");
296         xml.append(" </Column>\n");
297         xml.append(" <Column>\n");
298         xml.append(" <Name>ThreadBody</Name>\n");
299         xml.append(" <Value>").append(String.valueOf(threadBody)).append("</Value>\n");
300         xml.append(" </Column>\n");
301         xml.append(" <Column>\n");
302         xml.append(" <Name>ThreadVoteCount</Name>\n");
303         xml.append(" <Value>").append(String.valueOf(threadVoteCount)).append("</Value>\n");
304         xml.append(" </Column>\n");
305         xml.append(" <Column>\n");
306         xml.append(" <Name>ThreadVoteTotalStars</Name>\n");
307         xml.append(" <Value>").append(String.valueOf(threadVoteTotalStars)).append("</Value>\n");
308         xml.append(" </Column>\n");
309         xml.append(" <Column>\n");
310         xml.append(" <Name>ThreadCreationDate</Name>\n");
311         xml.append(" <Value>").append(String.valueOf(threadCreationDate)).append("</Value>\n");
312         xml.append(" </Column>\n");
313         xml.append(" <Column>\n");
314         xml.append(" <Name>ThreadLastPostDate</Name>\n");
315         xml.append(" <Value>").append(String.valueOf(threadLastPostDate)).append("</Value>\n");
316         xml.append(" </Column>\n");
317         xml.append(" <Column>\n");
318         xml.append(" <Name>ThreadType</Name>\n");
319         xml.append(" <Value>").append(String.valueOf(threadType)).append("</Value>\n");
320         xml.append(" </Column>\n");
321         xml.append(" <Column>\n");
322         xml.append(" <Name>ThreadOption</Name>\n");
323         xml.append(" <Value>").append(String.valueOf(threadOption)).append("</Value>\n");
324         xml.append(" </Column>\n");
325         xml.append(" <Column>\n");
326         xml.append(" <Name>ThreadStatus</Name>\n");
327         xml.append(" <Value>").append(String.valueOf(threadStatus)).append("</Value>\n");
328         xml.append(" </Column>\n");
329         xml.append(" <Column>\n");
330         xml.append(" <Name>ThreadHasPoll</Name>\n");
331         xml.append(" <Value>").append(String.valueOf(threadHasPoll)).append("</Value>\n");
332         xml.append(" </Column>\n");
333         xml.append(" <Column>\n");
334         xml.append(" <Name>ThreadViewCount</Name>\n");
335         xml.append(" <Value>").append(String.valueOf(threadViewCount)).append("</Value>\n");
336         xml.append(" </Column>\n");
337         xml.append(" <Column>\n");
338         xml.append(" <Name>ThreadReplyCount</Name>\n");
339         xml.append(" <Value>").append(String.valueOf(threadReplyCount)).append("</Value>\n");
340         xml.append(" </Column>\n");
341         xml.append(" <Column>\n");
342         xml.append(" <Name>ThreadIcon</Name>\n");
343         xml.append(" <Value>").append(String.valueOf(threadIcon)).append("</Value>\n");
344         xml.append(" </Column>\n");
345         xml.append(" <Column>\n");
346         xml.append(" <Name>ThreadDuration</Name>\n");
347         xml.append(" <Value>").append(String.valueOf(threadDuration)).append("</Value>\n");
348         xml.append(" </Column>\n");
349         xml.append(" <Column>\n");
350         xml.append(" <Name>ThreadAttachCount</Name>\n");
351         xml.append(" <Value>").append(String.valueOf(threadAttachCount)).append("</Value>\n");
352         xml.append(" </Column>\n");
353         xml.append(" </Row>\n");
354         xml.append(" </Rows>\n");
355         xml.append("</ThreadSection>\n");
356         return xml.toString();
357     }
358
359     public static String JavaDoc getXML(Collection JavaDoc objThreadBeans) {
360         StringBuffer JavaDoc xml = new StringBuffer JavaDoc(1024);
361         Iterator JavaDoc iterator = objThreadBeans.iterator();
362         xml.append("<ThreadSection>\n");
363         xml.append(" <Rows>\n");
364         while (iterator.hasNext()) {
365             ThreadBean objThreadBean = (ThreadBean)iterator.next();
366             xml.append(" <Row>\n");
367             xml.append(" <Column>\n");
368             xml.append(" <Name>ThreadID</Name>\n");
369             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadID)).append("</Value>\n");
370             xml.append(" </Column>\n");
371             xml.append(" <Column>\n");
372             xml.append(" <Name>ForumID</Name>\n");
373             xml.append(" <Value>").append(String.valueOf(objThreadBean.forumID)).append("</Value>\n");
374             xml.append(" </Column>\n");
375             xml.append(" <Column>\n");
376             xml.append(" <Name>MemberName</Name>\n");
377             xml.append(" <Value>").append(String.valueOf(objThreadBean.memberName)).append("</Value>\n");
378             xml.append(" </Column>\n");
379             xml.append(" <Column>\n");
380             xml.append(" <Name>LastPostMemberName</Name>\n");
381             xml.append(" <Value>").append(String.valueOf(objThreadBean.lastPostMemberName)).append("</Value>\n");
382             xml.append(" </Column>\n");
383             xml.append(" <Column>\n");
384             xml.append(" <Name>ThreadTopic</Name>\n");
385             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadTopic)).append("</Value>\n");
386             xml.append(" </Column>\n");
387             xml.append(" <Column>\n");
388             xml.append(" <Name>ThreadBody</Name>\n");
389             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadBody)).append("</Value>\n");
390             xml.append(" </Column>\n");
391             xml.append(" <Column>\n");
392             xml.append(" <Name>ThreadVoteCount</Name>\n");
393             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadVoteCount)).append("</Value>\n");
394             xml.append(" </Column>\n");
395             xml.append(" <Column>\n");
396             xml.append(" <Name>ThreadVoteTotalStars</Name>\n");
397             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadVoteTotalStars)).append("</Value>\n");
398             xml.append(" </Column>\n");
399             xml.append(" <Column>\n");
400             xml.append(" <Name>ThreadCreationDate</Name>\n");
401             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadCreationDate)).append("</Value>\n");
402             xml.append(" </Column>\n");
403             xml.append(" <Column>\n");
404             xml.append(" <Name>ThreadLastPostDate</Name>\n");
405             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadLastPostDate)).append("</Value>\n");
406             xml.append(" </Column>\n");
407             xml.append(" <Column>\n");
408             xml.append(" <Name>ThreadType</Name>\n");
409             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadType)).append("</Value>\n");
410             xml.append(" </Column>\n");
411             xml.append(" <Column>\n");
412             xml.append(" <Name>ThreadOption</Name>\n");
413             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadOption)).append("</Value>\n");
414             xml.append(" </Column>\n");
415             xml.append(" <Column>\n");
416             xml.append(" <Name>ThreadStatus</Name>\n");
417             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadStatus)).append("</Value>\n");
418             xml.append(" </Column>\n");
419             xml.append(" <Column>\n");
420             xml.append(" <Name>ThreadHasPoll</Name>\n");
421             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadHasPoll)).append("</Value>\n");
422             xml.append(" </Column>\n");
423             xml.append(" <Column>\n");
424             xml.append(" <Name>ThreadViewCount</Name>\n");
425             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadViewCount)).append("</Value>\n");
426             xml.append(" </Column>\n");
427             xml.append(" <Column>\n");
428             xml.append(" <Name>ThreadReplyCount</Name>\n");
429             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadReplyCount)).append("</Value>\n");
430             xml.append(" </Column>\n");
431             xml.append(" <Column>\n");
432             xml.append(" <Name>ThreadIcon</Name>\n");
433             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadIcon)).append("</Value>\n");
434             xml.append(" </Column>\n");
435             xml.append(" <Column>\n");
436             xml.append(" <Name>ThreadDuration</Name>\n");
437             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadDuration)).append("</Value>\n");
438             xml.append(" </Column>\n");
439             xml.append(" <Column>\n");
440             xml.append(" <Name>ThreadAttachCount</Name>\n");
441             xml.append(" <Value>").append(String.valueOf(objThreadBean.threadAttachCount)).append("</Value>\n");
442             xml.append(" </Column>\n");
443             xml.append(" </Row>\n");
444         }//while
445
xml.append(" </Rows>\n");
446         xml.append("</ThreadSection>\n");
447         return xml.toString();
448     }
449
450     /************************************************
451      * Customized methods come below
452      ************************************************/

453     private int threadPendingPostCount;
454
455     public int getThreadPendingPostCount() {
456         return threadPendingPostCount;
457     }
458     public void setThreadPendingPostCount(int threadPendingPostCount) {
459         this.threadPendingPostCount = threadPendingPostCount;
460     }
461
462     private Collection JavaDoc pendingPosts;
463
464     public Collection JavaDoc getPendingPosts() {
465         return pendingPosts;
466     }
467     public void setPendingPosts(Collection JavaDoc pendingPosts) {
468         this.pendingPosts = pendingPosts;
469     }
470
471     static public void validateThreadStatus(int status) throws IllegalArgumentException JavaDoc {
472         if ((status < 0) || (status > THREAD_STATUS_CLOSED)) {
473             throw new IllegalArgumentException JavaDoc("Invalid ThreadStatus = " + status);
474         }
475     }
476
477     static public void validateThreadType(int type) throws IllegalArgumentException JavaDoc {
478         if ((type < 0) || (type > THREAD_TYPE_GLOBAL_ANNOUNCEMENT)) {
479             throw new IllegalArgumentException JavaDoc("Invalid ThreadType = " + type);
480         }
481     }
482
483     public void ensureStatusCanReply() throws IllegalArgumentException JavaDoc {
484         if ( (getThreadStatus() == ThreadBean.THREAD_STATUS_LOCKED) ||
485             (getThreadStatus() == ThreadBean.THREAD_STATUS_CLOSED)) {
486             // or we can throw AssertionException. indicate that the gui MUST hide the option
487
//@todo : localize me
488
throw new IllegalStateException JavaDoc("Cannot reply when the thread is closed or locked.");
489         }
490     }
491
492     public void ensureStatusCanEdit() throws IllegalArgumentException JavaDoc {
493         if ( (getThreadStatus() == ThreadBean.THREAD_STATUS_LOCKED) ) {
494             // or we can throw AssertionException. indicate that the gui MUST hide the option
495
//@todo : localize me
496
throw new IllegalStateException JavaDoc("Cannot edit post when the thread is locked.");
497         }
498     }
499
500 } //end of class ThreadBean
501
Popular Tags