< prev index next >

src/java.base/share/classes/sun/util/locale/provider/LocaleNameProviderImpl.java

Print this page
rev 47480 : [mq]: 8176841
   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


 151      * Returns a localized name for the given variant code and the given locale that
 152      * is appropriate for display to the user.
 153      * If the name returned cannot be localized according to <code>locale</code>,
 154      * this method returns null.
 155      * @param vrnt the variant string
 156      * @param locale the desired locale
 157      * @return the name of the given variant string for the specified locale, or null if it's not
 158      *     available.
 159      * @exception NullPointerException if <code>variant</code> or <code>locale</code> is null
 160      * @exception IllegalArgumentException if <code>locale</code> isn't
 161      *     one of the locales returned from
 162      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
 163      *     getAvailableLocales()}.
 164      * @see java.util.Locale#getDisplayVariant(java.util.Locale)
 165      */
 166     @Override
 167     public String getDisplayVariant(String vrnt, Locale locale) {
 168         return getDisplayString("%%"+vrnt, locale);
 169     }
 170 




















 171     private String getDisplayString(String key, Locale locale) {
 172         if (key == null || locale == null) {
 173             throw new NullPointerException();
 174         }
 175 
 176         return LocaleProviderAdapter.forType(type).getLocaleResources(locale).getLocaleName(key);
 177     }
 178 
 179     @Override
 180     public Set<String> getAvailableLanguageTags() {
 181         return langtags;
 182     }
 183 }
   1 /*
   2  * Copyright (c) 2012, 2017, 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


 151      * Returns a localized name for the given variant code and the given locale that
 152      * is appropriate for display to the user.
 153      * If the name returned cannot be localized according to <code>locale</code>,
 154      * this method returns null.
 155      * @param vrnt the variant string
 156      * @param locale the desired locale
 157      * @return the name of the given variant string for the specified locale, or null if it's not
 158      *     available.
 159      * @exception NullPointerException if <code>variant</code> or <code>locale</code> is null
 160      * @exception IllegalArgumentException if <code>locale</code> isn't
 161      *     one of the locales returned from
 162      *     {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
 163      *     getAvailableLocales()}.
 164      * @see java.util.Locale#getDisplayVariant(java.util.Locale)
 165      */
 166     @Override
 167     public String getDisplayVariant(String vrnt, Locale locale) {
 168         return getDisplayString("%%"+vrnt, locale);
 169     }
 170 
 171     /**
 172      * @inheritDoc
 173      */
 174     @Override
 175     public String getDisplayUnicodeExtensionKey(String key, Locale locale) {
 176         String rbKey = "key." + key;
 177         String name = getDisplayString(rbKey, locale);
 178         return rbKey.equals(name) ? key : name;
 179     }
 180 
 181     /**
 182      * @inheritDoc
 183      */
 184     @Override
 185     public String getDisplayUnicodeExtensionType(String extType, String key, Locale locale) {
 186         String rbKey = "type." + key + "." + extType;
 187         String name = getDisplayString(rbKey, locale);
 188         return rbKey.equals(name) ? extType : name;
 189     }
 190 
 191     private String getDisplayString(String key, Locale locale) {
 192         if (key == null || locale == null) {
 193             throw new NullPointerException();
 194         }
 195 
 196         return LocaleProviderAdapter.forType(type).getLocaleResources(locale).getLocaleName(key);
 197     }
 198 
 199     @Override
 200     public Set<String> getAvailableLanguageTags() {
 201         return langtags;
 202     }
 203 }
< prev index next >