1 /* 2 * Copyright (c) 2007, 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 /* 24 * 25 */ 26 27 package com.bar; 28 29 import java.text.*; 30 import java.util.*; 31 import java.util.spi.*; 32 33 import com.foobar.Utils; 34 35 public class LocaleNameProviderImpl extends LocaleNameProvider { 36 static Locale[] avail = {Locale.JAPANESE, 37 Locale.JAPAN, 38 new Locale("ja", "JP", "osaka"), 39 new Locale("ja", "JP", "kyoto"), 40 new Locale("xx")}; 41 static List<Locale> availList = Arrays.asList(avail); 42 public Locale[] getAvailableLocales() { 43 return avail; 44 } 45 46 public String getDisplayLanguage(String lang, Locale target) { 47 if (!Utils.supportsLocale(availList, target)) { 48 throw new IllegalArgumentException("locale is not supported: "+target); 49 } 50 51 String ret = null; 52 53 try { 54 ResourceBundle rb = ResourceBundle.getBundle("com.bar.LocaleNames", target); 55 ret = rb.getString(lang); 56 } catch (MissingResourceException mre) { 57 } 58 59 return ret; 60 } 61 62 public String getDisplayCountry(String ctry, Locale target) { 63 if (!Utils.supportsLocale(availList, target)) { 64 throw new IllegalArgumentException("locale is not supported: "+target); 65 } 66 67 String ret = null; 68 69 try { 70 ResourceBundle rb = ResourceBundle.getBundle("LocaleNames", target); 71 ret = rb.getString(ctry); 72 } catch (MissingResourceException mre) { 73 } 74 75 return ret; 76 } 77 78 public String getDisplayVariant(String vrnt, Locale target) { 79 if (!Utils.supportsLocale(availList, target)) { 80 throw new IllegalArgumentException("locale is not supported: "+target); 81 } 82 83 String ret = null; 84 85 try { 86 ResourceBundle rb = ResourceBundle.getBundle("LocaleNames", target); 87 ret = rb.getString(vrnt); 88 } catch (MissingResourceException mre) { 89 } 90 91 return ret; 92 } 93 }