2
* $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/httpcore/src/main/java/org/apache/http/impl/EnglishReasonPhraseCatalog.java $
4
* $Date: 2009-02-14 17:59:14 +0100 (Sat, 14 Feb 2009) $
6
* ====================================================================
7
* Licensed to the Apache Software Foundation (ASF) under one
8
* or more contributor license agreements. See the NOTICE file
9
* distributed with this work for additional information
10
* regarding copyright ownership. The ASF licenses this file
11
* to you under the Apache License, Version 2.0 (the
12
* "License"); you may not use this file except in compliance
13
* with the License. You may obtain a copy of the License at
15
* http://www.apache.org/licenses/LICENSE-2.0
17
* Unless required by applicable law or agreed to in writing,
18
* software distributed under the License is distributed on an
19
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20
* KIND, either express or implied. See the License for the
21
* specific language governing permissions and limitations
23
* ====================================================================
25
* This software consists of voluntary contributions made by many
26
* individuals on behalf of the Apache Software Foundation. For more
27
* information on the Apache Software Foundation, please see
28
* <http://www.apache.org/>.
32
package org.apache.http.impl;
34
import java.util.Locale;
36
import org.apache.http.HttpStatus;
37
import org.apache.http.ReasonPhraseCatalog;
41
* English reason phrases for HTTP status codes.
42
* All status codes defined in RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1), and
43
* RFC2518 (WebDAV) are supported.
46
* @version $Revision: 744524 $
50
public class EnglishReasonPhraseCatalog implements ReasonPhraseCatalog {
52
// static array with english reason phrases defined below
55
* The default instance of this catalog.
56
* This catalog is thread safe, so there typically
57
* is no need to create other instances.
59
public final static EnglishReasonPhraseCatalog INSTANCE =
60
new EnglishReasonPhraseCatalog();
64
* Restricted default constructor, for derived classes.
65
* If you need an instance of this class, use {@link #INSTANCE INSTANCE}.
67
protected EnglishReasonPhraseCatalog() {
73
* Obtains the reason phrase for a status code.
75
* @param status the status code, in the range 100-599
78
* @return the reason phrase, or <code>null</code>
80
public String getReason(int status, Locale loc) {
81
if ((status < 100) || (status >= 600)) {
82
throw new IllegalArgumentException
83
("Unknown category for status code " + status + ".");
86
final int category = status / 100;
87
final int subcode = status - 100*category;
90
if (REASON_PHRASES[category].length > subcode)
91
reason = REASON_PHRASES[category][subcode];
97
/** Reason phrases lookup table. */
98
private static final String[][] REASON_PHRASES = new String[][]{
100
new String[3], // 1xx
101
new String[8], // 2xx
102
new String[8], // 3xx
103
new String[25], // 4xx
110
* Stores the given reason phrase, by status code.
111
* Helper method to initialize the static lookup table.
113
* @param status the status code for which to define the phrase
114
* @param reason the reason phrase for this status code
116
private static void setReason(int status, String reason) {
117
final int category = status / 100;
118
final int subcode = status - 100*category;
119
REASON_PHRASES[category][subcode] = reason;
123
// ----------------------------------------------------- Static Initializer
125
/** Set up status code to "reason phrase" map. */
127
// HTTP 1.0 Server status codes -- see RFC 1945
128
setReason(HttpStatus.SC_OK,
130
setReason(HttpStatus.SC_CREATED,
132
setReason(HttpStatus.SC_ACCEPTED,
134
setReason(HttpStatus.SC_NO_CONTENT,
136
setReason(HttpStatus.SC_MOVED_PERMANENTLY,
137
"Moved Permanently");
138
setReason(HttpStatus.SC_MOVED_TEMPORARILY,
139
"Moved Temporarily");
140
setReason(HttpStatus.SC_NOT_MODIFIED,
142
setReason(HttpStatus.SC_BAD_REQUEST,
144
setReason(HttpStatus.SC_UNAUTHORIZED,
146
setReason(HttpStatus.SC_FORBIDDEN,
148
setReason(HttpStatus.SC_NOT_FOUND,
150
setReason(HttpStatus.SC_INTERNAL_SERVER_ERROR,
151
"Internal Server Error");
152
setReason(HttpStatus.SC_NOT_IMPLEMENTED,
154
setReason(HttpStatus.SC_BAD_GATEWAY,
156
setReason(HttpStatus.SC_SERVICE_UNAVAILABLE,
157
"Service Unavailable");
159
// HTTP 1.1 Server status codes -- see RFC 2048
160
setReason(HttpStatus.SC_CONTINUE,
162
setReason(HttpStatus.SC_TEMPORARY_REDIRECT,
163
"Temporary Redirect");
164
setReason(HttpStatus.SC_METHOD_NOT_ALLOWED,
165
"Method Not Allowed");
166
setReason(HttpStatus.SC_CONFLICT,
168
setReason(HttpStatus.SC_PRECONDITION_FAILED,
169
"Precondition Failed");
170
setReason(HttpStatus.SC_REQUEST_TOO_LONG,
172
setReason(HttpStatus.SC_REQUEST_URI_TOO_LONG,
173
"Request-URI Too Long");
174
setReason(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE,
175
"Unsupported Media Type");
176
setReason(HttpStatus.SC_MULTIPLE_CHOICES,
178
setReason(HttpStatus.SC_SEE_OTHER,
180
setReason(HttpStatus.SC_USE_PROXY,
182
setReason(HttpStatus.SC_PAYMENT_REQUIRED,
184
setReason(HttpStatus.SC_NOT_ACCEPTABLE,
186
setReason(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED,
187
"Proxy Authentication Required");
188
setReason(HttpStatus.SC_REQUEST_TIMEOUT,
191
setReason(HttpStatus.SC_SWITCHING_PROTOCOLS,
192
"Switching Protocols");
193
setReason(HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION,
194
"Non Authoritative Information");
195
setReason(HttpStatus.SC_RESET_CONTENT,
197
setReason(HttpStatus.SC_PARTIAL_CONTENT,
199
setReason(HttpStatus.SC_GATEWAY_TIMEOUT,
201
setReason(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED,
202
"Http Version Not Supported");
203
setReason(HttpStatus.SC_GONE,
205
setReason(HttpStatus.SC_LENGTH_REQUIRED,
207
setReason(HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE,
208
"Requested Range Not Satisfiable");
209
setReason(HttpStatus.SC_EXPECTATION_FAILED,
210
"Expectation Failed");
212
// WebDAV Server-specific status codes
213
setReason(HttpStatus.SC_PROCESSING,
215
setReason(HttpStatus.SC_MULTI_STATUS,
217
setReason(HttpStatus.SC_UNPROCESSABLE_ENTITY,
218
"Unprocessable Entity");
219
setReason(HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE,
220
"Insufficient Space On Resource");
221
setReason(HttpStatus.SC_METHOD_FAILURE,
223
setReason(HttpStatus.SC_LOCKED,
225
setReason(HttpStatus.SC_INSUFFICIENT_STORAGE,
226
"Insufficient Storage");
227
setReason(HttpStatus.SC_FAILED_DEPENDENCY,
228
"Failed Dependency");