KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > main > OpenCmsServletErrorHandler


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/main/OpenCmsServletErrorHandler.java,v $
3  * Date : $Date: 2006/03/27 14:52:27 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.main;
33
34 import org.opencms.jsp.util.CmsJspStatusBean;
35 import org.opencms.util.CmsStringUtil;
36
37 import java.io.IOException JavaDoc;
38
39 import javax.servlet.ServletConfig JavaDoc;
40 import javax.servlet.ServletException JavaDoc;
41 import javax.servlet.http.HttpServletRequest JavaDoc;
42 import javax.servlet.http.HttpServletResponse JavaDoc;
43
44 /**
45  * This the error handler servlet of the OpenCms system.<p>
46  *
47  * This almost 1:1 extends the "standard" {@link org.opencms.main.OpenCmsServlet}.
48  * By default, all errors are handled by this servlet, which is controlled by the
49  * setting in the shipped <code>web.xml</code>.<p>
50  *
51  * This servlet is required because certain servlet containers (eg. BEA Weblogic)
52  * can not handler the error with the same servlet that produced the error.<p>
53  *
54  * @author Alexander Kandzior
55  *
56  * @version $Revision: 1.2 $
57  *
58  * @since 6.2.0
59  *
60  * @see org.opencms.main.OpenCmsServlet
61  * @see org.opencms.staticexport.CmsStaticExportManager
62  */

63 public class OpenCmsServletErrorHandler extends OpenCmsServlet {
64
65     /** Serial version UID required for safe serialization. */
66     private static final long serialVersionUID = 5316004893684482816L;
67
68     /**
69      * OpenCms servlet main request handling method.<p>
70      *
71      * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
72      */

73     public void doGet(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) throws IOException JavaDoc, ServletException JavaDoc {
74
75         // chech the error status
76
Integer JavaDoc errorStatus = (Integer JavaDoc)req.getAttribute(CmsJspStatusBean.ERROR_STATUS_CODE);
77         if (errorStatus != null) {
78             // only use super method if an error status code is set
79
if (OpenCmsCore.getInstance().getRunLevel() > OpenCms.RUNLEVEL_3_SHELL_ACCESS) {
80                 // use super method if servlet runlevel is available
81
super.doGet(req, res);
82             } else {
83                 // otherwise display a simple error page
84
String JavaDoc errorMessage = (String JavaDoc)req.getAttribute(CmsJspStatusBean.ERROR_MESSAGE);
85                 if (CmsStringUtil.isEmptyOrWhitespaceOnly(errorMessage)) {
86                     errorMessage = "";
87                 }
88                 String JavaDoc output = "<html><body>"
89                     + CmsStringUtil.escapeHtml(Messages.get().getBundle().key(
90                         Messages.ERR_OPENCMS_NOT_INITIALIZED_2,
91                         errorStatus,
92                         errorMessage))
93                     + "</body></html>";
94                 res.setStatus(errorStatus.intValue());
95                 res.getWriter().println(output);
96             }
97         } else {
98             // no status code set, this is an invalid request
99
res.sendError(HttpServletResponse.SC_FORBIDDEN);
100         }
101     }
102
103     /**
104      * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
105      */

106     public void init(ServletConfig JavaDoc config) {
107
108         // override super class to avoid default initialization
109
}
110 }
Popular Tags