src/macosx/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java

Print this page
rev 6958 : imported patch 8010666
   1 /*
   2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 503             @Override
 504             public String getDisplayName(String ID, boolean daylight, int style, Locale locale) {
 505                 return getTimeZoneDisplayString(locale.toLanguageTag(), style * 2 + (daylight ? 1 : 0), ID);
 506             }
 507         };
 508     }
 509 
 510     private static Locale[] getSupportedCalendarLocales() {
 511         if (supportedLocale.length != 0 &&
 512             supportedLocaleSet.contains(Locale.JAPAN) &&
 513             isJapaneseCalendar()) {
 514             Locale[] sup = new Locale[supportedLocale.length+1];
 515             sup[0] = JRELocaleConstants.JA_JP_JP;
 516             System.arraycopy(supportedLocale, 0, sup, 1, supportedLocale.length);
 517             return sup;
 518         }
 519         return supportedLocale;
 520     }
 521 
 522     private static boolean isSupportedCalendarLocale(Locale locale) {
 523         Locale base = locale.stripExtensions();








 524         if (!supportedLocaleSet.contains(base)) {
 525             return false;
 526         }
 527 
 528         String requestedCalType = locale.getUnicodeLocaleType("ca");
 529         String nativeCalType =
 530             getCalendarID(locale.toLanguageTag()).replaceFirst("gregorian", "gregory");
 531 
 532         if (requestedCalType == null) {
 533             return Calendar.getAvailableCalendarTypes().contains(nativeCalType);
 534         } else {
 535             return requestedCalType.equals(nativeCalType);
 536         }
 537     }
 538 
 539     private static boolean isJapaneseCalendar() {
 540         return getCalendarID("ja-JP").equals("japanese");
 541     }
 542 
 543     private static Locale getCalendarLocale(Locale locale) {
 544         String nativeCalType = getCalendarID(locale.toLanguageTag())
 545                      .replaceFirst("gregorian", "gregory");
 546         if (Calendar.getAvailableCalendarTypes().contains(nativeCalType)) {
 547             return new Locale.Builder()
 548                            .setLocale(locale)
 549                            .setUnicodeLocaleKeyword("ca", nativeCalType)
 550                            .build();


   1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 503             @Override
 504             public String getDisplayName(String ID, boolean daylight, int style, Locale locale) {
 505                 return getTimeZoneDisplayString(locale.toLanguageTag(), style * 2 + (daylight ? 1 : 0), ID);
 506             }
 507         };
 508     }
 509 
 510     private static Locale[] getSupportedCalendarLocales() {
 511         if (supportedLocale.length != 0 &&
 512             supportedLocaleSet.contains(Locale.JAPAN) &&
 513             isJapaneseCalendar()) {
 514             Locale[] sup = new Locale[supportedLocale.length+1];
 515             sup[0] = JRELocaleConstants.JA_JP_JP;
 516             System.arraycopy(supportedLocale, 0, sup, 1, supportedLocale.length);
 517             return sup;
 518         }
 519         return supportedLocale;
 520     }
 521 
 522     private static boolean isSupportedCalendarLocale(Locale locale) {
 523         Locale base = locale;
 524 
 525         if (base.hasExtensions() || base.getVariant() != "") {
 526             base = new Locale.Builder()
 527                             .setLocale(locale)
 528                             .clearExtensions()
 529                             .build();
 530         }
 531 
 532         if (!supportedLocaleSet.contains(base)) {
 533             return false;
 534         }
 535 
 536         String requestedCalType = locale.getUnicodeLocaleType("ca");
 537         String nativeCalType =
 538             getCalendarID(base.toLanguageTag()).replaceFirst("gregorian", "gregory");
 539 
 540         if (requestedCalType == null) {
 541             return Calendar.getAvailableCalendarTypes().contains(nativeCalType);
 542         } else {
 543             return requestedCalType.equals(nativeCalType);
 544         }
 545     }
 546 
 547     private static boolean isJapaneseCalendar() {
 548         return getCalendarID("ja-JP").equals("japanese");
 549     }
 550 
 551     private static Locale getCalendarLocale(Locale locale) {
 552         String nativeCalType = getCalendarID(locale.toLanguageTag())
 553                      .replaceFirst("gregorian", "gregory");
 554         if (Calendar.getAvailableCalendarTypes().contains(nativeCalType)) {
 555             return new Locale.Builder()
 556                            .setLocale(locale)
 557                            .setUnicodeLocaleKeyword("ca", nativeCalType)
 558                            .build();