Print this page
rev 5615 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o Jigsaw. by Naoto Sato and Masayoshi Okutsu)

Split Close
Expand all
Collapse all
          --- old/test/sun/text/resources/LocaleDataTest.java
          +++ new/test/sun/text/resources/LocaleDataTest.java
↓ open down ↓ 137 lines elided ↑ open up ↑
 138  138  
 139  139  import java.io.*;
 140  140  import java.text.*;
 141  141  import java.util.Locale;
 142  142  import java.util.ResourceBundle;
 143  143  import java.util.ResourceBundle.Control;
 144  144  import java.util.MissingResourceException;
 145  145  
 146  146  public class LocaleDataTest
 147  147  {
      148 +    static final String TEXT_RESOURCES_PACKAGE ="sun.text.resources";
      149 +    static final String UTIL_RESOURCES_PACKAGE ="sun.util.resources";
      150 +
 148  151      public static void main(String[] args) throws Exception {
 149  152  
 150  153          // set up our flags and our input and output streams based on the
 151  154          // command-line arguments (exceptions generated here will propagate out
 152  155          // to the environment)
 153  156          BufferedReader in = null;
 154  157          PrintWriter out = null;
 155  158          boolean writeNewFile = false;
 156  159          boolean doThrow = true;
 157  160  
↓ open down ↓ 121 lines elided ↑ open up ↑
 279  282              qualifier = "";
 280  283  
 281  284          String retrievedValue = null;
 282  285          Object resource = null;
 283  286          try {
 284  287              String fullName = null;
 285  288              if (rbName.equals("CalendarData")
 286  289                      || rbName.equals("CurrencyNames")
 287  290                      || rbName.equals("LocaleNames")
 288  291                      || rbName.equals("TimeZoneNames")) {
 289      -                fullName = "sun.util.resources." + rbName;
      292 +                fullName = UTIL_RESOURCES_PACKAGE + "." + rbName;
 290  293              } else {
 291      -                fullName = "sun.text.resources." + rbName;
      294 +                fullName = TEXT_RESOURCES_PACKAGE + "." + rbName;
 292  295              }
 293  296              Locale locale;
 294  297              if (use_tag) {
 295  298                  locale = Locale.forLanguageTag(localeName);
 296  299              } else {
 297  300                  locale = new Locale(language, country, variant);
 298  301              }
 299  302              ResourceBundle bundle = ResourceBundle.getBundle(fullName,
 300      -                           locale,
 301      -                           ResourceBundle.Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
      303 +                                                             locale,
      304 +                                                             JRELocaleResourceBundleControl.INSTANCE);
 302  305              resource = bundle.getObject(resTag);
 303  306          }
 304  307          catch (MissingResourceException e) {
 305  308          }
 306  309  
 307  310          if (resource != null) {
 308  311              if (resource instanceof String) {
 309  312                  retrievedValue = (String)resource;
 310  313              }
 311  314              else if (resource instanceof String[]) {
 312  315                  int element = Integer.valueOf(qualifier).intValue();
 313  316                  String[] stringList = (String[])resource;
 314      -                if (element >= 0 || element < stringList.length)
      317 +                if (element >= 0 && element < stringList.length)
 315  318                      retrievedValue = stringList[element];
 316  319              }
 317  320              else if (resource instanceof String[][]) {
 318  321                  String[][] stringArray = (String[][])resource;
 319  322                  int slash = qualifier.indexOf("/");
 320  323                  if (slash == -1) {
 321  324                      for (int i = 0; i < stringArray.length; i++) {
 322  325                          if (stringArray[i][0].equals(qualifier))
 323  326                              retrievedValue = stringArray[i][1];
 324  327                      }
 325  328                  }
 326  329                  else {
 327  330                      int row = Integer.valueOf(qualifier.substring(0, slash)).intValue();
 328  331                      int column = Integer.valueOf(qualifier.substring(slash + 1)).intValue();
 329      -                    if (row >= 0 || row < stringArray.length || column >= 0 || column <
      332 +                    if (row >= 0 && row < stringArray.length && column >= 0 && column <
 330  333                                      stringArray[row].length)
 331  334                          retrievedValue = stringArray[row][column];
 332  335                  }
 333  336              }
 334  337          }
 335  338  
 336  339          if (retrievedValue == null || !retrievedValue.equals(expectedValue)) {
 337  340              if (retrievedValue == null)
 338  341                  retrievedValue = "<MISSING!>";
 339  342  
↓ open down ↓ 5 lines elided ↑ open up ↑
 345  348                  out.println("   jvm = \"" + retrievedValue + "\"");
 346  349              }
 347  350              return false;
 348  351          }
 349  352          else {
 350  353              if (writeNewFile)
 351  354                  out.println(key + "=" + expectedValue);
 352  355          }
 353  356          return true;
 354  357      }
      358 +
      359 +    private static class JRELocaleResourceBundleControl extends ResourceBundle.Control {
      360 +        static final JRELocaleResourceBundleControl INSTANCE = new JRELocaleResourceBundleControl();
      361 +
      362 +        private JRELocaleResourceBundleControl() {
      363 +        }
      364 +
      365 +        @Override
      366 +        public Locale getFallbackLocale(String baseName, Locale locale) {
      367 +            if (baseName == null || locale == null) {
      368 +                throw new NullPointerException();
      369 +            }
      370 +            return null;
      371 +        }
      372 +
      373 +        private static final String CLDR      = ".cldr";
      374 +
      375 +        /**
      376 +         * Changes baseName to its per-language package name and
      377 +         * calls the super class implementation. For example,
      378 +         * if the baseName is "sun.text.resources.FormatData" and locale is ja_JP,
      379 +         * the baseName is changed to "sun.text.resources.ja.FormatData". If
      380 +         * baseName contains "cldr", such as "sun.text.resources.cldr.FormatData",
      381 +         * the name is changed to "sun.text.resources.cldr.jp.FormatData".
      382 +         */
      383 +        @Override
      384 +        public String toBundleName(String baseName, Locale locale) {
      385 +            String newBaseName = baseName;
      386 +            String lang = locale.getLanguage();
      387 +            if (lang.length() > 0) {
      388 +                if (baseName.startsWith(UTIL_RESOURCES_PACKAGE)
      389 +                    || baseName.startsWith(TEXT_RESOURCES_PACKAGE)) {
      390 +                    // Assume the lengths are the same.
      391 +                    if (UTIL_RESOURCES_PACKAGE.length()
      392 +                        != TEXT_RESOURCES_PACKAGE.length()) {
      393 +                        throw new InternalError("The resources package names have different lengths.");
      394 +                    }
      395 +                    int index = TEXT_RESOURCES_PACKAGE.length();
      396 +                    if (baseName.indexOf(CLDR, index) > 0) {
      397 +                        index += CLDR.length();
      398 +                    }
      399 +                    newBaseName = baseName.substring(0, index + 1) + lang
      400 +                                      + baseName.substring(index);
      401 +                }
      402 +            }
      403 +            return super.toBundleName(newBaseName, locale);
      404 +        }
      405 +    }
 355  406  }
 356  407  
 357  408  class EscapeReader extends FilterReader {
 358  409      public EscapeReader(Reader in) {
 359  410          super(in);
 360  411      }
 361  412  
 362  413      public int read() throws IOException {
 363  414          if (buffer != null) {
 364  415              String b = buffer.toString();
↓ open down ↓ 85 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX