KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > admin > ForumAdminServlet


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/ForumAdminServlet.java,v 1.7 2006/04/14 17:05:25 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.7 $
5  * $Date: 2006/04/14 17:05:25 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Minh Nguyen
39  * @author: Mai Nguyen
40  */

41 package com.mvnforum.admin;
42
43 import java.io.IOException JavaDoc;
44 import javax.servlet.ServletException JavaDoc;
45 import javax.servlet.http.*;
46
47 import org.apache.commons.logging.Log;
48 import org.apache.commons.logging.LogFactory;
49 import com.mvnforum.MVNForumInfo;
50 import net.myvietnam.mvncore.db.DBUtils;
51 import net.myvietnam.mvncore.filter.IPFilter;
52 import net.myvietnam.mvncore.filter.UserAgentFilter;
53 import net.myvietnam.mvncore.util.ParamUtil;
54 import net.myvietnam.mvncore.util.DateUtil;
55
56 public class ForumAdminServlet extends HttpServlet {
57
58     private static Log log = LogFactory.getLog(ForumAdminServlet.class);
59
60     private AdminModuleProcessor adminModuleProcessor = null;
61     private static int count = 0;
62
63     static final long START_TIME = DateUtil.getCurrentGMTTimestamp().getTime();
64
65     public static final long getStartTime() {
66         return START_TIME;
67     }
68     /**Initialize global variables*/
69     public void init() throws ServletException JavaDoc {
70         adminModuleProcessor = new AdminModuleProcessor(this);
71         log.info("<<---- ForumAdminServlet has been inited. Detailed info: " + MVNForumInfo.getProductVersion() + " (Build: " + MVNForumInfo.getProductReleaseDate() + ") ---->>");
72     }
73
74     /**Process the HTTP Get request*/
75     public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException JavaDoc, IOException JavaDoc {
76         process(request, response);
77     }
78
79     /**Process the HTTP Post request*/
80     public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException JavaDoc, IOException JavaDoc {
81         process(request, response);
82     }
83
84     public void process(HttpServletRequest request, HttpServletResponse response)
85         throws IOException JavaDoc, ServletException JavaDoc {
86         long startTime = 0;
87         if (log.isDebugEnabled()) {
88             startTime = System.currentTimeMillis();
89         }
90         count++;
91         try {
92             request.setCharacterEncoding("utf-8");
93             //String requestURI = request.getPathInfo();
94
String JavaDoc responseURI = null;
95
96             if (IPFilter.filter(request) == false) {
97                 getServletContext().getRequestDispatcher("/mvnplugin/mvnforum/404.jsp").forward(request, response);
98                 return;
99             }
100             if (UserAgentFilter.filter(request) == false) {
101                 getServletContext().getRequestDispatcher("/mvnplugin/mvnforum/404.jsp").forward(request, response);
102                 return;
103             }
104
105             // this method should not throw Exception (it must catch all Exceptions)
106
responseURI = adminModuleProcessor.process(request, response);
107             //this IF ensures we don't try to redirect if already committed output
108
if ( (null!=responseURI) && (!response.isCommitted()) ) {
109                if (responseURI.endsWith(".jsp")) {
110                   request.getRequestDispatcher(responseURI).forward(request, response);
111                } else {
112                   response.sendRedirect(ParamUtil.getContextPath() + responseURI);
113                }
114             }
115         } catch (Exception JavaDoc e) {
116             // so it should never go here
117
log.error("Error assertion", e);
118         } finally {
119             if (log.isDebugEnabled()) {
120                 long processTime = System.currentTimeMillis() - startTime;
121                 log.debug("ForumAdminServlet processed " + count + " times. Took " + processTime + " miliseconds.\n");
122             }
123         }
124     }// process
125

126     /**
127      * Clean up resources
128      */

129     public void destroy() {
130         // This code will release all connections currently pooled.
131
// The next call to #getConnection will recreate the pool.
132
DBUtils.closeAllConnections();
133
134         log.info("<<---- ForumAdminServlet has been destroyed. ---->>");
135     }
136 }
137
Popular Tags