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
23 * questions.
24 */
25
26 package sun.util.locale.provider;
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.text.spi.DateFormatProvider;
34 import java.text.spi.DateFormatSymbolsProvider;
35 import java.text.spi.DecimalFormatSymbolsProvider;
36 import java.text.spi.NumberFormatProvider;
37 import java.util.HashSet;
38 import java.util.Locale;
39 import java.util.Set;
40 import java.util.StringTokenizer;
41 import java.util.concurrent.ConcurrentHashMap;
42 import java.util.concurrent.ConcurrentMap;
43 import java.util.spi.CalendarDataProvider;
44 import java.util.spi.CalendarNameProvider;
45 import java.util.spi.CurrencyNameProvider;
46 import java.util.spi.LocaleNameProvider;
47 import java.util.spi.LocaleServiceProvider;
48 import java.util.spi.TimeZoneNameProvider;
49 import sun.util.resources.LocaleData;
50 import sun.util.spi.CalendarProvider;
51
52 /**
53 * LocaleProviderAdapter implementation for the legacy JRE locale data.
54 *
55 * @author Naoto Sato
56 * @author Masayoshi Okutsu
339 */
340 @Override
341 public Locale[] getAvailableLocales() {
342 return AvailableJRELocales.localeList.clone();
343 }
344
345 public Set<String> getLanguageTagSet(String category) {
346 Set<String> tagset = langtagSets.get(category);
347 if (tagset == null) {
348 tagset = createLanguageTagSet(category);
349 Set<String> ts = langtagSets.putIfAbsent(category, tagset);
350 if (ts != null) {
351 tagset = ts;
352 }
353 }
354 return tagset;
355 }
356
357 protected Set<String> createLanguageTagSet(String category) {
358 String supportedLocaleString = LocaleDataMetaInfo.getSupportedLocaleString(category);
359 Set<String> tagset = new HashSet<>();
360 StringTokenizer tokens = new StringTokenizer(supportedLocaleString);
361 while (tokens.hasMoreTokens()) {
362 String token = tokens.nextToken();
363 if (token.equals("|")) {
364 if (isNonENLangSupported()) {
365 continue;
366 }
367 break;
368 }
369 tagset.add(token);
370 }
371
372 return tagset;
373 }
374
375 /**
376 * Lazy load available locales.
377 */
378 private static class AvailableJRELocales {
|
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.locale.provider;
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.text.spi.DateFormatProvider;
34 import java.text.spi.DateFormatSymbolsProvider;
35 import java.text.spi.DecimalFormatSymbolsProvider;
36 import java.text.spi.NumberFormatProvider;
37 import java.util.Collections;
38 import java.util.HashSet;
39 import java.util.Locale;
40 import java.util.Set;
41 import java.util.StringTokenizer;
42 import java.util.concurrent.ConcurrentHashMap;
43 import java.util.concurrent.ConcurrentMap;
44 import java.util.spi.CalendarDataProvider;
45 import java.util.spi.CalendarNameProvider;
46 import java.util.spi.CurrencyNameProvider;
47 import java.util.spi.LocaleNameProvider;
48 import java.util.spi.LocaleServiceProvider;
49 import java.util.spi.TimeZoneNameProvider;
50 import sun.util.resources.LocaleData;
51 import sun.util.spi.CalendarProvider;
52
53 /**
54 * LocaleProviderAdapter implementation for the legacy JRE locale data.
55 *
56 * @author Naoto Sato
57 * @author Masayoshi Okutsu
340 */
341 @Override
342 public Locale[] getAvailableLocales() {
343 return AvailableJRELocales.localeList.clone();
344 }
345
346 public Set<String> getLanguageTagSet(String category) {
347 Set<String> tagset = langtagSets.get(category);
348 if (tagset == null) {
349 tagset = createLanguageTagSet(category);
350 Set<String> ts = langtagSets.putIfAbsent(category, tagset);
351 if (ts != null) {
352 tagset = ts;
353 }
354 }
355 return tagset;
356 }
357
358 protected Set<String> createLanguageTagSet(String category) {
359 String supportedLocaleString = LocaleDataMetaInfo.getSupportedLocaleString(category);
360 if (supportedLocaleString == null) {
361 return Collections.emptySet();
362 }
363 Set<String> tagset = new HashSet<>();
364 StringTokenizer tokens = new StringTokenizer(supportedLocaleString);
365 while (tokens.hasMoreTokens()) {
366 String token = tokens.nextToken();
367 if (token.equals("|")) {
368 if (isNonENLangSupported()) {
369 continue;
370 }
371 break;
372 }
373 tagset.add(token);
374 }
375
376 return tagset;
377 }
378
379 /**
380 * Lazy load available locales.
381 */
382 private static class AvailableJRELocales {
|