KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > webconnector > ErrorPageHandler


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.webconnector;
20
21 import java.io.IOException JavaDoc;
22 import java.io.Writer JavaDoc;
23 import java.net.URLDecoder JavaDoc;
24
25 import org.mortbay.http.HttpRequest;
26 import org.mortbay.util.StringUtil;
27
28
29 public class ErrorPageHandler extends org.mortbay.http.handler.ErrorPageHandler
30 {
31     protected void writeErrorPage(HttpRequest request, Writer JavaDoc writer, int code, String JavaDoc message)
32     throws IOException JavaDoc
33     {
34         if (message != null)
35         {
36             message=URLDecoder.decode(message,"UTF-8");
37             message= StringUtil.replace(message, "<", "&lt;");
38             message= StringUtil.replace(message, ">", "&gt;");
39         }
40         String JavaDoc uri= request.getPath();
41         uri= StringUtil.replace(uri, "<", "&lt;");
42         uri= StringUtil.replace(uri, ">", "&gt;");
43         
44         writer.write("<html>\n<head>\n<title>Error ");
45         writer.write(Integer.toString(code));
46         writer.write(' ');
47         writer.write(message);
48         writer.write("</title>\n");
49         writer.write("<link type='text/css' rel='stylesheet' HREF='/general.css'/>\n");
50         writer.write("</head>\n<body>\n");
51         if(code >= 500)
52             writer.write("<div class='error'>\n");
53         else
54             writer.write("<div class='warning'>\n");
55         writer.write("<h1>HTTP ERROR: ");
56         writer.write(Integer.toString(code));
57         writer.write("</h1>\n");
58         writer.write("<pre>");
59         writer.write(message);
60         writer.write("</pre>\n");
61         writer.write("<p>RequestURI=");
62         writer.write(uri);
63         writer.write("</p>\n</div>");
64         writer.write("\n</body>\n</html>\n");
65     }
66 }
Popular Tags