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

📄 postwebhandler.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/PostWebHandler.java,v 1.78 2006/04/14 17:05:27 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.78 $
 * $Date: 2006/04/14 17:05:27 $
 *
 * ====================================================================
 *
 * 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.user;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;

import com.mvnforum.*;
import com.mvnforum.auth.*;
import com.mvnforum.common.StatisticsUtil;
import com.mvnforum.db.*;
import com.mvnforum.search.post.*;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
import net.myvietnam.mvncore.interceptor.InterceptorService;
import net.myvietnam.mvncore.security.FloodControl;
import net.myvietnam.mvncore.util.*;
import net.myvietnam.mvncore.web.GenericRequest;
import net.myvietnam.mvncore.web.GenericResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class PostWebHandler {

    private static Log log = LogFactory.getLog(PostWebHandler.class);

    private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();

    public PostWebHandler() {
    }

    /**
     * This method is for addpost page
     */
    public void prepareAdd(GenericRequest request, GenericResponse response)
        throws ObjectNotFoundException, DatabaseException, BadInputException, AuthenticationException, AssertionException {

        Locale locale = I18nUtil.getLocaleInRequest(request);

        if (MVNForumConfig.getEnableNewPost() == false) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_create_new_post.new_post_is_disabled");
            throw new AssertionException(localizedMessage);
            //throw new AssertionException("Cannot create new post because NEW_POST feature is disabled by administrator.");
        }

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

        if (MVNForumConfig.isGuestUserInDatabase() == false) {
            permission.ensureIsAuthenticated();
        }

        // we set this action attribute first because the return below can make method return prematurely
        request.setAttribute("action", "addnew");

        int parentPostID    = 0;
        try {
            // neu co parent thi` khong co forum !!!
            parentPostID = GenericParamUtil.getParameterInt(request, "parent");
        } catch (Exception ex) {
            // do nothing
            // NOTE: we cannot return here since user can have a parameter parent = 0
        }

        if (parentPostID == 0) {// new thread
            int forumID = GenericParamUtil.getParameterInt(request, "forum");

            ForumBean forumBean = null;
            try {
                forumBean = ForumCache.getInstance().getBean(forumID);
            } catch (ObjectNotFoundException e) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object[] {new Integer(forumID)});
                throw new ObjectNotFoundException(localizedMessage);
            }
            forumBean.ensureNotDisabledForum();
            forumBean.ensureNotClosedForum();
            forumBean.ensureNotLockedForum();

            permission.ensureCanAddThread(forumID);
        } else {// reply to a post
            // this is a parent post
            PostBean postBean = null;
            try {
                postBean = DAOFactory.getPostDAO().getPost(parentPostID);// can throw DatabaseException
            } catch (ObjectNotFoundException ex) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.postid_not_exists", new Object[] {new Integer(parentPostID)});
                throw new ObjectNotFoundException(localizedMessage);
            }

            // check permission
            int forumID  = postBean.getForumID();

            ForumBean forumBean = null;
            try {
                forumBean = ForumCache.getInstance().getBean(forumID);
            } catch (ObjectNotFoundException e) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object[] {new Integer(forumID)});
                throw new ObjectNotFoundException(localizedMessage);
            }
            forumBean.ensureNotDisabledForum();
            forumBean.ensureNotClosedForum();
            forumBean.ensureNotLockedForum();

            permission.ensureCanAddPost(forumID);

            // now we prepare to list lastest post in the thread
            int threadID = postBean.getThreadID();

            // now check if thread is closed or locked, if it is, then cannot reply to a post
            ThreadBean threadBean = null;
            try {
                threadBean = DAOFactory.getThreadDAO().getThread(threadID);
            } catch ( ObjectNotFoundException ex ) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.threadid_not_exists", new Object[] {new Integer(threadID)});
                throw new ObjectNotFoundException(localizedMessage);
            }

            threadBean.ensureStatusCanReply();

            Collection postBeans = DAOFactory.getPostDAO().getLastEnablePosts_inThread_limit(threadID, MVNForumConfig.ROWS_IN_LAST_REPLIES);
            request.setAttribute("ParentPostBean", postBean);
            request.setAttribute("PostBeans", postBeans);
        }

        boolean isPreviewing = GenericParamUtil.getParameterBoolean(request, "preview");
        if (isPreviewing) {
            MyUtil.saveVNTyperMode(request, response);

            // Check if user enter some text or not
            GenericParamUtil.getParameter(request, "PostTopic", true);
            GenericParamUtil.getParameter(request, "message", true);// use message instead of MessageBody
            MemberBean memberBean = MemberCache.getInstance().getMember_forPublic(onlineUser.getMemberID());
            request.setAttribute("MemberBean", memberBean);
        }
    }

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

        Locale locale = I18nUtil.getLocaleInRequest(request);
        if (MVNForumConfig.getEnableNewPost() == false) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.cannot_create_new_post.new_post_is_disabled");
            throw new AssertionException(localizedMessage);
            //throw new AssertionException("Cannot create new post because NEW_POST feature is disabled by administrator.");
        }

        String currentIP = request.getRemoteAddr();
        try {
            FloodControl.ensureNotReachMaximum(MVNForumGlobal.FLOOD_ID_NEW_POST, currentIP);
        } catch (FloodException fe) {
            //throw new FloodException("You have reached the maximum number of the post adding actions for this page. Please try this page later. This is to prevent forum from being flooded.");
            Integer maxPosts = new Integer(FloodControl.getActionsPerHour(MVNForumGlobal.FLOOD_ID_NEW_POST));
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.FloodException.add_post_too_many_times", new Object[] {maxPosts});
            throw new FloodException(localizedMessage);
        }
        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        MVNForumPermission permission = onlineUser.getPermission();

        MyUtil.saveVNTyperMode(request, response);

        int memberID      = onlineUser.getMemberID();
        String memberName = onlineUser.getMemberName();

        Timestamp now     = DateUtil.getCurrentGMTTimestamp();

        int parentPostID  = GenericParamUtil.getParameterInt(request, "parent");

        boolean attachMore  = GenericParamUtil.getParameterBoolean(request, "AttachMore");
        boolean addFavoriteThread = GenericParamUtil.getParameterBoolean(request, "AddFavoriteParentThread");
        boolean addWatchThread    = GenericParamUtil.getParameterBoolean(request, "AddWatchParentThread");

        String postTopic = GenericParamUtil.getParameter(request, "PostTopic", true);
        postTopic = DisableHtmlTagFilter.filter(postTopic);// always disable HTML
        postTopic = InterceptorService.getInstance().validateContent(postTopic);

        String postBody = GenericParamUtil.getParameter(request, "message", true); // use message instead of MessageBody
        postBody = DisableHtmlTagFilter.filter(postBody);// always disable HTML
        postBody = InterceptorService.getInstance().validateContent(postBody);

        String postIcon = GenericParamUtil.getParameter(request, "PostIcon");
        postIcon = DisableHtmlTagFilter.filter(postIcon);// always disable HTML

        int forumID = 0;
        int threadID= 0;
        boolean isPendingThread = false;
        boolean isForumModerator = false;
        if (parentPostID == 0) {// new thread

            forumID = GenericParamUtil.getParameterInt(request, "forum");
            ForumBean forumBean = null;
            try {
                forumBean = ForumCache.getInstance().getBean(forumID);
            } catch (ObjectNotFoundException e) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.forumid_not_exists", new Object[] {new Integer(forumID)});
                throw new ObjectNotFoundException(localizedMessage);
            }
            forumBean.ensureNotDisabledForum();
            forumBean.ensureNotClosedForum();
            forumBean.ensureNotLockedForum();

            // check permission
            isForumModerator = permission.canModerateThread(forumID);
            permission.ensureCanAddThread(forumID);

            String lastPostMemberName = memberName;

            int threadType = GenericParamUtil.getParameterUnsignedInt(request, "ThreadType", ThreadBean.THREAD_TYPE_DEFAULT);
            if ( threadType > ThreadBean.THREAD_TYPE_GLOBAL_ANNOUNCEMENT /* 3 */) {
                //threadType = 0;

⌨️ 快捷键说明

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