⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forumwebhandler.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
字号:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/ForumWebHandler.java,v 1.34 2006/04/14 17:05:25 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.34 $
 * $Date: 2006/04/14 17:05:25 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2006 by MyVietnam.net
 *
 * 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 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.
 *
 * 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 at MyVietnam net
 *
 * @author: Minh Nguyen  
 * @author: Mai  Nguyen  
 */
package com.mvnforum.admin;

import java.sql.Timestamp;
import java.util.Locale;

import com.mvnforum.*;
import com.mvnforum.auth.*;
import com.mvnforum.common.AttachmentUtil;
import com.mvnforum.db.*;
import com.mvnforum.search.post.DeletePostIndexTask;
import com.mvnforum.search.post.PostIndexer;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
import net.myvietnam.mvncore.util.*;
import net.myvietnam.mvncore.web.GenericRequest;
import net.myvietnam.mvncore.web.GenericResponse;

public class ForumWebHandler {

    private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();

    public ForumWebHandler() {
    }

    public void processAdd(GenericRequest request, GenericResponse response)
        throws BadInputException, CreateException, DatabaseException, DuplicateKeyException,
        ForeignKeyNotFoundException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        permission.ensureCanAddForum();

        MyUtil.saveVNTyperMode(request, response);
        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        int categoryID              = GenericParamUtil.getParameterInt(request, "CategoryID");
        String forumName            = GenericParamUtil.getParameterSafe(request, "ForumName", true);
        forumName = DisableHtmlTagFilter.filter(forumName);
        String forumDesc            = GenericParamUtil.getParameterSafe(request, "ForumDesc", false);
        forumDesc = DisableHtmlTagFilter.filter(forumDesc);
        int forumType               = GenericParamUtil.getParameterInt(request, "ForumType");
        int forumFormatOption       = 0;//@todo review and support it later
        int forumOption             = 0;//@todo review and support it later
        int forumStatus             = GenericParamUtil.getParameterInt(request, "ForumStatus");
        int forumModerationMode     = GenericParamUtil.getParameterInt(request, "ForumModerationMode");
        String forumPassword        = "";//@todo review and support it later

        // check valid
        ForumBean.validateForumType(forumType);
        ForumBean.validateForumFormatOption(forumFormatOption);
        ForumBean.validateForumOption(forumOption);
        ForumBean.validateForumStatus(forumStatus);
        ForumBean.validateForumModerationMode(forumModerationMode);

        int forumID = DAOFactory.getForumDAO().createForum(categoryID, ""/*lastPostMemberName*/, forumName,
                                  forumDesc, now/*forumCreationDate*/, now/*forumModifiedDate*/,
                                  now/*forumLastPostDate*/, 0/*forumOrder*/, forumType,
                                  forumFormatOption, forumOption, forumStatus,
                                  forumModerationMode, forumPassword, 0/*forumThreadCount*/,
                                  0/*forumPostCount*/);

        // Check if the user created forum should be the owner (ForumAdmin) of that forum
        // This is used for KG
        if (MVNForumConfig.getEnableAutoForumOwner()) {
            int memberID = onlineUser.getMemberID();
            DAOFactory.getMemberForumDAO().create(memberID, forumID, MVNForumPermission.PERMISSION_FORUM_ADMIN);
            onlineUser.reloadPermission();
        }

        // For Company, we auto add PERMISSION_NORMAL_USER of the relation of forum and group of this company
        try {
            int companyID = GenericParamUtil.getParameterInt(request, "companyid");
            CompanyBean companyBean = DAOFactory.getCompanyDAO().getCompany(companyID);
            int groupID = companyBean.getGroupID();
            DAOFactory.getGroupForumDAO().create(groupID, forumID, MVNForumPermission.PERMISSION_NORMAL_USER);
        } catch (Exception ex) {
            // catch all Exception and just ignore
        }
        
        // Now clear the cache
        ForumCache.getInstance().clear();

        request.setAttribute("ForumName", forumName);
    }
    
    public void prepareDelete(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();

        // primary key column(s)
        int forumID = GenericParamUtil.getParameterInt(request, "forum");

        permission.ensureCanDeleteForum(forumID);

        ForumBean forumBean = null;
        try {
            forumBean = DAOFactory.getForumDAO().getForum(forumID);
        } catch (ObjectNotFoundException e) {
            Locale locale = I18nUtil.getLocaleInRequest(request);
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object[] {new Integer(forumID)});
            throw new ObjectNotFoundException(localizedMessage);
        }
        int numberOfThreads = DAOFactory.getThreadDAO().getNumberOfEnableThreads_inForum(forumID);
        int numberOfPosts = DAOFactory.getPostDAO().getNumberOfEnablePosts_inForum(forumID);

        int numberOfPendingThreads = DAOFactory.getThreadDAO().getNumberOfDisableThreads_inForum(forumID);
        int numberOfPendingPosts = DAOFactory.getPostDAO().getNumberOfDisablePosts_inForum(forumID);

        request.setAttribute("ForumBean", forumBean);
        request.setAttribute("NumberOfThreads", new Integer(numberOfThreads));
        request.setAttribute("NumberOfPosts", new Integer(numberOfPosts));
        request.setAttribute("NumberOfPendingThreads", new Integer(numberOfPendingThreads));
        request.setAttribute("NumberOfPendingPosts", new Integer(numberOfPendingPosts));
    }

    public void processDelete(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();

        // primary key column(s)
        int forumID = GenericParamUtil.getParameterInt(request, "forum");

        // user must have been authenticated before he can delete
        permission.ensureIsAuthenticated();

        permission.ensureCanDeleteForum(forumID);

        // now check the password
        MyUtil.ensureCorrectCurrentPassword(request);

        // Delete all attachments in this forum,
        // we must call this before any attempt to delete the post/thread/forum
        // That is, the order when delete is VERY IMPORTANT
        AttachmentUtil.deleteAttachments_inForum(forumID);

        DAOFactory.getGroupForumDAO().delete_inForum(forumID);
        DAOFactory.getMemberForumDAO().delete_inForum(forumID);

        DAOFactory.getFavoriteThreadDAO().delete_inForum(forumID);

        DAOFactory.getWatchDAO().delete_inForum(forumID);

        DAOFactory.getPostDAO().delete_inForum(forumID);
        DAOFactory.getThreadDAO().delete_inForum(forumID);

        // now delete the forum, note that we delete it after delete all child objects
        DAOFactory.getForumDAO().delete(forumID);

        // now update the search index
        PostIndexer.scheduleDeletePostTask(forumID, DeletePostIndexTask.OBJECT_TYPE_FORUM);

        // Clear cache
        PostCache.getInstance().clear();
        ThreadCache.getInstance().clear();
        ForumCache.getInstance().clear();
    }

    public void prepareEdit(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();

        // primary key column(s)
        int forumID = GenericParamUtil.getParameterInt(request, "forum");

        permission.ensureCanEditForum(forumID);
        ForumBean forumBean = null;
        Locale locale = I18nUtil.getLocaleInRequest(request);
        try {
            forumBean = DAOFactory.getForumDAO().getForum(forumID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object[] {new Integer(forumID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        request.setAttribute("ForumBean", forumBean);
    }

    public void processUpdate(GenericRequest request, GenericResponse response)
        throws BadInputException, ObjectNotFoundException, DatabaseException, DuplicateKeyException,
        ForeignKeyNotFoundException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();

        // primary key column(s)
        int forumID = GenericParamUtil.getParameterInt(request, "ForumID");

        permission.ensureCanEditForum(forumID);

        MyUtil.saveVNTyperMode(request, response);

        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        // column(s) to update
        int categoryID              = GenericParamUtil.getParameterInt(request, "CategoryID");
        String forumName            = GenericParamUtil.getParameterSafe(request, "ForumName", true);
        forumName = DisableHtmlTagFilter.filter(forumName);
        String forumDesc            = GenericParamUtil.getParameterSafe(request, "ForumDesc", false);
        forumDesc = DisableHtmlTagFilter.filter(forumDesc);
        Timestamp forumModifiedDate = now;
        int forumOrder              = GenericParamUtil.getParameterUnsignedInt(request, "ForumOrder");
        int forumType               = GenericParamUtil.getParameterInt(request, "ForumType");
        int forumFormatOption       = 0;//GenericParamUtil.getParameterInt(request, "ForumFormatOption");
        int forumOption             = 0;//GenericParamUtil.getParameterInt(request, "ForumOption");
        int forumStatus             = GenericParamUtil.getParameterInt(request, "ForumStatus");
        int forumModerationMode     = GenericParamUtil.getParameterInt(request, "ForumModerationMode");

        // check valid
        ForumBean.validateForumType(forumType);
        ForumBean.validateForumFormatOption(forumFormatOption);
        ForumBean.validateForumOption(forumOption);
        ForumBean.validateForumStatus(forumStatus);
        ForumBean.validateForumModerationMode(forumModerationMode);

        DAOFactory.getForumDAO().update(forumID, // primary key
                                  categoryID, forumName, forumDesc,
                                  forumModifiedDate, forumOrder, forumType,
                                  forumFormatOption, forumOption, forumStatus,
                                  forumModerationMode);

        // Now clear the cache
        ForumCache.getInstance().clear();
    }

    /*
     * @todo: check permission
     */
    public void processUpdateForumOrder(GenericRequest request)
        throws BadInputException, DatabaseException,
        ObjectNotFoundException, AuthenticationException, AssertionException {

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();

        Locale locale = I18nUtil.getLocaleInRequest(request);

        // primary key column(s)
        int forumID   = GenericParamUtil.getParameterInt(request, "forum");

        permission.ensureCanEditForum(forumID);

        Timestamp now = DateUtil.getCurrentGMTTimestamp();

        String action = GenericParamUtil.getParameterSafe(request, "action", true);
        if (action.equals("up")) {
            DAOFactory.getForumDAO().decreaseForumOrder(forumID, now);
        } else if (action.equals("down")) {
            DAOFactory.getForumDAO().increaseForumOrder(forumID, now);
        } else {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_update_order.unknown_action", new Object[] {action});
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot update ForumOrder: unknown action: " + action);
        }

        // Now clear the cache
        ForumCache.getInstance().clear();
    }

    public void prepareForumManagement(GenericRequest request)
        throws AssertionException, DatabaseException, AuthenticationException {
        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();
        if ((permission.canEditAnyForum() == false) && (permission.canAddForum() == false)) {
            permission.ensureCanEditAnyForum(); // is this the correct permission
            permission.ensureCanAddForum();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -