?? forumuserservlet.java
字號:
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/ForumUserServlet.java,v 1.21.2.5 2006/07/12 07:43:28 phuongpdd Exp $
* $Author: phuongpdd $
* $Revision: 1.21.2.5 $
* $Date: 2006/07/12 07:43:28 $
*
* ====================================================================
*
* 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 javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import com.mvnforum.*;
import com.mvnforum.auth.*;
import com.mvnforum.db.WatchBean;
import net.myvietnam.mvncore.db.DBUtils;
import net.myvietnam.mvncore.filter.IPFilter;
import net.myvietnam.mvncore.filter.UserAgentFilter;
import net.myvietnam.mvncore.util.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class ForumUserServlet extends HttpServlet {
private static Log log = LogFactory.getLog(ForumUserServlet.class);
private UserModuleProcessor userModuleProcessor = null;
private static int count = 0;
/**Initialize global variables*/
public void init() throws ServletException {
/*
if (MVNForumConfig.isShouldRun() == false) {
throw new ServletException("Cannot init system. Reason = " + MVNForumConfig.getReason());
}*/
//log.debug(" USING LOGGING::::" + log.getClass());
userModuleProcessor = new UserModuleProcessor(this);
// Check if the servlet is in specs Servlet 2.3 or later
if (MVNForumConfig.isShouldRun()) {
ServletContext context = getServletContext();
int majorVersion = context.getMajorVersion();
int mimorVersion = context.getMinorVersion();
if ((majorVersion < 2) ||
((majorVersion == 2) && (mimorVersion < 3))) {
MVNForumConfig.setShouldRun(false, "mvnForum requires Servlet 2.3 or later. Please upgrade your Servlet Container.");
}
}
// schedule the WatchTask
if (MVNForumConfig.getEnableWatch()) {
if (MVNForumConfig.isShouldRun()) {
log.info("Schedule the WatchTask.");
if (MVNForumConfig.getDefaultWatchOption() == WatchBean.WATCH_OPTION_LIVE) {
// The default watch is LIVE, so the timer is called more often (5 minutes)
WatchTask.getInstance().schedule(DateUtil.MINUTE, DateUtil.MINUTE * 5);
} else {
// Other options, we only check the watch hourly
WatchTask.getInstance().schedule(DateUtil.MINUTE, DateUtil.HOUR);
}
}
} else {
log.info("Watch is disabled. Do not schedule the WatchTask.");
}
// schedule the DeleteOrphanPmAttachmentTask
if (MVNForumConfig.isShouldRun()) {
log.info("Schedule the DeleteOrphanPmAttachmentTask.");
if (MVNForumConfig.getEnableMessageAttachment()) {
//Repeated task
DeleteOrphanPmAttachmentTask.getInstance().schedule(DateUtil.MINUTE, DateUtil.HOUR);
} else {
// Try to delete the PmAttachment at least once time
DeleteOrphanPmAttachmentTask.getInstance().schedule(DateUtil.MINUTE);
}
}
log.info("<<---- ForumUserServlet has been inited. Detailed info: " + MVNForumInfo.getProductVersion() + " (Build: " + MVNForumInfo.getProductReleaseDate() + ") ---->>");
}
/**Process the HTTP Get request*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}
/**Process the HTTP Post request*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}
public void process(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
if (MVNForumConfig.isShouldRun() == false) {
String error = "Cannot init system. Reason : " + MVNForumConfig.getReason();
request.setAttribute("fatal_error_message", error);
getServletContext().getRequestDispatcher("/mvnplugin/mvnforum/mvnfatalerror.jsp").forward(request, response);
return;
}
long startTime = 0;
if (log.isDebugEnabled()) {
startTime = System.currentTimeMillis();
}
count++;
try {
if (IPFilter.filter(request) == false) {
getServletContext().getRequestDispatcher("/mvnplugin/mvnforum/404.jsp").forward(request, response);
return;
}
if (UserAgentFilter.filter(request) == false) {
getServletContext().getRequestDispatcher("/mvnplugin/mvnforum/404.jsp").forward(request, response);
return;
}
//request.setCharacterEncoding("utf-8");
String responseURI = null;
responseURI = ManagerFactory.getRequestProcessor().preLogin(request, response);
// This will make sure that the user information is put in
// the request.
OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();
OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
OnlineUserAction action = onlineUser.getOnlineUserAction();
if (action.getRemoteAddr().equals(request.getRemoteAddr()) == false) {
request.getRequestDispatcher("/mvnplugin/mvnforum/invalidsession.html").forward(request, response);
return;
}
// check the module is on. Otherwise, go to message inform that
// the module is Off now. Please access later when the admin change mode to on
if (MVNForumConfig.getShouldShowUserArea() == false) {
if (!onlineUser.getPermission().canAdminSystem()) {
request.getRequestDispatcher("/mvnplugin/mvnforum/turnoff.html").forward(request, response);
return;
}
}
//Config.set(request, Config.FMT_FALLBACK_LOCALE, "en");
String localeName = ParamUtil.getParameter(request, MVNForumConfig.getLocaleParameterName());
if (MVNForumConfig.supportLocale(localeName)) {
onlineUser.setLocaleName(localeName);
}
I18nUtil.setLocaleInRequest(request, onlineUser.getLocale());
// save Vietnamese typer mode if exists one
//MyUtil.saveVNTyperMode(request, response);
if (null == responseURI) {
responseURI = ManagerFactory.getRequestProcessor().preProcess(request, response);
}
if (null == responseURI) {
// this method should not throw Exception (it must catch all Exceptions)
responseURI = userModuleProcessor.process(request, response);
}
responseURI = ManagerFactory.getRequestProcessor().postProcess(request, response, responseURI);
if ((null != responseURI) && !response.isCommitted()) {
if (responseURI.startsWith("http://") || responseURI.startsWith("https://")) {
response.sendRedirect(responseURI);
} else {
if (responseURI.endsWith(".jsp")) {
request.getRequestDispatcher(responseURI).forward(request, response);
} else {
response.sendRedirect(request.getContextPath() + responseURI);
}
}
}
} catch (Exception e) {
// so it should never go here
log.error("Error assertion", e);
} finally {
if (log.isDebugEnabled()) {
long processTime = System.currentTimeMillis() - startTime;
log.debug("ForumUserServlet processed " + count + " times. Took " + processTime + " miliseconds.\n");
}
}
}// process
/**
* Clean up resources
*/
public void destroy() {
// This code will release all connections currently pooled.
// The next call to #getConnection will recreate the pool.
DBUtils.closeAllConnections();
//finally, cancel the TimerUtil
TimerUtil.getInstance().cancel();
log.info("<<---- ForumUserServlet has been destroyed. ---->>");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -