home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/db/ForumBean.java,v 1.13 2005/01/18 11:52:18 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.13 $
 * $Date: 2005/01/18 11:52:18 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2005 by MyVietnam.net
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * All copyright notices regarding mvnForum MUST remain intact
 * in the scripts and in the outputted HTML.
 * The "powered by" text/logo with a link back to
 * http://www.mvnForum.com and http://www.MyVietnam.net in the
 * footer of the pages MUST remain visible when the pages
 * are viewed on the internet or intranet.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Support can be obtained from support forums at:
 * http://www.mvnForum.com/mvnforum/index
 *
 * Correspondence and Marketing Questions can be sent to:
 * info@MyVietnam.net
 *
 * @author: Minh Nguyen  minhnn@MyVietnam.net
 * @author: Mai  Nguyen  mai.nh@MyVietnam.net
 */
package com.mvnforum.db;

import java.sql.Timestamp;
import java.util.Collection;
import java.util.Iterator;

import net.myvietnam.mvncore.util.StringUtil;
import net.myvietnam.mvncore.exception.BadInputException;
import com.mvnforum.MVNForumConfig;

/*
 * Included columns: ForumID, CategoryID, LastPostMemberName, ForumName, ForumDesc,
 *                   ForumCreationDate, ForumModifiedDate, ForumLastPostDate, ForumOrder, ForumType,
 *                   ForumFormatOption, ForumOption, ForumStatus, ForumModerationMode, ForumPassword,
 *                   ForumThreadCount, ForumPostCount
 * Excluded columns:
 */
public class ForumBean {
    /*************************************************************************
     * NOTE: below constants MUST NOT be changed IN ALL CASES,
     *       or it will break the compatibility
     *************************************************************************/

    /** The default value mean forum is enable and normal */
    public final static int FORUM_STATUS_DEFAULT                  = 0;

    /** The disabled value mean forum is disabled */
    public final static int FORUM_STATUS_DISABLED                 = 1;

    /**
     * No changes (edit, attach, reply) could be maded, moderator
     * have to change this status before making any changes is possible
     */
    public final static int FORUM_STATUS_LOCKED                   = 2;

    /** Noone can reply, but moderator can change it */
    public final static int FORUM_STATUS_CLOSED                   = 3;


    /**  */
    public final static int FORUM_TYPE_DEFAULT                    = 0;

    /**  */
    public final static int FORUM_TYPE_PRIVATE                    = 1;


    /**  */
    public final static int FORUM_MODERATION_MODE_SYSTEM_DEFAULT  = 0;

    /**  */
    public final static int FORUM_MODERATION_MODE_NO_MODERATION   = 1;

    /**  */
    public final static int FORUM_MODERATION_MODE_THREAD_AND_POST = 2;

    /**  */
    public final static int FORUM_MODERATION_MODE_THREAD_ONLY     = 3;

    /**  */
    public final static int FORUM_MODERATION_MODE_POST_ONLY       = 4;

    public final static String TYPE_NAMES[] = {"Default", "Private"};

    public final static String MODE_NAMES[] = {"System Default", "No Moderation", "Thread and Post Moderation", "Thread Only Moderation", "Post Only Moderation"};

    private int forumID;
    private int categoryID;
    private String lastPostMemberName;
    private String forumName;
    private String forumDesc;
    private Timestamp forumCreationDate;
    private Timestamp forumModifiedDate;
    private Timestamp forumLastPostDate;
    private int forumOrder;
    private int forumType;
    private int forumFormatOption;
    private int forumOption;
    private int forumStatus;
    private int forumModerationMode;
    private String forumPassword;
    private int forumThreadCount;
    private int forumPostCount;

    public int getForumID() {
        return forumID;
    }
    public void setForumID(int forumID) {
        this.forumID = forumID;
    }

    public int getCategoryID() {
        return categoryID;
    }
    public void setCategoryID(int categoryID) {
        this.categoryID = categoryID;
    }

    public String getLastPostMemberName() {
        return lastPostMemberName;
    }
    public void setLastPostMemberName(String lastPostMemberName) {
        this.lastPostMemberName = StringUtil.getEmptyStringIfNull(lastPostMemberName);
    }

    public String getForumName() {
        return forumName;
    }
    public void setForumName(String forumName) {
        this.forumName = forumName;
    }

    public String getForumDesc() {
        return forumDesc;
    }
    public void setForumDesc(String forumDesc) {
        this.forumDesc = StringUtil.getEmptyStringIfNull(forumDesc);
    }

    public Timestamp getForumCreationDate() {
        return forumCreationDate;
    }
    public void setForumCreationDate(Timestamp forumCreationDate) {
        this.forumCreationDate = forumCreationDate;
    }

    public Timestamp getForumModifiedDate() {
        return forumModifiedDate;
    }
    public void setForumModifiedDate(Timestamp forumModifiedDate) {
        this.forumModifiedDate = forumModifiedDate;
    }

    public Timestamp getForumLastPostDate() {
        return forumLastPostDate;
    }
    public void setForumLastPostDate(Timestamp forumLastPostDate) {
        this.forumLastPostDate = forumLastPostDate;
    }

    public int getForumOrder() {
        return forumOrder;
    }
    public void setForumOrder(int forumOrder) {
        this.forumOrder = forumOrder;
    }

    public int getForumType() {
        return forumType;
    }
    public void setForumType(int forumType) {
        this.forumType = forumType;
    }

    public int getForumFormatOption() {
        return forumFormatOption;
    }
    public void setForumFormatOption(int forumFormatOption) {
        this.forumFormatOption = forumFormatOption;
    }

    public int getForumOption() {
        return forumOption;
    }
    public void setForumOption(int forumOption) {
        this.forumOption = forumOption;
    }

    public int getForumStatus() {
        return forumStatus;
    }
    public void setForumStatus(int forumStatus) {
        this.forumStatus = forumStatus;
    }

    public int getForumModerationMode() {
        return forumModerationMode;
    }
    public void setForumModerationMode(int forumModerationMode) {
        this.forumModerationMode = forumModerationMode;
    }

    public String getForumPassword() {
        return forumPassword;
    }
    public void setForumPassword(String forumPassword) {
        this.forumPassword = StringUtil.getEmptyStringIfNull(forumPassword);
    }

    public int getForumThreadCount() {
        return forumThreadCount;
    }
    public void setForumThreadCount(int forumThreadCount) {
        this.forumThreadCount = forumThreadCount;
    }

    public int getForumPostCount() {
        return forumPostCount;
    }
    public void setForumPostCount(int forumPostCount) {
        this.forumPostCount = forumPostCount;
    }

    public String getXMLTag() {
        StringBuffer xml = new StringBuffer(1024);
        xml.append("<Forum");
        xml.append(" forumID=\"").append(String.valueOf(forumID)).append("\"");
        xml.append(" categoryID=\"").append(String.valueOf(categoryID)).append("\"");
        xml.append(" lastPostMemberName=\"").append(String.valueOf(lastPostMemberName)).append("\"");
        xml.append(" forumName=\"").append(String.valueOf(forumName)).append("\"");
        xml.append(" forumDesc=\"").append(String.valueOf(forumDesc)).append("\"");
        xml.append(" forumCreationDate=\"").append(String.valueOf(forumCreationDate)).append("\"");
        xml.append(" forumModifiedDate=\"").append(String.valueOf(forumModifiedDate)).append("\"");
        xml.append(" forumLastPostDate=\"").append(String.valueOf(forumLastPostDate)).append("\"");
        xml.append(" forumOrder=\"").append(String.valueOf(forumOrder)).append("\"");
        xml.append(" forumType=\"").append(String.valueOf(forumType)).append("\"");
        xml.append(" forumFormatOption=\"").append(String.valueOf(forumFormatOption)).append("\"");
        xml.append(" forumOption=\"").append(String.valueOf(forumOption)).append("\"");
        xml.append(" forumStatus=\"").append(String.valueOf(forumStatus)).append("\"");
        xml.append(" forumModerationMode=\"").append(String.valueOf(forumModerationMode)).append("\"");
        xml.append(" forumPassword=\"").append(String.valueOf(forumPassword)).append("\"");
        xml.append(" forumThreadCount=\"").append(String.valueOf(forumThreadCount)).append("\"");
        xml.append(" forumPostCount=\"").append(String.valueOf(forumPostCount)).append("\"");
        xml.append(">");
        return xml.toString();
    }

    public String getXML() {
        StringBuffer xml = new StringBuffer(1024);
        xml.append("<ForumSection>\n");
        xml.append("  <Rows>\n");
        xml.append("    <Row>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumID\n");
        xml.append("        <Value>").append(String.valueOf(forumID)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>CategoryID\n");
        xml.append("        <Value>").append(String.valueOf(categoryID)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>LastPostMemberName\n");
        xml.append("        <Value>").append(String.valueOf(lastPostMemberName)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumName\n");
        xml.append("        <Value>").append(String.valueOf(forumName)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumDesc\n");
        xml.append("        <Value>").append(String.valueOf(forumDesc)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumCreationDate\n");
        xml.append("        <Value>").append(String.valueOf(forumCreationDate)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumModifiedDate\n");
        xml.append("        <Value>").append(String.valueOf(forumModifiedDate)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumLastPostDate\n");
        xml.append("        <Value>").append(String.valueOf(forumLastPostDate)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumOrder\n");
        xml.append("        <Value>").append(String.valueOf(forumOrder)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumType\n");
        xml.append("        <Value>").append(String.valueOf(forumType)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumFormatOption\n");
        xml.append("        <Value>").append(String.valueOf(forumFormatOption)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumOption\n");
        xml.append("        <Value>").append(String.valueOf(forumOption)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumStatus\n");
        xml.append("        <Value>").append(String.valueOf(forumStatus)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumModerationMode\n");
        xml.append("        <Value>").append(String.valueOf(forumModerationMode)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumPassword\n");
        xml.append("        <Value>").append(String.valueOf(forumPassword)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumThreadCount\n");
        xml.append("        <Value>").append(String.valueOf(forumThreadCount)).append("\n");
        xml.append("      </Column>\n");
        xml.append("      <Column>\n");
        xml.append("        <Name>ForumPostCount\n");
        xml.append("        <Value>").append(String.valueOf(forumPostCount)).append("\n");
        xml.append("      </Column>\n");
        xml.append("    </Row>\n");
        xml.append("  </Rows>\n");
        xml.append("</ForumSection>\n");
        return xml.toString();
    }

    public static String getXML(Collection objForumBeans) {
        StringBuffer xml = new StringBuffer(1024);
        Iterator iterator = objForumBeans.iterator();
        xml.append("<ForumSection>\n");
        xml.append("  <Rows>\n");
        while (iterator.hasNext()) {
            ForumBean objForumBean = (ForumBean)iterator.next();
            xml.append("    <Row>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumID\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumID)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>CategoryID\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.categoryID)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>LastPostMemberName\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.lastPostMemberName)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumName\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumName)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumDesc\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumDesc)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumCreationDate\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumCreationDate)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumModifiedDate\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumModifiedDate)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumLastPostDate\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumLastPostDate)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumOrder\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumOrder)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumType\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumType)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumFormatOption\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumFormatOption)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumOption\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumOption)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumStatus\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumStatus)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumModerationMode\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumModerationMode)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumPassword\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumPassword)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumThreadCount\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumThreadCount)).append("\n");
            xml.append("      </Column>\n");
            xml.append("      <Column>\n");
            xml.append("        <Name>ForumPostCount\n");
            xml.append("        <Value>").append(String.valueOf(objForumBean.forumPostCount)).append("\n");
            xml.append("      </Column>\n");
            xml.append("    </Row>\n");
        }//while
        xml.append("  </Rows>\n");
        xml.append("</ForumSection>\n");
        return xml.toString();
    }

    /************************************************
     * Customized methods come below
     ************************************************/
    private int pendingThreadCount = 0;
    private int threadsWithPendingPostsCount = 0;
    private int pendingPostCount = 0;

    public int getPendingPostCount() {
        return pendingPostCount;
    }
    public void setPendingPostCount(int pendingPostCount) {
        this.pendingPostCount = pendingPostCount;
    }

    public int getPendingThreadCount() {
        return pendingThreadCount;
    }
    public void setPendingThreadCount(int pendingThreadCount) {
        this.pendingThreadCount = pendingThreadCount;
    }

    public int getThreadsWithPendingPostsCount() {
        return threadsWithPendingPostsCount;
    }
    public void setThreadsWithPendingPostsCount(int threadsWithPendingPostsCount) {
        this.threadsWithPendingPostsCount = threadsWithPendingPostsCount;
    }

    static public void validateForumType(int type) throws IllegalArgumentException {
        if ((type < 0) || (type > FORUM_TYPE_PRIVATE)) {
            throw new IllegalArgumentException("Invalid ForumType = " + type);
        }
    }

    static public void validateForumModerationMode(int moderationMod) throws IllegalArgumentException {
        if ((moderationMod < 0) || (moderationMod > FORUM_MODERATION_MODE_POST_ONLY)) {
            throw new IllegalArgumentException("Invalid ForumModerationMod = " + moderationMod);
        }
    }

    static public void validateForumStatus(int status) throws IllegalArgumentException {
        if ((status < 0) || (status > FORUM_STATUS_CLOSED)) {
            throw new IllegalArgumentException("Invalid ForumStatus = " + status);
        }
    }

    static public void validateForumOption(int option) throws IllegalArgumentException {
        if ((option < 0) || (option > 0)) {
            throw new IllegalArgumentException("Invalid ForumOption = " + option);
        }
    }

    static public void validateForumFormatOption(int option) throws IllegalArgumentException {
        if ((option < 0) || (option > 0)) {
            throw new IllegalArgumentException("Invalid ForumFormatOption = " + option);
        }
    }

    public void ensureNotDisabledForum() throws BadInputException {
        if (forumStatus == ForumBean.FORUM_STATUS_DISABLED) {
            throw new BadInputException("Cannnot process this action in a disabled forum.");//@todo : localize me
        }
    }

    public void ensureNotLockedForum() throws BadInputException {
        if (forumStatus == ForumBean.FORUM_STATUS_LOCKED) {
            throw new BadInputException("Cannnot process this action in a locked forum.");//@todo : localize me
        }
    }

    public void ensureNotClosedForum() throws BadInputException {
        if (forumStatus == ForumBean.FORUM_STATUS_CLOSED) {
            throw new BadInputException("Cannnot process this action in a closed forum.");//@todo : localize me
        }
    }

    public boolean shouldModeratePost() {
        int mode = forumModerationMode;
        if (mode == FORUM_MODERATION_MODE_SYSTEM_DEFAULT) {
            mode = MVNForumConfig.getDefaultModerationOption();
        }
        if ((mode == FORUM_MODERATION_MODE_POST_ONLY) || (mode == FORUM_MODERATION_MODE_THREAD_AND_POST)) {
            return true;
        }
        return false;
    }

    public boolean shouldModerateThread() {
        int mode = forumModerationMode;
        if (mode == FORUM_MODERATION_MODE_SYSTEM_DEFAULT) {
            mode = MVNForumConfig.getDefaultModerationOption();
        }
        if ((mode == FORUM_MODERATION_MODE_THREAD_ONLY) || (mode == FORUM_MODERATION_MODE_THREAD_AND_POST)) {
            return true;
        }
        return false;
    }

    public String getForumModeName() {
        return MODE_NAMES[this.forumModerationMode];
    }

    public String getForumTypeName() {
        return TYPE_NAMES[this.forumType];
    }


} //end of class ForumBean


my book on functional programming

 

new blog posts

 

Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.