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
23 * questions.
24 */
25
26 package sun.util.cldr;
27
28 import java.io.File;
29 import java.security.AccessController;
30 import java.security.PrivilegedAction;
31 import java.text.spi.BreakIteratorProvider;
32 import java.text.spi.CollatorProvider;
33 import java.util.HashSet;
34 import java.util.Locale;
35 import java.util.ResourceBundle;
36 import java.util.Set;
37 import java.util.StringTokenizer;
38 import java.util.spi.TimeZoneNameProvider;
39 import sun.util.locale.provider.JRELocaleProviderAdapter;
40 import sun.util.locale.provider.LocaleProviderAdapter;
41
42 /**
43 * LocaleProviderAdapter implementation for the CLDR locale data.
44 *
45 * @author Masayoshi Okutsu
46 * @author Naoto Sato
47 */
48 public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {
49 private static final String LOCALE_DATA_JAR_NAME = "cldrdata.jar";
50
51 public CLDRLocaleProviderAdapter() {
52 final String sep = File.separator;
86 @Override
87 public CollatorProvider getCollatorProvider() {
88 return null;
89 }
90
91 @Override
92 public Locale[] getAvailableLocales() {
93 Set<String> all = createLanguageTagSet("All");
94 Locale[] locs = new Locale[all.size()];
95 int index = 0;
96 for (String tag : all) {
97 locs[index++] = Locale.forLanguageTag(tag);
98 }
99 return locs;
100 }
101
102 @Override
103 protected Set<String> createLanguageTagSet(String category) {
104 ResourceBundle rb = ResourceBundle.getBundle("sun.util.cldr.CLDRLocaleDataMetaInfo", Locale.ROOT);
105 String supportedLocaleString = rb.getString(category);
106 Set<String> tagset = new HashSet<>();
107 StringTokenizer tokens = new StringTokenizer(supportedLocaleString);
108 while (tokens.hasMoreTokens()) {
109 tagset.add(tokens.nextToken());
110 }
111 return tagset;
112 }
113 }
|
1 /*
2 * Copyright (c) 2012, 2015, 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
23 * questions.
24 */
25
26 package sun.util.cldr;
27
28 import java.io.File;
29 import java.security.AccessController;
30 import java.security.PrivilegedAction;
31 import java.text.spi.BreakIteratorProvider;
32 import java.text.spi.CollatorProvider;
33 import java.util.Collections;
34 import java.util.HashSet;
35 import java.util.Locale;
36 import java.util.ResourceBundle;
37 import java.util.Set;
38 import java.util.StringTokenizer;
39 import java.util.spi.TimeZoneNameProvider;
40 import sun.util.locale.provider.JRELocaleProviderAdapter;
41 import sun.util.locale.provider.LocaleProviderAdapter;
42
43 /**
44 * LocaleProviderAdapter implementation for the CLDR locale data.
45 *
46 * @author Masayoshi Okutsu
47 * @author Naoto Sato
48 */
49 public class CLDRLocaleProviderAdapter extends JRELocaleProviderAdapter {
50 private static final String LOCALE_DATA_JAR_NAME = "cldrdata.jar";
51
52 public CLDRLocaleProviderAdapter() {
53 final String sep = File.separator;
87 @Override
88 public CollatorProvider getCollatorProvider() {
89 return null;
90 }
91
92 @Override
93 public Locale[] getAvailableLocales() {
94 Set<String> all = createLanguageTagSet("All");
95 Locale[] locs = new Locale[all.size()];
96 int index = 0;
97 for (String tag : all) {
98 locs[index++] = Locale.forLanguageTag(tag);
99 }
100 return locs;
101 }
102
103 @Override
104 protected Set<String> createLanguageTagSet(String category) {
105 ResourceBundle rb = ResourceBundle.getBundle("sun.util.cldr.CLDRLocaleDataMetaInfo", Locale.ROOT);
106 String supportedLocaleString = rb.getString(category);
107 if (supportedLocaleString == null) {
108 return Collections.emptySet();
109 }
110 Set<String> tagset = new HashSet<>();
111 StringTokenizer tokens = new StringTokenizer(supportedLocaleString);
112 while (tokens.hasMoreTokens()) {
113 tagset.add(tokens.nextToken());
114 }
115 return tagset;
116 }
117 }
|