jdk/test/sun/util/resources/TimeZone/Bug4640234.java
author ant
Wed, 19 Mar 2008 16:23:50 +0300
changeset 131 fe5ccd4774b4
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6567410: PIT : java/awt/Focus/AutoRequestFocusTest/AutoRequestFocusSetVisibleTest.java fails Summary: A filter flag has been added to the HCBT focus hook. Reviewed-by: dcherepanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright (c) 2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4640234 4946057 4938151 4873691 5023181
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Verifies the translation of time zone names, this test will catch presence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *          of country name for english and selected locales for all ISO country
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *          codes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *          The test program also displays which timezone, country and language names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *          are not translated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * 4946057 Localization for ISO country & language data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * 4938151 Time zones not translated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * 4873691 Changes in TimeZone mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.text.MessageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.text.SimpleDateFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.TimeZone;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public class Bug4640234  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  static SimpleDateFormat sdfEn = new SimpleDateFormat("zzzz", Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  static SimpleDateFormat sdfEnShort = new SimpleDateFormat("z", Locale.US);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  static Locale locEn = Locale.ENGLISH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  static SimpleDateFormat sdfLoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  static SimpleDateFormat sdfLocShort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  static Date date = new Date();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  // Define supported locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  static Locale[] locales2Test = new Locale[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    new Locale("de"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    new Locale("es"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    new Locale("fr"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    new Locale("it"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    new Locale("ja"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    new Locale("ko"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    new Locale("sv"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    new Locale("zh", "CN"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    new Locale("zh", "TW")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    Locale.setDefault(Locale.ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    StringBuffer errors = new StringBuffer("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    StringBuffer warnings = new StringBuffer("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    String[] timezones = TimeZone.getAvailableIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    String[] countries = locEn.getISOCountries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    String[] languages = locEn.getISOLanguages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    ResourceBundle resEn = ResourceBundle.getBundle("sun.util.resources.LocaleNames", locEn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    Map<String, String> countryMapEn = getList(resEn, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    Map<String, String> languageMapEn = getList(resEn, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    ResourceBundle resLoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    Map<String, String> countryMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    Map<String, String> languageMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    for (Locale locale : locales2Test) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
      resLoc = ResourceBundle.getBundle("sun.util.resources.LocaleNames", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
      sdfLoc = new SimpleDateFormat("zzzz", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
      sdfLocShort = new SimpleDateFormat("z", locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
      for (String timezone : timezones) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        if (isTZIgnored(timezone)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
          continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        warnings.append(testTZ(timezone, locale));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      countryMap = getList(resLoc, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      for (String country : countries) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        String[] result = testEntry(country,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
          countryMapEn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
          countryMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
          locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
          "ERROR: {0} country name for country code: {1} not found!\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
          "WARNING: {0} country name for country code: {1} not localized!\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (warnings.indexOf(result[0]) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
          warnings.append(result[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (errors.indexOf(result[1]) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
          errors.append(result[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
      languageMap = getList(resLoc, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
      for (String language : languages) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        String[] result = testEntry(language,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
          languageMapEn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
          languageMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
          locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
          "ERROR: {0} language name for language code: {1} not found!\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
          "WARNING: {0} language name for language code: {1} not localized!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (warnings.indexOf(result[0]) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
          warnings.append(result[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        if (errors.indexOf(result[1]) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
          errors.append(result[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    StringBuffer message = new StringBuffer("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    if (!"".equals(errors.toString())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      message.append("Test failed! ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      message.append("ERROR: some keys are missing! ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    if ("".equals(message.toString())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
      System.out.println("\nTest passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      System.out.println(warnings.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
      System.out.println("\nTest failed!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
      System.out.println(errors.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
      System.out.println(warnings.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
      throw new Exception("\n" + message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
  * Compares the english timezone name and timezone name in specified locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
  * @param timeZoneName - name of the timezone to compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
  * @param locale - locale to test against english
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
  * @return empty string when passed, descriptive error message in other cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
  private static String testTZ(String timeZoneName, Locale locale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    StringBuffer timeZoneResult = new StringBuffer("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    TimeZone tz = TimeZone.getTimeZone(timeZoneName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    sdfEn.setTimeZone(tz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    sdfEnShort.setTimeZone(tz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    sdfLoc.setTimeZone(tz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    sdfLocShort.setTimeZone(tz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    String en, enShort, loc, locShort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    en = sdfEn.format(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    enShort = sdfEnShort.format(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    loc = sdfLoc.format(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    locShort = sdfLocShort.format(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    String displayLanguage = locale.getDisplayLanguage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    String displayCountry = locale.getDisplayCountry();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    if (loc.equals(en)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
      timeZoneResult.append("[");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
      timeZoneResult.append(displayLanguage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
      if (!"".equals(displayCountry)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        timeZoneResult.append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        timeZoneResult.append(displayCountry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
      timeZoneResult.append("] timezone \"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      timeZoneResult.append(timeZoneName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      timeZoneResult.append("\" long name \"" + en);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
      timeZoneResult.append("\" not localized!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    if (!locShort.equals(enShort)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
      timeZoneResult.append("[");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
      timeZoneResult.append(displayLanguage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
      if (!"".equals(displayCountry)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        timeZoneResult.append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        timeZoneResult.append(displayCountry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
      timeZoneResult.append("] timezone \"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
      timeZoneResult.append(timeZoneName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
      timeZoneResult.append("\" short name \"" + enShort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
      timeZoneResult.append("\" is localized \"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
      timeZoneResult.append(locShort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
      timeZoneResult.append("\"!\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    return timeZoneResult.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
  * Verifies whether the name for ISOCode is localized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
  * @param ISOCode - ISO country/language code for country/language name to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
  * @param entriesEn - array of english country/language names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
  * @param entriesLoc - array of localized country/language names for specified locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
  * @param locale - locale to test against english
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
  * @param notFoundMessage - message in form ready for MessageFormat, {0} will be human readable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
  *                          language name, {1} will be ISOCode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
  * @param notLocalizedMessage - message in for ready for MessageFormat, same formatting like
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
  *                              for notFountMessage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
  * @return array of two empty strings when passed, descriptive error message in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
  *         other cases, [0] - warnings for not localized, [1] - errors for missing keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
  private static String[] testEntry(String ISOCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                    Map<String, String> entriesEn,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                                    Map<String, String> entriesLoc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                                    Locale locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                                    String notFoundMessage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                                    String notLocalizedMessage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    String nameEn = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    String nameLoc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    for (String key: entriesEn.keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
      if (ISOCode.equalsIgnoreCase(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        nameEn = entriesEn.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    for (String key: entriesLoc.keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
      if (ISOCode.equalsIgnoreCase(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        nameLoc = entriesLoc.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    if (nameEn == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
      // We should not get here but test is a MUST have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
      return new String[] {"", MessageFormat.format(notFoundMessage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        new String[] {"English", ISOCode})};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    if (nameLoc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      return new String[] {"", MessageFormat.format(notFoundMessage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        new String[] {locale.getDisplayName(), ISOCode})};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    if (nameEn.equals(nameLoc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
      return new String[] {MessageFormat.format(notLocalizedMessage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        new String[] {locale.getDisplayName(), ISOCode}), ""};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    return new String[] {"", ""};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
  private static boolean isTZIgnored(String TZName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    if (TZName.startsWith("Etc/GMT") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        TZName.indexOf("Riyadh8") != -1 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        TZName.equals("GMT0") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        TZName.equals("MET")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
      return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private static Map<String, String> getList(ResourceBundle rs, Boolean getCountryList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        char beginChar = 'a';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        char endChar = 'z';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (getCountryList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            beginChar = 'A';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            endChar = 'Z';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        Map<String, String> hm = new HashMap<String, String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        Enumeration<String> keys = rs.getKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        while (keys.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            String s = keys.nextElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            if (s.length() == 2 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                s.charAt(0) >= beginChar && s.charAt(0) <= endChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                hm.put(s, rs.getString(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        return hm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
}