~ubuntu-branches/ubuntu/lucid/commons-httpclient/lucid

« back to all changes in this revision

Viewing changes to src/test/org/apache/commons/httpclient/server/ErrorResponse.java

  • Committer: Bazaar Package Importer
  • Author(s): Barry Hawkins
  • Date: 2005-11-25 13:12:23 UTC
  • Revision ID: james.westby@ubuntu.com-20051125131223-2g7eyo21pqgrohpo
Tags: upstream-2.0.2
ImportĀ upstreamĀ versionĀ 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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 $
 
3
 * $Revision: 1.1.2.2 $
 
4
 * $Date: 2004/02/22 18:21:18 $
 
5
 *
 
6
 * ====================================================================
 
7
 *
 
8
 *  Copyright 1999-2004 The Apache Software Foundation
 
9
 *
 
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
 
13
 *
 
14
 *      http://www.apache.org/licenses/LICENSE-2.0
 
15
 *
 
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
 * ====================================================================
 
22
 *
 
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/>.
 
27
 *
 
28
 * [Additional notices, if required by prior licensing conditions]
 
29
 *
 
30
 */
 
31
 
 
32
package org.apache.commons.httpclient.server;
 
33
 
 
34
import java.util.HashMap;
 
35
 
 
36
import org.apache.commons.httpclient.HttpStatus;
 
37
 
 
38
/**
 
39
 * Default error responses.
 
40
 * 
 
41
 * @author Christian Kohlschuetter
 
42
 */
 
43
public class ErrorResponse {
 
44
    private static ErrorResponse instance = null;
 
45
    public static synchronized ErrorResponse getInstance() {
 
46
        if(instance == null) {
 
47
            instance = new ErrorResponse();
 
48
        }
 
49
        return instance;
 
50
    }
 
51
    
 
52
    private final HashMap responses = new HashMap();
 
53
    
 
54
    private ErrorResponse() {
 
55
    }
 
56
    
 
57
    public void setResponse(int statusCode, GenericResponse r) {
 
58
        Integer code = new Integer(statusCode);
 
59
        responses.put(code, r);
 
60
    }
 
61
    
 
62
    public GenericResponse getResponse(int statusCode) {
 
63
        Integer code = new Integer(statusCode);
 
64
        GenericResponse r = (GenericResponse)responses.get(code);
 
65
        if(r == null) {
 
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"
 
69
                + "<html>\n<head>"
 
70
                + "<title>"+text+"</title>"
 
71
                + "</head>\n<body>"
 
72
                + "<h1>"+text+"</h1></body>\n</html>\n",
 
73
            "text/html");
 
74
            
 
75
            responses.put(code, r);
 
76
        }
 
77
        return r;
 
78
    }
 
79
}