1 31 32 package org.apache.commons.httpclient.server; 33 34 import java.util.HashMap ; 35 36 import org.apache.commons.httpclient.HttpStatus; 37 38 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 } 80 | Popular Tags |