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

📄 threadwebhandler.java

📁 easy to use, easy to setup bulletin board (forum)
💻 JAVA
字号:
/*
 * Copyright (C) 2002 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 net.myvietnam.mvnplugin.mvnforum.user;

import javax.servlet.http.*;
import java.sql.*;
import java.util.Collection;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.ParamUtil;
import net.myvietnam.mvnplugin.mvnforum.MVNForumConfig;
import net.myvietnam.mvnplugin.mvnforum.MyUtil;
import net.myvietnam.mvnplugin.mvnforum.db.ThreadBean;
import net.myvietnam.mvnplugin.mvnforum.auth.*;

class ThreadWebHandler {

    private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();

    ThreadWebHandler() {
    }

    public void prepareList_limit(HttpServletRequest request)
        throws BadInputException, DatabaseException, AssertionException, AuthenticationException {

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

        int forumID = ParamUtil.getParameterInt(request, "forum");
        permission.ensureCanReadPost(forumID);

        int offset  = 0;
        int rows    = MVNForumConfig.ROWS_IN_THREADS;

        try {
            offset = ParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException ex) {}

        try {
            rows = ParamUtil.getParameterInt(request, "rows");
        } catch (BadInputException ex) {}

        int totalThreads = ThreadWebHelper.getNumberOfThreads_inForum(forumID);
        if (offset > totalThreads) {
            throw new BadInputException("The offset is not allowed to be greater than total rows.");
        }

        Collection beans = ThreadWebHelper.getThreads_inForum_limit(forumID, offset, rows);

        /** @todo: MVNForumConfig.ROWS_IN_THREADS or rows ??? */
        MyUtil.prepareNavigate(request, offset, beans.size(), totalThreads, MVNForumConfig.ROWS_IN_THREADS);

        int totalPosts = PostWebHelper.getNumberOfPosts_inForum(forumID);

        request.setAttribute("ThreadBeans", beans);
        request.setAttribute("TotalThreads", new Integer(totalThreads));
        request.setAttribute("TotalPosts", new Integer(totalPosts));
    }

    public void prepareListRecentThreads_limit(HttpServletRequest request)
        throws DatabaseException, AssertionException, BadInputException, AuthenticationException {

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

        int offset = 0;
        try {
            offset = ParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }

        int totalPosts  = PostWebHelper.getNumberOfPosts();
        int totalThreads = ThreadWebHelper.getNumberOfThreads();
        if (offset > totalThreads) {
            throw new BadInputException("The offset is not allowed to be greater than total rows.");
        }

        Collection threadBeans = ThreadWebHelper.getThreads_limit(offset, MVNForumConfig.ROWS_IN_RECENT_THREADS);

        MyUtil.prepareNavigate(request, offset, threadBeans.size(), totalThreads, MVNForumConfig.ROWS_IN_RECENT_THREADS);

        request.setAttribute("ThreadBeans", threadBeans);
        request.setAttribute("TotalThreads", new Integer(totalThreads));
        request.setAttribute("TotalPosts", new Integer(totalPosts));
    }

}

⌨️ 快捷键说明

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