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

📄 usermoduleprocessor.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.*;
import javax.servlet.http.*;
import java.io.IOException;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.StringUtil;
import net.myvietnam.mvncore.util.ParamUtil;
import net.myvietnam.mvnplugin.mvnforum.db.*;
import net.myvietnam.mvnplugin.mvnforum.MVNForumConfig;
import net.myvietnam.mvnplugin.mvnforum.URLMap;
import net.myvietnam.mvnplugin.mvnforum.auth.*;

public class UserModuleProcessor {

    private HttpServlet     mainServlet     = null;
    private ServletContext  servletContext  = null;

    private ForumURLMapHandler      urlMapHandler       = new ForumURLMapHandler();
    private ForumWebHandler         forumWebHandler     = new ForumWebHandler();
    private ThreadWebHandler        threadWebHandler    = new ThreadWebHandler();
    private PostWebHandler          postWebHandler      = new PostWebHandler();
    private MemberWebHandler        memberWebHandler    = new MemberWebHandler();
    private OnlineUserManager       onlineUserManager   = OnlineUserManager.getInstance();

    public UserModuleProcessor(HttpServlet servlet) {
        mainServlet     = servlet;
        servletContext  = servlet.getServletContext();
    }

    public void process(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

        long start = System.currentTimeMillis();
        String requestURI = StringUtil.getEmptyStringIfNull(request.getPathInfo());
        String responseURI = null;
        System.out.println("UserModuleProcessor : requestURI  = " + requestURI);

        // step 1: some command need to be processed before we do the URI mapping (of the MODAL)
        // MODAL processing
        try {
            if (requestURI.equals("/index")) {
                forumWebHandler.prepareList(request);//no permission
            } else if (requestURI.equals("/listforums")) {
                forumWebHandler.prepareList(request);//no permission
            } else if (requestURI.equals("/listthreads")) {
                threadWebHandler.prepareList_limit(request);
            } else if (requestURI.equals("/listrecentthreads")) {
                threadWebHandler.prepareListRecentThreads_limit(request);//no permission
            } else if (requestURI.equals("/viewthread")) {
                postWebHandler.listPost_inThread(request);

            } else if (requestURI.equals("/listonlineusers")) {
                request.setAttribute("OnlineUserActions", onlineUserManager.getOnlineUserActions(0/*default*/));// no permission

            /** @todo can Guest new a post */
            } else if (requestURI.equals("/addpost")) {
                postWebHandler.prepareAdd(request);
            } else if (requestURI.equals("/addpostprocess")) {
                postWebHandler.processAdd(request);
            } else if (requestURI.equals("/editpost")) {
                postWebHandler.prepareEdit(request);
            } else if (requestURI.equals("/updatepost")) {
                postWebHandler.processUpdate(request);

            } else if (requestURI.equals("/registermemberprocess")) {
                memberWebHandler.processAdd(request);// no permission
            } else if (requestURI.equals("/viewmember")) {
                memberWebHandler.prepareView_forPublic(request);// no permission
            } else if (requestURI.equals("/listmembers")) {
                memberWebHandler.prepareListMembers_forPublic(request);// no permission
            } else if (requestURI.equals("/editmember")) {
                memberWebHandler.prepareEdit_forCurrentMember(request);
            } else if (requestURI.equals("/updatemember")) {
                memberWebHandler.processUpdate(request);
            } else if (requestURI.equals("/myprofile")) {
                memberWebHandler.prepareView_forCurrentMember(request);
            } else if (requestURI.equals("/changepasswordprocess")) {
                memberWebHandler.processUpdatePassword(request);
            } else if (requestURI.equals("/changeemail")) {
                memberWebHandler.prepareEditEmail(request);
            } else if (requestURI.equals("/changeemailprocess")) {
                memberWebHandler.processUpdateEmail(request);
            } else if (requestURI.equals("/changesignature")) {
                memberWebHandler.prepareEditSignature(request);
            } else if (requestURI.equals("/changesignatureprocess")) {
                memberWebHandler.processUpdateSignature(request);
            } else if (requestURI.equals("/forgotpasswordprocess")) {
                memberWebHandler.forgotPassword(request);//no permission
            } else if (requestURI.equals("/resetpasswordprocess")) {
                memberWebHandler.resetPassword(request);//no permission
            } else if (requestURI.equals("/changeavatar")) {
                memberWebHandler.prepareEditAvatar(request);
            } else if (requestURI.equals("/uploadpicture")) {
                memberWebHandler.uploadPicture(mainServlet.getServletConfig(), request, response);
            } else if (requestURI.equals("/updatepicture")) {
                memberWebHandler.updateMemberAvatar(servletContext, request);
            } else if (requestURI.equals("/loginprocess")) {
                onlineUserManager.processLogin(request);
                String originalRequest = ParamUtil.getAttribute(request.getSession(), "OriginalRequest");
                if (originalRequest.length() > 0) {
                    request.getSession().setAttribute("OriginalRequest", "");
                    responseURI = originalRequest;
                }
            } else if (requestURI.equals("/logout")) {
                onlineUserManager.logout(request);
                request.setAttribute("Reason", "Logout successfully.");
            }
        } catch (AuthenticationException e) {
            // make sure not from login page, we cannot set original request in this situation
            // and also make sure the request's method must be GET to set the OriginalRequest
            if ((e.getReason() == NotLoginException.NOT_LOGIN) && (request.getMethod().equals("GET"))) {
                String url = UserModuleConfig.URL_PATTERN + requestURI + "?" + StringUtil.getEmptyStringIfNull(request.getQueryString());
                request.getSession().setAttribute("OriginalRequest", url);
            }
            requestURI = "/login";
            request.setAttribute("Reason", e.getReasonExplanation());
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Caught an exception in UserModuleProcessor e = " + e.getMessage());
            requestURI = "/error";
            request.getSession().setAttribute("ErrorMessage", StringUtil.getEmptyStringIfNull(e.getMessage()));
        }

        // step 2: map the URI (of the CONTROLLER)
        try {
            // NOTE 1:  there is one situation when responseURI != null (after login successfully for the first time),
            //          but since it will make a NEW request via sendRedirect, so we dont count
            // NOTE 2:  there are 2 situation when requestURI is different from the original requestURI
            //          that is /login and /error, because of this so we must pass the requestURI
            /* @todo Could below the MapHandler ??? */
            Action action = new ActionInUserModule(request, requestURI);// may throw MissingURLMapEntryException
            onlineUserManager.updateOnlineUserAction(request, action);

            // now updateOnlineUserAction is ok, we go ahead
            if (responseURI == null) {
                URLMap map = urlMapHandler.getMap(requestURI, request);
                responseURI = map.getResponse();
            }// if
        } catch (MissingURLMapEntryException e) {
            System.out.println("Exception: missing urlmap entry in forum module.");
            responseURI = "/mvnplugin/mvnforum/user/error.jsp";
            request.getSession().setAttribute("ErrorMessage", e.getMessage());
        } catch (Exception e) {
            // This will catch AuthenticationException, AssertionException, DatabaseException
            // in the method onlineUserManager.updateOnlineUserAction(request, action)
            responseURI = "/mvnplugin/mvnforum/user/error.jsp";
            request.getSession().setAttribute("ErrorMessage", e.getMessage());
        }

        // step 3: forward or dispatch to the VIEW
        long duration = System.currentTimeMillis() - start;
        System.out.println("UserModuleProcessor : responseURI = " + responseURI + ". (" + duration + " ms)\n");

        if (responseURI.endsWith(".jsp")) {
            servletContext.getRequestDispatcher(responseURI).forward(request, response);
        } else {
            response.sendRedirect(ParamUtil.getContextPath() + responseURI);
        }
    }
}

⌨️ 快捷键说明

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