1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/impl/EnglishReasonPhraseCatalog.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,224 @@ 1.4 +/* 1.5 + * ==================================================================== 1.6 + * Licensed to the Apache Software Foundation (ASF) under one 1.7 + * or more contributor license agreements. See the NOTICE file 1.8 + * distributed with this work for additional information 1.9 + * regarding copyright ownership. The ASF licenses this file 1.10 + * to you under the Apache License, Version 2.0 (the 1.11 + * "License"); you may not use this file except in compliance 1.12 + * with the License. You may obtain a copy of the License at 1.13 + * 1.14 + * http://www.apache.org/licenses/LICENSE-2.0 1.15 + * 1.16 + * Unless required by applicable law or agreed to in writing, 1.17 + * software distributed under the License is distributed on an 1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1.19 + * KIND, either express or implied. See the License for the 1.20 + * specific language governing permissions and limitations 1.21 + * under the License. 1.22 + * ==================================================================== 1.23 + * 1.24 + * This software consists of voluntary contributions made by many 1.25 + * individuals on behalf of the Apache Software Foundation. For more 1.26 + * information on the Apache Software Foundation, please see 1.27 + * <http://www.apache.org/>. 1.28 + * 1.29 + */ 1.30 + 1.31 +package ch.boye.httpclientandroidlib.impl; 1.32 + 1.33 +import java.util.Locale; 1.34 + 1.35 +import ch.boye.httpclientandroidlib.HttpStatus; 1.36 +import ch.boye.httpclientandroidlib.ReasonPhraseCatalog; 1.37 + 1.38 +/** 1.39 + * English reason phrases for HTTP status codes. 1.40 + * All status codes defined in RFC1945 (HTTP/1.0), RFC2616 (HTTP/1.1), and 1.41 + * RFC2518 (WebDAV) are supported. 1.42 + * 1.43 + * @since 4.0 1.44 + */ 1.45 +public class EnglishReasonPhraseCatalog implements ReasonPhraseCatalog { 1.46 + 1.47 + // static array with english reason phrases defined below 1.48 + 1.49 + /** 1.50 + * The default instance of this catalog. 1.51 + * This catalog is thread safe, so there typically 1.52 + * is no need to create other instances. 1.53 + */ 1.54 + public final static EnglishReasonPhraseCatalog INSTANCE = 1.55 + new EnglishReasonPhraseCatalog(); 1.56 + 1.57 + 1.58 + /** 1.59 + * Restricted default constructor, for derived classes. 1.60 + * If you need an instance of this class, use {@link #INSTANCE INSTANCE}. 1.61 + */ 1.62 + protected EnglishReasonPhraseCatalog() { 1.63 + // no body 1.64 + } 1.65 + 1.66 + 1.67 + /** 1.68 + * Obtains the reason phrase for a status code. 1.69 + * 1.70 + * @param status the status code, in the range 100-599 1.71 + * @param loc ignored 1.72 + * 1.73 + * @return the reason phrase, or <code>null</code> 1.74 + */ 1.75 + public String getReason(int status, Locale loc) { 1.76 + if ((status < 100) || (status >= 600)) { 1.77 + throw new IllegalArgumentException 1.78 + ("Unknown category for status code " + status + "."); 1.79 + } 1.80 + 1.81 + final int category = status / 100; 1.82 + final int subcode = status - 100*category; 1.83 + 1.84 + String reason = null; 1.85 + if (REASON_PHRASES[category].length > subcode) 1.86 + reason = REASON_PHRASES[category][subcode]; 1.87 + 1.88 + return reason; 1.89 + } 1.90 + 1.91 + 1.92 + /** Reason phrases lookup table. */ 1.93 + private static final String[][] REASON_PHRASES = new String[][]{ 1.94 + null, 1.95 + new String[3], // 1xx 1.96 + new String[8], // 2xx 1.97 + new String[8], // 3xx 1.98 + new String[25], // 4xx 1.99 + new String[8] // 5xx 1.100 + }; 1.101 + 1.102 + 1.103 + 1.104 + /** 1.105 + * Stores the given reason phrase, by status code. 1.106 + * Helper method to initialize the static lookup table. 1.107 + * 1.108 + * @param status the status code for which to define the phrase 1.109 + * @param reason the reason phrase for this status code 1.110 + */ 1.111 + private static void setReason(int status, String reason) { 1.112 + final int category = status / 100; 1.113 + final int subcode = status - 100*category; 1.114 + REASON_PHRASES[category][subcode] = reason; 1.115 + } 1.116 + 1.117 + 1.118 + // ----------------------------------------------------- Static Initializer 1.119 + 1.120 + /** Set up status code to "reason phrase" map. */ 1.121 + static { 1.122 + // HTTP 1.0 Server status codes -- see RFC 1945 1.123 + setReason(HttpStatus.SC_OK, 1.124 + "OK"); 1.125 + setReason(HttpStatus.SC_CREATED, 1.126 + "Created"); 1.127 + setReason(HttpStatus.SC_ACCEPTED, 1.128 + "Accepted"); 1.129 + setReason(HttpStatus.SC_NO_CONTENT, 1.130 + "No Content"); 1.131 + setReason(HttpStatus.SC_MOVED_PERMANENTLY, 1.132 + "Moved Permanently"); 1.133 + setReason(HttpStatus.SC_MOVED_TEMPORARILY, 1.134 + "Moved Temporarily"); 1.135 + setReason(HttpStatus.SC_NOT_MODIFIED, 1.136 + "Not Modified"); 1.137 + setReason(HttpStatus.SC_BAD_REQUEST, 1.138 + "Bad Request"); 1.139 + setReason(HttpStatus.SC_UNAUTHORIZED, 1.140 + "Unauthorized"); 1.141 + setReason(HttpStatus.SC_FORBIDDEN, 1.142 + "Forbidden"); 1.143 + setReason(HttpStatus.SC_NOT_FOUND, 1.144 + "Not Found"); 1.145 + setReason(HttpStatus.SC_INTERNAL_SERVER_ERROR, 1.146 + "Internal Server Error"); 1.147 + setReason(HttpStatus.SC_NOT_IMPLEMENTED, 1.148 + "Not Implemented"); 1.149 + setReason(HttpStatus.SC_BAD_GATEWAY, 1.150 + "Bad Gateway"); 1.151 + setReason(HttpStatus.SC_SERVICE_UNAVAILABLE, 1.152 + "Service Unavailable"); 1.153 + 1.154 + // HTTP 1.1 Server status codes -- see RFC 2048 1.155 + setReason(HttpStatus.SC_CONTINUE, 1.156 + "Continue"); 1.157 + setReason(HttpStatus.SC_TEMPORARY_REDIRECT, 1.158 + "Temporary Redirect"); 1.159 + setReason(HttpStatus.SC_METHOD_NOT_ALLOWED, 1.160 + "Method Not Allowed"); 1.161 + setReason(HttpStatus.SC_CONFLICT, 1.162 + "Conflict"); 1.163 + setReason(HttpStatus.SC_PRECONDITION_FAILED, 1.164 + "Precondition Failed"); 1.165 + setReason(HttpStatus.SC_REQUEST_TOO_LONG, 1.166 + "Request Too Long"); 1.167 + setReason(HttpStatus.SC_REQUEST_URI_TOO_LONG, 1.168 + "Request-URI Too Long"); 1.169 + setReason(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE, 1.170 + "Unsupported Media Type"); 1.171 + setReason(HttpStatus.SC_MULTIPLE_CHOICES, 1.172 + "Multiple Choices"); 1.173 + setReason(HttpStatus.SC_SEE_OTHER, 1.174 + "See Other"); 1.175 + setReason(HttpStatus.SC_USE_PROXY, 1.176 + "Use Proxy"); 1.177 + setReason(HttpStatus.SC_PAYMENT_REQUIRED, 1.178 + "Payment Required"); 1.179 + setReason(HttpStatus.SC_NOT_ACCEPTABLE, 1.180 + "Not Acceptable"); 1.181 + setReason(HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED, 1.182 + "Proxy Authentication Required"); 1.183 + setReason(HttpStatus.SC_REQUEST_TIMEOUT, 1.184 + "Request Timeout"); 1.185 + 1.186 + setReason(HttpStatus.SC_SWITCHING_PROTOCOLS, 1.187 + "Switching Protocols"); 1.188 + setReason(HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION, 1.189 + "Non Authoritative Information"); 1.190 + setReason(HttpStatus.SC_RESET_CONTENT, 1.191 + "Reset Content"); 1.192 + setReason(HttpStatus.SC_PARTIAL_CONTENT, 1.193 + "Partial Content"); 1.194 + setReason(HttpStatus.SC_GATEWAY_TIMEOUT, 1.195 + "Gateway Timeout"); 1.196 + setReason(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED, 1.197 + "Http Version Not Supported"); 1.198 + setReason(HttpStatus.SC_GONE, 1.199 + "Gone"); 1.200 + setReason(HttpStatus.SC_LENGTH_REQUIRED, 1.201 + "Length Required"); 1.202 + setReason(HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE, 1.203 + "Requested Range Not Satisfiable"); 1.204 + setReason(HttpStatus.SC_EXPECTATION_FAILED, 1.205 + "Expectation Failed"); 1.206 + 1.207 + // WebDAV Server-specific status codes 1.208 + setReason(HttpStatus.SC_PROCESSING, 1.209 + "Processing"); 1.210 + setReason(HttpStatus.SC_MULTI_STATUS, 1.211 + "Multi-Status"); 1.212 + setReason(HttpStatus.SC_UNPROCESSABLE_ENTITY, 1.213 + "Unprocessable Entity"); 1.214 + setReason(HttpStatus.SC_INSUFFICIENT_SPACE_ON_RESOURCE, 1.215 + "Insufficient Space On Resource"); 1.216 + setReason(HttpStatus.SC_METHOD_FAILURE, 1.217 + "Method Failure"); 1.218 + setReason(HttpStatus.SC_LOCKED, 1.219 + "Locked"); 1.220 + setReason(HttpStatus.SC_INSUFFICIENT_STORAGE, 1.221 + "Insufficient Storage"); 1.222 + setReason(HttpStatus.SC_FAILED_DEPENDENCY, 1.223 + "Failed Dependency"); 1.224 + } 1.225 + 1.226 + 1.227 +}