/* GENERATED SOURCE. DO NOT MODIFY. */ // © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * Copyright (C) 2004-2016, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* */ package android.icu.util; import java.nio.ByteBuffer; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import android.icu.impl.ICUData; import android.icu.impl.ICUResourceBundle; import android.icu.impl.ICUResourceBundleReader; import android.icu.impl.ResourceBundleWrapper; /** * [icu enhancement] ICU's replacement for {@link java.util.ResourceBundle}. Methods, fields, and other functionality specific to ICU are labeled '[icu]'. * *
A class representing a collection of resource information pertaining to a given * locale. A resource bundle provides a way of accessing locale- specific information in a * data file. You create a resource bundle that manages the resources for a given locale * and then ask it for individual resources. * *
In ResourceBundle, an object is created and the sub-items are fetched using the * getString and getObject methods. In UResourceBundle, each individual element of a * resource is a resource by itself. * *
Resource bundles in ICU are currently defined using text files that conform to the * following BNF * definition. More on resource bundle concepts and syntax can be found in the Users Guide. * *
The packaging of ICU *.res files can be of two types * ICU4C: *
* root.res * | * -------- * | | * fr.res en.res * | * -------- * | | * fr_CA.res fr_FR.res ** JAVA/JDK: *
* LocaleElements.res * | * ------------------- * | | * LocaleElements_fr.res LocaleElements_en.res * | * --------------------------- * | | * LocaleElements_fr_CA.res LocaleElements_fr_FR.res ** * Depending on the organization of your resources, the syntax to getBundleInstance will * change. To open ICU style organization use: * *
* UResourceBundle bundle = * UResourceBundle.getBundleInstance("com/mycompany/resources", * "en_US", myClassLoader); ** To open Java/JDK style organization use: *
* UResourceBundle bundle = * UResourceBundle.getBundleInstance("com.mycompany.resources.LocaleElements", * "en_US", myClassLoader); ** *
Note: Please use pass a class loader for loading non-ICU resources. Java security does not
* allow loading of resources across jar files. You must provide your class loader
* to load the resources
* @author ram
* @hide Only a subset of ICU is exposed in Android
*/
public abstract class UResourceBundle extends ResourceBundle {
/**
* [icu] Creates a resource bundle using the specified base name and locale.
* ICU_DATA_CLASS is used as the default root.
* @param baseName string containing the name of the data package.
* If null the default ICU package name is used.
* @param localeName the locale for which a resource bundle is desired
* @throws MissingResourceException If no resource bundle for the specified base name
* can be found
* @return a resource bundle for the given base name and locale
*/
public static UResourceBundle getBundleInstance(String baseName, String localeName){
return getBundleInstance(baseName, localeName, ICUResourceBundle.ICU_DATA_CLASS_LOADER,
false);
}
/**
* [icu] Creates a resource bundle using the specified base name, locale, and class root.
*
* @param baseName string containing the name of the data package.
* If null the default ICU package name is used.
* @param localeName the locale for which a resource bundle is desired
* @param root the class object from which to load the resource bundle
* @throws MissingResourceException If no resource bundle for the specified base name
* can be found
* @return a resource bundle for the given base name and locale
*/
public static UResourceBundle getBundleInstance(String baseName, String localeName,
ClassLoader root){
return getBundleInstance(baseName, localeName, root, false);
}
/**
* [icu] Creates a resource bundle using the specified base name, locale, and class
* root.
*
* @param baseName string containing the name of the data package.
* If null the default ICU package name is used.
* @param localeName the locale for which a resource bundle is desired
* @param root the class object from which to load the resource bundle
* @param disableFallback Option to disable locale inheritance.
* If true the fallback chain will not be built.
* @throws MissingResourceException
* if no resource bundle for the specified base name can be found
* @return a resource bundle for the given base name and locale
*
*/
protected static UResourceBundle getBundleInstance(String baseName, String localeName,
ClassLoader root, boolean disableFallback) {
return instantiateBundle(baseName, localeName, root, disableFallback);
}
/**
* [icu] Sole constructor. (For invocation by subclass constructors, typically
* implicit.) This is public for compatibility with Java, whose compiler
* will generate public default constructors for an abstract class.
*/
public UResourceBundle() {
}
/**
* [icu] Creates a UResourceBundle for the locale specified, from which users can extract
* resources by using their corresponding keys.
* @param locale specifies the locale for which we want to open the resource.
* If null the bundle for default locale is opened.
* @return a resource bundle for the given locale
*/
public static UResourceBundle getBundleInstance(ULocale locale) {
if (locale==null) {
locale = ULocale.getDefault();
}
return getBundleInstance(ICUData.ICU_BASE_NAME, locale.getBaseName(),
ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
}
/**
* [icu] Creates a UResourceBundle for the default locale and specified base name,
* from which users can extract resources by using their corresponding keys.
* @param baseName string containing the name of the data package.
* If null the default ICU package name is used.
* @return a resource bundle for the given base name and default locale
*/
public static UResourceBundle getBundleInstance(String baseName) {
if (baseName == null) {
baseName = ICUData.ICU_BASE_NAME;
}
ULocale uloc = ULocale.getDefault();
return getBundleInstance(baseName, uloc.getBaseName(), ICUResourceBundle.ICU_DATA_CLASS_LOADER,
false);
}
/**
* [icu] Creates a UResourceBundle for the specified locale and specified base name,
* from which users can extract resources by using their corresponding keys.
* @param baseName string containing the name of the data package.
* If null the default ICU package name is used.
* @param locale specifies the locale for which we want to open the resource.
* If null the bundle for default locale is opened.
* @return a resource bundle for the given base name and locale
*/
public static UResourceBundle getBundleInstance(String baseName, Locale locale) {
if (baseName == null) {
baseName = ICUData.ICU_BASE_NAME;
}
ULocale uloc = locale == null ? ULocale.getDefault() : ULocale.forLocale(locale);
return getBundleInstance(baseName, uloc.getBaseName(),
ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
}
/**
* [icu] Creates a UResourceBundle, from which users can extract resources by using
* their corresponding keys.
* @param baseName string containing the name of the data package.
* If null the default ICU package name is used.
* @param locale specifies the locale for which we want to open the resource.
* If null the bundle for default locale is opened.
* @return a resource bundle for the given base name and locale
*/
@android.compat.annotation.UnsupportedAppUsage
public static UResourceBundle getBundleInstance(String baseName, ULocale locale) {
if (baseName == null) {
baseName = ICUData.ICU_BASE_NAME;
}
if (locale == null) {
locale = ULocale.getDefault();
}
return getBundleInstance(baseName, locale.getBaseName(),
ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
}
/**
* [icu] Creates a UResourceBundle for the specified locale and specified base name,
* from which users can extract resources by using their corresponding keys.
* @param baseName string containing the name of the data package.
* If null the default ICU package name is used.
* @param locale specifies the locale for which we want to open the resource.
* If null the bundle for default locale is opened.
* @param loader the loader to use
* @return a resource bundle for the given base name and locale
*/
public static UResourceBundle getBundleInstance(String baseName, Locale locale,
ClassLoader loader) {
if (baseName == null) {
baseName = ICUData.ICU_BASE_NAME;
}
ULocale uloc = locale == null ? ULocale.getDefault() : ULocale.forLocale(locale);
return getBundleInstance(baseName, uloc.getBaseName(), loader, false);
}
/**
* [icu] Creates a UResourceBundle, from which users can extract resources by using
* their corresponding keys.
* Note: Please use this API for loading non-ICU resources. Java security does not
* allow loading of resources across jar files. You must provide your class loader
* to load the resources
* @param baseName string containing the name of the data package.
* If null the default ICU package name is used.
* @param locale specifies the locale for which we want to open the resource.
* If null the bundle for default locale is opened.
* @param loader the loader to use
* @return a resource bundle for the given base name and locale
*/
public static UResourceBundle getBundleInstance(String baseName, ULocale locale,
ClassLoader loader) {
if (baseName == null) {
baseName = ICUData.ICU_BASE_NAME;
}
if (locale == null) {
locale = ULocale.getDefault();
}
return getBundleInstance(baseName, locale.getBaseName(), loader, false);
}
/**
* [icu] Returns the RFC 3066 conformant locale id of this resource bundle.
* This method can be used after a call to getBundleInstance() to
* determine whether the resource bundle returned really
* corresponds to the requested locale or is a fallback.
*
* @return the locale of this resource bundle
*/
public abstract ULocale getULocale();
/**
* [icu] Returns the localeID
* @return The string representation of the localeID
*/
protected abstract String getLocaleID();
/**
* [icu] Returns the base name of the resource bundle
* @return The string representation of the base name
*/
protected abstract String getBaseName();
/**
* [icu] Returns the parent bundle
* @return The parent bundle
*/
protected abstract UResourceBundle getParent();
/**
* Returns the locale of this bundle
* @return the locale of this resource bundle
*/
@Override
public Locale getLocale(){
return getULocale().toLocale();
}
private enum RootType { MISSING, ICU, JAVA }
private static Map
Note: Integer array is treated as a scalar type. There are no APIs to
* access individual members of an integer array. It is always returned as a whole.
* @return number of resources in a given resource.
*/
public int getSize() {
return 1;
}
/**
* [icu] Returns the type of a resource.
* Available types are {@link #INT INT}, {@link #ARRAY ARRAY},
* {@link #BINARY BINARY}, {@link #INT_VECTOR INT_VECTOR},
* {@link #STRING STRING}, {@link #TABLE TABLE}.
*
* @return type of the given resource.
*/
@android.compat.annotation.UnsupportedAppUsage
public int getType() {
return NONE;
}
/**
* [icu] Return the version number associated with this UResourceBundle as an
* VersionInfo object.
* @return VersionInfo object containing the version of the bundle
*/
public VersionInfo getVersion() {
return null;
}
/**
* [icu] Returns the iterator which iterates over this
* resource bundle
* @return UResourceBundleIterator that iterates over the resources in the bundle
*/
public UResourceBundleIterator getIterator() {
return new UResourceBundleIterator(this);
}
/**
* [icu] Returns the key associated with a given resource. Not all the resources have
* a key - only those that are members of a table.
* @return a key associated to this resource, or null if it doesn't have a key
*/
@android.compat.annotation.UnsupportedAppUsage
public String getKey() {
return null;
}
/**
* [icu] Resource type constant for "no resource".
*/
public static final int NONE = -1;
/**
* [icu] Resource type constant for strings.
*/
public static final int STRING = 0;
/**
* [icu] Resource type constant for binary data.
*/
public static final int BINARY = 1;
/**
* [icu] Resource type constant for tables of key-value pairs.
*/
public static final int TABLE = 2;
/**
* [icu] Resource type constant for a single 28-bit integer, interpreted as
* signed or unsigned by the getInt() function.
* @see #getInt
*/
public static final int INT = 7;
/**
* [icu] Resource type constant for arrays of resources.
*/
public static final int ARRAY = 8;
/**
* Resource type constant for vectors of 32-bit integers.
* @see #getIntVector
*/
public static final int INT_VECTOR = 14;
//====== protected members ==============
/**
* [icu] Actual worker method for fetching a resource based on the given key.
* Sub classes must override this method if they support resources with keys.
* @param aKey the key string of the resource to be fetched
* @param aliasesVisited hashtable object to hold references of resources already seen
* @param requested the original resource bundle object on which the get method was invoked.
* The requested bundle and the bundle on which this method is invoked
* are the same, except in the cases where aliases are involved.
* @return UResourceBundle a resource associated with the key
*/
protected UResourceBundle handleGet(String aKey, HashMap