LegacyErrorStrings.java revision f1a9b1bc249161fe1a9b0d85d4ed31153e4421c1
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
17package android.webkit;
18
19import android.content.Context;
20import android.net.http.EventHandler;
21import android.util.Log;
22
23/**
24 * Localized strings for the error codes defined in EventHandler.
25 *
26 * {@hide}
27 */
28class LegacyErrorStrings {
29    private LegacyErrorStrings() { /* Utility class, don't instantiate. */ }
30
31    private static final String LOGTAG = "Http";
32
33    /**
34     * Get the localized error message resource for the given error code.
35     * If the code is unknown, we'll return a generic error message.
36     */
37    static String getString(int errorCode, Context context) {
38        return context.getText(getResource(errorCode)).toString();
39    }
40
41    /**
42     * Get the localized error message resource for the given error code.
43     * If the code is unknown, we'll return a generic error message.
44     */
45    private static int getResource(int errorCode) {
46        switch(errorCode) {
47            case EventHandler.OK:
48                return com.android.internal.R.string.httpErrorOk;
49
50            case EventHandler.ERROR:
51                return com.android.internal.R.string.httpError;
52
53            case EventHandler.ERROR_LOOKUP:
54                return com.android.internal.R.string.httpErrorLookup;
55
56            case EventHandler.ERROR_UNSUPPORTED_AUTH_SCHEME:
57                return com.android.internal.R.string.httpErrorUnsupportedAuthScheme;
58
59            case EventHandler.ERROR_AUTH:
60                return com.android.internal.R.string.httpErrorAuth;
61
62            case EventHandler.ERROR_PROXYAUTH:
63                return com.android.internal.R.string.httpErrorProxyAuth;
64
65            case EventHandler.ERROR_CONNECT:
66                return com.android.internal.R.string.httpErrorConnect;
67
68            case EventHandler.ERROR_IO:
69                return com.android.internal.R.string.httpErrorIO;
70
71            case EventHandler.ERROR_TIMEOUT:
72                return com.android.internal.R.string.httpErrorTimeout;
73
74            case EventHandler.ERROR_REDIRECT_LOOP:
75                return com.android.internal.R.string.httpErrorRedirectLoop;
76
77            case EventHandler.ERROR_UNSUPPORTED_SCHEME:
78                return com.android.internal.R.string.httpErrorUnsupportedScheme;
79
80            case EventHandler.ERROR_FAILED_SSL_HANDSHAKE:
81                return com.android.internal.R.string.httpErrorFailedSslHandshake;
82
83            case EventHandler.ERROR_BAD_URL:
84                return com.android.internal.R.string.httpErrorBadUrl;
85
86            case EventHandler.FILE_ERROR:
87                return com.android.internal.R.string.httpErrorFile;
88
89            case EventHandler.FILE_NOT_FOUND_ERROR:
90                return com.android.internal.R.string.httpErrorFileNotFound;
91
92            case EventHandler.TOO_MANY_REQUESTS_ERROR:
93                return com.android.internal.R.string.httpErrorTooManyRequests;
94
95            default:
96                Log.w(LOGTAG, "Using generic message for unknown error code: " + errorCode);
97                return com.android.internal.R.string.httpError;
98        }
99    }
100}
101