Home | History | Annotate | Download | only in http
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.net.http;
     18 
     19 import android.content.Context;
     20 import android.util.Log;
     21 
     22 /**
     23  * Localized strings for the error codes defined in EventHandler.
     24  *
     25  * {@hide}
     26  */
     27 public class ErrorStrings {
     28     private ErrorStrings() { /* Utility class, don't instantiate. */ }
     29 
     30     private static final String LOGTAG = "Http";
     31 
     32     /**
     33      * Get the localized error message resource for the given error code.
     34      * If the code is unknown, we'll return a generic error message.
     35      */
     36     public static String getString(int errorCode, Context context) {
     37         return context.getText(getResource(errorCode)).toString();
     38     }
     39 
     40     /**
     41      * Get the localized error message resource for the given error code.
     42      * If the code is unknown, we'll return a generic error message.
     43      */
     44     public static int getResource(int errorCode) {
     45         switch(errorCode) {
     46             case EventHandler.OK:
     47                 return com.android.internal.R.string.httpErrorOk;
     48 
     49             case EventHandler.ERROR:
     50                 return com.android.internal.R.string.httpError;
     51 
     52             case EventHandler.ERROR_LOOKUP:
     53                 return com.android.internal.R.string.httpErrorLookup;
     54 
     55             case EventHandler.ERROR_UNSUPPORTED_AUTH_SCHEME:
     56                 return com.android.internal.R.string.httpErrorUnsupportedAuthScheme;
     57 
     58             case EventHandler.ERROR_AUTH:
     59                 return com.android.internal.R.string.httpErrorAuth;
     60 
     61             case EventHandler.ERROR_PROXYAUTH:
     62                 return com.android.internal.R.string.httpErrorProxyAuth;
     63 
     64             case EventHandler.ERROR_CONNECT:
     65                 return com.android.internal.R.string.httpErrorConnect;
     66 
     67             case EventHandler.ERROR_IO:
     68                 return com.android.internal.R.string.httpErrorIO;
     69 
     70             case EventHandler.ERROR_TIMEOUT:
     71                 return com.android.internal.R.string.httpErrorTimeout;
     72 
     73             case EventHandler.ERROR_REDIRECT_LOOP:
     74                 return com.android.internal.R.string.httpErrorRedirectLoop;
     75 
     76             case EventHandler.ERROR_UNSUPPORTED_SCHEME:
     77                 return com.android.internal.R.string.httpErrorUnsupportedScheme;
     78 
     79             case EventHandler.ERROR_FAILED_SSL_HANDSHAKE:
     80                 return com.android.internal.R.string.httpErrorFailedSslHandshake;
     81 
     82             case EventHandler.ERROR_BAD_URL:
     83                 return com.android.internal.R.string.httpErrorBadUrl;
     84 
     85             case EventHandler.FILE_ERROR:
     86                 return com.android.internal.R.string.httpErrorFile;
     87 
     88             case EventHandler.FILE_NOT_FOUND_ERROR:
     89                 return com.android.internal.R.string.httpErrorFileNotFound;
     90 
     91             case EventHandler.TOO_MANY_REQUESTS_ERROR:
     92                 return com.android.internal.R.string.httpErrorTooManyRequests;
     93 
     94             default:
     95                 Log.w(LOGTAG, "Using generic message for unknown error code: " + errorCode);
     96                 return com.android.internal.R.string.httpError;
     97         }
     98     }
     99 }
    100