Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/util/cldr/CLDRLocaleProviderAdapter.java
38918 views
/*1* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.util.cldr;2627import java.io.File;28import java.security.AccessController;29import java.security.PrivilegedAction;30import java.text.spi.BreakIteratorProvider;31import java.text.spi.CollatorProvider;32import java.util.Collections;33import java.util.HashSet;34import java.util.Locale;35import java.util.ResourceBundle;36import java.util.Set;37import java.util.StringTokenizer;38import java.util.spi.TimeZoneNameProvider;39import sun.util.locale.provider.JRELocaleProviderAdapter;40import sun.util.locale.provider.LocaleProviderAdapter;4142/**43* LocaleProviderAdapter implementation for the CLDR locale data.44*45* @author Masayoshi Okutsu46* @author Naoto Sato47*/48public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {49private static final String LOCALE_DATA_JAR_NAME = "cldrdata.jar";5051public CLDRLocaleProviderAdapter() {52final String sep = File.separator;53String localeDataJar = java.security.AccessController.doPrivileged(54new sun.security.action.GetPropertyAction("java.home"))55+ sep + "lib" + sep + "ext" + sep + LOCALE_DATA_JAR_NAME;5657// Peek at the installed extension directory to see if the jar file for58// CLDR resources is installed or not.59final File f = new File(localeDataJar);60boolean result = AccessController.doPrivileged(61new PrivilegedAction<Boolean>() {62@Override63public Boolean run() {64return f.exists();65}66});67if (!result) {68throw new UnsupportedOperationException();69}70}7172/**73* Returns the type of this LocaleProviderAdapter74* @return the type of this75*/76@Override77public LocaleProviderAdapter.Type getAdapterType() {78return LocaleProviderAdapter.Type.CLDR;79}8081@Override82public BreakIteratorProvider getBreakIteratorProvider() {83return null;84}8586@Override87public CollatorProvider getCollatorProvider() {88return null;89}9091@Override92public Locale[] getAvailableLocales() {93Set<String> all = createLanguageTagSet("All");94Locale[] locs = new Locale[all.size()];95int index = 0;96for (String tag : all) {97locs[index++] = Locale.forLanguageTag(tag);98}99return locs;100}101102@Override103protected Set<String> createLanguageTagSet(String category) {104ResourceBundle rb = ResourceBundle.getBundle("sun.util.cldr.CLDRLocaleDataMetaInfo", Locale.ROOT);105String supportedLocaleString = rb.getString(category);106if (supportedLocaleString == null) {107return Collections.emptySet();108}109Set<String> tagset = new HashSet<>();110StringTokenizer tokens = new StringTokenizer(supportedLocaleString);111while (tokens.hasMoreTokens()) {112tagset.add(tokens.nextToken());113}114return tagset;115}116}117118119