001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/contrib/phpbb2mvnforum/src/org/mvnforum/phpbb2mvnforum/db/ForumBean.java,v 1.5 2007/12/07 04:13:40 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.5 $
005: * $Date: 2007/12/07 04:13:40 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Minh Nguyen
039: * @author: Mai Nguyen
040: */
041: package org.mvnforum.phpbb2mvnforum.db;
042:
043: import java.sql.Timestamp;
044: import java.util.Collection;
045: import java.util.Iterator;
046:
047: import org.w3c.dom.Document;
048: import org.w3c.dom.Element;
049: import org.w3c.dom.Node;
050:
051: import net.myvietnam.mvncore.util.StringUtil;
052: import net.myvietnam.mvncore.exception.BadInputException;
053: import com.mvnforum.MVNForumConfig;
054:
055: /*
056: * Included columns: ForumID, CategoryID, LastPostMemberName, ForumName, ForumDesc,
057: * ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType,
058: * ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword,
059: * ForumThreadCount, ForumPostCount
060: * Excluded columns:
061: */
062: public class ForumBean {
063: /*************************************************************************
064: * NOTE: below constants MUST NOT be changed IN ALL CASES,
065: * or it will break the compatibility
066: *************************************************************************/
067:
068: /** The default value mean forum is enable and normal */
069: public final static int FORUM_STATUS_DEFAULT = 0;
070:
071: /** The disabled value mean forum is disabled */
072: public final static int FORUM_STATUS_DISABLED = 1;
073:
074: /**
075: * No changes (edit, attach, reply) could be maded, moderator
076: * have to change this status before making any changes is possible
077: */
078: public final static int FORUM_STATUS_LOCKED = 2;
079:
080: /** Noone can reply, but moderator can change it */
081: public final static int FORUM_STATUS_CLOSED = 3;
082:
083: /** */
084: public final static int FORUM_TYPE_DEFAULT = 0;
085:
086: /** */
087: public final static int FORUM_TYPE_PRIVATE = 1;
088:
089: /** */
090: public final static int FORUM_MODERATION_MODE_SYSTEM_DEFAULT = 0;
091:
092: /** */
093: public final static int FORUM_MODERATION_MODE_NO_MODERATION = 1;
094:
095: /** */
096: public final static int FORUM_MODERATION_MODE_THREAD_AND_POST = 2;
097:
098: /** */
099: public final static int FORUM_MODERATION_MODE_THREAD_ONLY = 3;
100:
101: /** */
102: public final static int FORUM_MODERATION_MODE_POST_ONLY = 4;
103:
104: private int forumID;
105: private int categoryID;
106: private String lastPostMemberName;
107: private String forumName;
108: private String forumDesc;
109: private Timestamp forumCreationDate;
110: private Timestamp forumModifiedDate;
111: private Timestamp forumLastPostDate;
112: private int forumOrder;
113: private int forumType;
114: private int forumFormatOption;
115: private int forumOption;
116: private int forumStatus;
117: private int forumModerationMode;
118: private String forumPassword;
119: private int forumThreadCount;
120: private int forumPostCount;
121:
122: public int getForumID() {
123: return forumID;
124: }
125:
126: public void setForumID(int forumID) {
127: this .forumID = forumID;
128: }
129:
130: public int getCategoryID() {
131: return categoryID;
132: }
133:
134: public void setCategoryID(int categoryID) {
135: this .categoryID = categoryID;
136: }
137:
138: public String getLastPostMemberName() {
139: return lastPostMemberName;
140: }
141:
142: public void setLastPostMemberName(String lastPostMemberName) {
143: this .lastPostMemberName = StringUtil
144: .getEmptyStringIfNull(lastPostMemberName);
145: }
146:
147: public String getForumName() {
148: return forumName;
149: }
150:
151: public void setForumName(String forumName) {
152: this .forumName = forumName;
153: }
154:
155: public String getForumDesc() {
156: return forumDesc;
157: }
158:
159: public void setForumDesc(String forumDesc) {
160: this .forumDesc = StringUtil.getEmptyStringIfNull(forumDesc);
161: }
162:
163: public Timestamp getForumCreationDate() {
164: return forumCreationDate;
165: }
166:
167: public void setForumCreationDate(Timestamp forumCreationDate) {
168: this .forumCreationDate = forumCreationDate;
169: }
170:
171: public Timestamp getForumModifiedDate() {
172: return forumModifiedDate;
173: }
174:
175: public void setForumModifiedDate(Timestamp forumModifiedDate) {
176: this .forumModifiedDate = forumModifiedDate;
177: }
178:
179: public Timestamp getForumLastPostDate() {
180: return forumLastPostDate;
181: }
182:
183: public void setForumLastPostDate(Timestamp forumLastPostDate) {
184: this .forumLastPostDate = forumLastPostDate;
185: }
186:
187: public int getForumOrder() {
188: return forumOrder;
189: }
190:
191: public void setForumOrder(int forumOrder) {
192: this .forumOrder = forumOrder;
193: }
194:
195: public int getForumType() {
196: return forumType;
197: }
198:
199: public void setForumType(int forumType) {
200: this .forumType = forumType;
201: }
202:
203: public int getForumFormatOption() {
204: return forumFormatOption;
205: }
206:
207: public void setForumFormatOption(int forumFormatOption) {
208: this .forumFormatOption = forumFormatOption;
209: }
210:
211: public int getForumOption() {
212: return forumOption;
213: }
214:
215: public void setForumOption(int forumOption) {
216: this .forumOption = forumOption;
217: }
218:
219: public int getForumStatus() {
220: return forumStatus;
221: }
222:
223: public void setForumStatus(int forumStatus) {
224: this .forumStatus = forumStatus;
225: }
226:
227: public int getForumModerationMode() {
228: return forumModerationMode;
229: }
230:
231: public void setForumModerationMode(int forumModerationMode) {
232: this .forumModerationMode = forumModerationMode;
233: }
234:
235: public String getForumPassword() {
236: return forumPassword;
237: }
238:
239: public void setForumPassword(String forumPassword) {
240: this .forumPassword = StringUtil
241: .getEmptyStringIfNull(forumPassword);
242: }
243:
244: public int getForumThreadCount() {
245: return forumThreadCount;
246: }
247:
248: public void setForumThreadCount(int forumThreadCount) {
249: this .forumThreadCount = forumThreadCount;
250: }
251:
252: public int getForumPostCount() {
253: return forumPostCount;
254: }
255:
256: public void setForumPostCount(int forumPostCount) {
257: this .forumPostCount = forumPostCount;
258: }
259:
260: public void getBeanDocument(Document doc, Element element) {
261: Element category = doc.createElement("Forum");
262: element.appendChild(category);
263:
264: category.appendChild(getNode(doc, "ForumID", String
265: .valueOf(forumID)));
266: category.appendChild(getNode(doc, "CategoryID", String
267: .valueOf(categoryID)));
268: category.appendChild(getNode(doc, "LastPostMemberName", String
269: .valueOf(lastPostMemberName)));
270: category.appendChild(getNode(doc, "ForumName", String
271: .valueOf(forumName)));
272: category.appendChild(getNode(doc, "ForumDesc", String
273: .valueOf(forumDesc)));
274: category.appendChild(getNode(doc, "ForumCreationDate", String
275: .valueOf(forumCreationDate)));
276: category.appendChild(getNode(doc, "ForumModifiedDate", String
277: .valueOf(forumModifiedDate)));
278: category.appendChild(getNode(doc, "ForumLastPostDate", String
279: .valueOf(forumLastPostDate)));
280: category.appendChild(getNode(doc, "ForumOrder", String
281: .valueOf(forumOrder)));
282: category.appendChild(getNode(doc, "ForumType", String
283: .valueOf(forumType)));
284: category.appendChild(getNode(doc, "ForumFormatOption", String
285: .valueOf(forumFormatOption)));
286: category.appendChild(getNode(doc, "ForumOption", String
287: .valueOf(forumOption)));
288: category.appendChild(getNode(doc, "ForumStatus", String
289: .valueOf(forumStatus)));
290: category.appendChild(getNode(doc, "ForumModerationMode", String
291: .valueOf(forumModerationMode)));
292: category.appendChild(getNode(doc, "ForumPassword", String
293: .valueOf(forumPassword)));
294: category.appendChild(getNode(doc, "ForumThreadCount", String
295: .valueOf(forumThreadCount)));
296: category.appendChild(getNode(doc, "ForumPostCount", String
297: .valueOf(forumPostCount)));
298: }
299:
300: public static Node getNode(Document doc, String childName,
301: String childValue) {
302: Element child = doc.createElement(childName);
303: child.appendChild(doc.createTextNode(childValue));
304: return child;
305: }
306:
307: public String getXML() {
308: StringBuffer xml = new StringBuffer(1024);
309: xml.append("<ForumSection>\n");
310: xml.append(" <Rows>\n");
311: xml.append(" <Row>\n");
312: xml.append(" <Column>\n");
313: xml.append(" <Name>ForumID</Name>\n");
314: xml.append(" <Value>").append(String.valueOf(forumID))
315: .append("</Value>\n");
316: xml.append(" </Column>\n");
317: xml.append(" <Column>\n");
318: xml.append(" <Name>CategoryID</Name>\n");
319: xml.append(" <Value>")
320: .append(String.valueOf(categoryID))
321: .append("</Value>\n");
322: xml.append(" </Column>\n");
323: xml.append(" <Column>\n");
324: xml.append(" <Name>LastPostMemberName</Name>\n");
325: xml.append(" <Value>").append(
326: String.valueOf(lastPostMemberName))
327: .append("</Value>\n");
328: xml.append(" </Column>\n");
329: xml.append(" <Column>\n");
330: xml.append(" <Name>ForumName</Name>\n");
331: xml.append(" <Value>").append(String.valueOf(forumName))
332: .append("</Value>\n");
333: xml.append(" </Column>\n");
334: xml.append(" <Column>\n");
335: xml.append(" <Name>ForumDesc</Name>\n");
336: xml.append(" <Value>").append(String.valueOf(forumDesc))
337: .append("</Value>\n");
338: xml.append(" </Column>\n");
339: xml.append(" <Column>\n");
340: xml.append(" <Name>ForumCreationDate</Name>\n");
341: xml.append(" <Value>").append(
342: String.valueOf(forumCreationDate)).append("</Value>\n");
343: xml.append(" </Column>\n");
344: xml.append(" <Column>\n");
345: xml.append(" <Name>ForumModifiedDate</Name>\n");
346: xml.append(" <Value>").append(
347: String.valueOf(forumModifiedDate)).append("</Value>\n");
348: xml.append(" </Column>\n");
349: xml.append(" <Column>\n");
350: xml.append(" <Name>ForumLastPostDate</Name>\n");
351: xml.append(" <Value>").append(
352: String.valueOf(forumLastPostDate)).append("</Value>\n");
353: xml.append(" </Column>\n");
354: xml.append(" <Column>\n");
355: xml.append(" <Name>ForumOrder</Name>\n");
356: xml.append(" <Value>")
357: .append(String.valueOf(forumOrder))
358: .append("</Value>\n");
359: xml.append(" </Column>\n");
360: xml.append(" <Column>\n");
361: xml.append(" <Name>ForumType</Name>\n");
362: xml.append(" <Value>").append(String.valueOf(forumType))
363: .append("</Value>\n");
364: xml.append(" </Column>\n");
365: xml.append(" <Column>\n");
366: xml.append(" <Name>ForumFormatOption</Name>\n");
367: xml.append(" <Value>").append(
368: String.valueOf(forumFormatOption)).append("</Value>\n");
369: xml.append(" </Column>\n");
370: xml.append(" <Column>\n");
371: xml.append(" <Name>ForumOption</Name>\n");
372: xml.append(" <Value>").append(
373: String.valueOf(forumOption)).append("</Value>\n");
374: xml.append(" </Column>\n");
375: xml.append(" <Column>\n");
376: xml.append(" <Name>ForumStatus</Name>\n");
377: xml.append(" <Value>").append(
378: String.valueOf(forumStatus)).append("</Value>\n");
379: xml.append(" </Column>\n");
380: xml.append(" <Column>\n");
381: xml.append(" <Name>ForumModerationMode</Name>\n");
382: xml.append(" <Value>").append(
383: String.valueOf(forumModerationMode)).append(
384: "</Value>\n");
385: xml.append(" </Column>\n");
386: xml.append(" <Column>\n");
387: xml.append(" <Name>ForumPassword</Name>\n");
388: xml.append(" <Value>").append(
389: String.valueOf(forumPassword)).append("</Value>\n");
390: xml.append(" </Column>\n");
391: xml.append(" <Column>\n");
392: xml.append(" <Name>ForumThreadCount</Name>\n");
393: xml.append(" <Value>").append(
394: String.valueOf(forumThreadCount)).append("</Value>\n");
395: xml.append(" </Column>\n");
396: xml.append(" <Column>\n");
397: xml.append(" <Name>ForumPostCount</Name>\n");
398: xml.append(" <Value>").append(
399: String.valueOf(forumPostCount)).append("</Value>\n");
400: xml.append(" </Column>\n");
401: xml.append(" </Row>\n");
402: xml.append(" </Rows>\n");
403: xml.append("</ForumSection>\n");
404: return xml.toString();
405: }
406:
407: public static String getXML(Collection objForumBeans) {
408: StringBuffer xml = new StringBuffer(1024);
409: Iterator iterator = objForumBeans.iterator();
410: xml.append("<ForumSection>\n");
411: xml.append(" <Rows>\n");
412: while (iterator.hasNext()) {
413: ForumBean objForumBean = (ForumBean) iterator.next();
414: xml.append(" <Row>\n");
415: xml.append(" <Column>\n");
416: xml.append(" <Name>ForumID</Name>\n");
417: xml.append(" <Value>").append(
418: String.valueOf(objForumBean.forumID)).append(
419: "</Value>\n");
420: xml.append(" </Column>\n");
421: xml.append(" <Column>\n");
422: xml.append(" <Name>CategoryID</Name>\n");
423: xml.append(" <Value>").append(
424: String.valueOf(objForumBean.categoryID)).append(
425: "</Value>\n");
426: xml.append(" </Column>\n");
427: xml.append(" <Column>\n");
428: xml.append(" <Name>LastPostMemberName</Name>\n");
429: xml.append(" <Value>").append(
430: String.valueOf(objForumBean.lastPostMemberName))
431: .append("</Value>\n");
432: xml.append(" </Column>\n");
433: xml.append(" <Column>\n");
434: xml.append(" <Name>ForumName</Name>\n");
435: xml.append(" <Value>").append(
436: String.valueOf(objForumBean.forumName)).append(
437: "</Value>\n");
438: xml.append(" </Column>\n");
439: xml.append(" <Column>\n");
440: xml.append(" <Name>ForumDesc</Name>\n");
441: xml.append(" <Value>").append(
442: String.valueOf(objForumBean.forumDesc)).append(
443: "</Value>\n");
444: xml.append(" </Column>\n");
445: xml.append(" <Column>\n");
446: xml.append(" <Name>ForumCreationDate</Name>\n");
447: xml.append(" <Value>").append(
448: String.valueOf(objForumBean.forumCreationDate))
449: .append("</Value>\n");
450: xml.append(" </Column>\n");
451: xml.append(" <Column>\n");
452: xml.append(" <Name>ForumModifiedDate</Name>\n");
453: xml.append(" <Value>").append(
454: String.valueOf(objForumBean.forumModifiedDate))
455: .append("</Value>\n");
456: xml.append(" </Column>\n");
457: xml.append(" <Column>\n");
458: xml.append(" <Name>ForumLastPostDate</Name>\n");
459: xml.append(" <Value>").append(
460: String.valueOf(objForumBean.forumLastPostDate))
461: .append("</Value>\n");
462: xml.append(" </Column>\n");
463: xml.append(" <Column>\n");
464: xml.append(" <Name>ForumOrder</Name>\n");
465: xml.append(" <Value>").append(
466: String.valueOf(objForumBean.forumOrder)).append(
467: "</Value>\n");
468: xml.append(" </Column>\n");
469: xml.append(" <Column>\n");
470: xml.append(" <Name>ForumType</Name>\n");
471: xml.append(" <Value>").append(
472: String.valueOf(objForumBean.forumType)).append(
473: "</Value>\n");
474: xml.append(" </Column>\n");
475: xml.append(" <Column>\n");
476: xml.append(" <Name>ForumFormatOption</Name>\n");
477: xml.append(" <Value>").append(
478: String.valueOf(objForumBean.forumFormatOption))
479: .append("</Value>\n");
480: xml.append(" </Column>\n");
481: xml.append(" <Column>\n");
482: xml.append(" <Name>ForumOption</Name>\n");
483: xml.append(" <Value>").append(
484: String.valueOf(objForumBean.forumOption)).append(
485: "</Value>\n");
486: xml.append(" </Column>\n");
487: xml.append(" <Column>\n");
488: xml.append(" <Name>ForumStatus</Name>\n");
489: xml.append(" <Value>").append(
490: String.valueOf(objForumBean.forumStatus)).append(
491: "</Value>\n");
492: xml.append(" </Column>\n");
493: xml.append(" <Column>\n");
494: xml.append(" <Name>ForumModerationMode</Name>\n");
495: xml.append(" <Value>").append(
496: String.valueOf(objForumBean.forumModerationMode))
497: .append("</Value>\n");
498: xml.append(" </Column>\n");
499: xml.append(" <Column>\n");
500: xml.append(" <Name>ForumPassword</Name>\n");
501: xml.append(" <Value>").append(
502: String.valueOf(objForumBean.forumPassword)).append(
503: "</Value>\n");
504: xml.append(" </Column>\n");
505: xml.append(" <Column>\n");
506: xml.append(" <Name>ForumThreadCount</Name>\n");
507: xml.append(" <Value>").append(
508: String.valueOf(objForumBean.forumThreadCount))
509: .append("</Value>\n");
510: xml.append(" </Column>\n");
511: xml.append(" <Column>\n");
512: xml.append(" <Name>ForumPostCount</Name>\n");
513: xml.append(" <Value>").append(
514: String.valueOf(objForumBean.forumPostCount))
515: .append("</Value>\n");
516: xml.append(" </Column>\n");
517: xml.append(" </Row>\n");
518: }//while
519: xml.append(" </Rows>\n");
520: xml.append("</ForumSection>\n");
521: return xml.toString();
522: }
523:
524: /************************************************
525: * Customized methods come below
526: ************************************************/
527: private int pendingThreadCount = 0;
528: private int threadsWithPendingPostsCount = 0;
529: private int pendingPostCount = 0;
530:
531: public int getPendingPostCount() {
532: return pendingPostCount;
533: }
534:
535: public void setPendingPostCount(int pendingPostCount) {
536: this .pendingPostCount = pendingPostCount;
537: }
538:
539: public int getPendingThreadCount() {
540: return pendingThreadCount;
541: }
542:
543: public void setPendingThreadCount(int pendingThreadCount) {
544: this .pendingThreadCount = pendingThreadCount;
545: }
546:
547: public int getThreadsWithPendingPostsCount() {
548: return threadsWithPendingPostsCount;
549: }
550:
551: public void setThreadsWithPendingPostsCount(
552: int threadsWithPendingPostsCount) {
553: this .threadsWithPendingPostsCount = threadsWithPendingPostsCount;
554: }
555:
556: static public void validateForumType(int type)
557: throws IllegalArgumentException {
558: if ((type < 0) || (type > FORUM_TYPE_PRIVATE)) {
559: throw new IllegalArgumentException("Invalid ForumType = "
560: + type);
561: }
562: }
563:
564: static public void validateForumModerationMode(int moderationMod)
565: throws IllegalArgumentException {
566: if ((moderationMod < 0)
567: || (moderationMod > FORUM_MODERATION_MODE_POST_ONLY)) {
568: throw new IllegalArgumentException(
569: "Invalid ForumModerationMod = " + moderationMod);
570: }
571: }
572:
573: static public void validateForumStatus(int status)
574: throws IllegalArgumentException {
575: if ((status < 0) || (status > FORUM_STATUS_CLOSED)) {
576: throw new IllegalArgumentException("Invalid ForumStatus = "
577: + status);
578: }
579: }
580:
581: static public void validateForumOption(int option)
582: throws IllegalArgumentException {
583: if ((option < 0) || (option > 0)) {
584: throw new IllegalArgumentException("Invalid ForumOption = "
585: + option);
586: }
587: }
588:
589: static public void validateForumFormatOption(int option)
590: throws IllegalArgumentException {
591: if ((option < 0) || (option > 0)) {
592: throw new IllegalArgumentException(
593: "Invalid ForumFormatOption = " + option);
594: }
595: }
596:
597: public void ensureNotDisabledForum() throws BadInputException {
598: if (forumStatus == ForumBean.FORUM_STATUS_DISABLED) {
599: throw new BadInputException(
600: "Cannot process this action in a disabled forum.");//@todo : localize me
601: }
602: }
603:
604: public void ensureNotLockedForum() throws BadInputException {
605: if (forumStatus == ForumBean.FORUM_STATUS_LOCKED) {
606: throw new BadInputException(
607: "Cannot process this action in a locked forum.");//@todo : localize me
608: }
609: }
610:
611: public void ensureNotClosedForum() throws BadInputException {
612: if (forumStatus == ForumBean.FORUM_STATUS_CLOSED) {
613: throw new BadInputException(
614: "Cannot process this action in a closed forum.");//@todo : localize me
615: }
616: }
617:
618: public boolean shouldModeratePost() {
619: int mode = forumModerationMode;
620: if (mode == FORUM_MODERATION_MODE_SYSTEM_DEFAULT) {
621: mode = MVNForumConfig.getDefaultModerationOption();
622: }
623: if ((mode == FORUM_MODERATION_MODE_POST_ONLY)
624: || (mode == FORUM_MODERATION_MODE_THREAD_AND_POST)) {
625: return true;
626: }
627: return false;
628: }
629:
630: public boolean shouldModerateThread() {
631: int mode = forumModerationMode;
632: if (mode == FORUM_MODERATION_MODE_SYSTEM_DEFAULT) {
633: mode = MVNForumConfig.getDefaultModerationOption();
634: }
635: if ((mode == FORUM_MODERATION_MODE_THREAD_ONLY)
636: || (mode == FORUM_MODERATION_MODE_THREAD_AND_POST)) {
637: return true;
638: }
639: return false;
640: }
641:
642: } //end of class ForumBean
|