2
* $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/server/ErrorResponse.java,v 1.1.2.2 2004/02/22 18:21:18 olegk Exp $
4
* $Date: 2004/02/22 18:21:18 $
6
* ====================================================================
8
* Copyright 1999-2004 The Apache Software Foundation
10
* Licensed under the Apache License, Version 2.0 (the "License");
11
* you may not use this file except in compliance with the License.
12
* You may obtain a copy of the License at
14
* http://www.apache.org/licenses/LICENSE-2.0
16
* Unless required by applicable law or agreed to in writing, software
17
* distributed under the License is distributed on an "AS IS" BASIS,
18
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
* See the License for the specific language governing permissions and
20
* limitations under the License.
21
* ====================================================================
23
* This software consists of voluntary contributions made by many
24
* individuals on behalf of the Apache Software Foundation. For more
25
* information on the Apache Software Foundation, please see
26
* <http://www.apache.org/>.
28
* [Additional notices, if required by prior licensing conditions]
32
package org.apache.commons.httpclient.server;
34
import java.util.HashMap;
36
import org.apache.commons.httpclient.HttpStatus;
39
* Default error responses.
41
* @author Christian Kohlschuetter
43
public class ErrorResponse {
44
private static ErrorResponse instance = null;
45
public static synchronized ErrorResponse getInstance() {
46
if(instance == null) {
47
instance = new ErrorResponse();
52
private final HashMap responses = new HashMap();
54
private ErrorResponse() {
57
public void setResponse(int statusCode, GenericResponse r) {
58
Integer code = new Integer(statusCode);
59
responses.put(code, r);
62
public GenericResponse getResponse(int statusCode) {
63
Integer code = new Integer(statusCode);
64
GenericResponse r = (GenericResponse)responses.get(code);
66
String text = statusCode+" "+HttpStatus.getStatusText(statusCode);
67
r = new GenericResponse("HTTP/1.0 "+text,
68
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
70
+ "<title>"+text+"</title>"
72
+ "<h1>"+text+"</h1></body>\n</html>\n",
75
responses.put(code, r);