public abstract class UResourceBundle extends ResourceBundle
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.resJAVA/JDK:
LocaleElements.res | ------------------- | | LocaleElements_fr.res LocaleElements_en.res | --------------------------- | | LocaleElements_fr_CA.res LocaleElements_fr_FR.resDepending 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
ResourceBundle.Control
Modifier and Type | Field and Description |
---|---|
static int |
ARRAY
[icu] Resource type constant for arrays of resources.
|
static int |
BINARY
[icu] Resource type constant for binary data.
|
static int |
INT
[icu] Resource type constant for a single 28-bit integer, interpreted as
signed or unsigned by the getInt() function.
|
static int |
INT_VECTOR
Resource type constant for vectors of 32-bit integers.
|
static int |
NONE
[icu] Resource type constant for "no resource".
|
static int |
STRING
[icu] Resource type constant for strings.
|
static int |
TABLE
[icu] Resource type constant for tables of key-value pairs.
|
parent
Constructor and Description |
---|
UResourceBundle()
[icu] Sole constructor.
|
Modifier and Type | Method and Description |
---|---|
protected UResourceBundle |
findTopLevel(int index)
Deprecated.
This API is ICU internal only.
|
protected UResourceBundle |
findTopLevel(String aKey)
Deprecated.
This API is ICU internal only.
|
UResourceBundle |
get(int index)
[icu] Returns the resource in a given resource at the specified index.
|
UResourceBundle |
get(String aKey)
[icu] Returns a resource in a given resource that has a given key.
|
protected abstract String |
getBaseName()
[icu] Returns the base name of the resource bundle
|
ByteBuffer |
getBinary()
[icu] Returns a binary data item from a binary resource, as a read-only ByteBuffer.
|
byte[] |
getBinary(byte[] ba)
[icu] Returns a binary data from a binary resource, as a byte array with a copy
of the bytes from the resource bundle.
|
static UResourceBundle |
getBundleInstance(String baseName)
[icu] Creates a UResourceBundle for the default locale and specified base name,
from which users can extract resources by using their corresponding keys.
|
static UResourceBundle |
getBundleInstance(String baseName,
Locale locale)
[icu] Creates a UResourceBundle for the specified locale and specified base name,
from which users can extract resources by using their corresponding keys.
|
static UResourceBundle |
getBundleInstance(String baseName,
Locale locale,
ClassLoader loader)
[icu] Creates a UResourceBundle for the specified locale and specified base name,
from which users can extract resources by using their corresponding keys.
|
static UResourceBundle |
getBundleInstance(String baseName,
String localeName)
[icu] Creates a resource bundle using the specified base name and locale.
|
static UResourceBundle |
getBundleInstance(String baseName,
String localeName,
ClassLoader root)
[icu] Creates a resource bundle using the specified base name, locale, and class root.
|
protected static UResourceBundle |
getBundleInstance(String baseName,
String localeName,
ClassLoader root,
boolean disableFallback)
[icu] Creates a resource bundle using the specified base name, locale, and class
root.
|
static UResourceBundle |
getBundleInstance(String baseName,
ULocale locale)
[icu] Creates a UResourceBundle, from which users can extract resources by using
their corresponding keys.
|
static UResourceBundle |
getBundleInstance(String baseName,
ULocale locale,
ClassLoader loader)
[icu] Creates a UResourceBundle, from which users can extract resources by using
their corresponding keys.
|
static UResourceBundle |
getBundleInstance(ULocale locale)
[icu] Creates a UResourceBundle for the locale specified, from which users can extract
resources by using their corresponding keys.
|
int |
getInt()
[icu] Returns a signed integer from a resource.
|
int[] |
getIntVector()
[icu] Returns a 32 bit integer array from a resource.
|
UResourceBundleIterator |
getIterator()
[icu] Returns the iterator which iterates over this
resource bundle
|
String |
getKey()
[icu] Returns the key associated with a given resource.
|
Enumeration<String> |
getKeys()
Returns the keys in this bundle as an enumeration
|
Locale |
getLocale()
Returns the locale of this bundle
|
protected abstract String |
getLocaleID()
[icu] Returns the localeID
|
protected abstract UResourceBundle |
getParent()
[icu] Returns the parent bundle
|
int |
getSize()
[icu] Returns the size of a resource.
|
String |
getString()
Returns a string from a string resource type
|
String |
getString(int index)
Returns the string in a given resource at the specified index.
|
String[] |
getStringArray()
Returns a string array from a array resource type
|
int |
getType()
[icu] Returns the type of a resource.
|
int |
getUInt()
[icu] Returns a unsigned integer from a resource.
|
abstract ULocale |
getULocale()
[icu] Returns the RFC 3066 conformant locale id of this resource bundle.
|
VersionInfo |
getVersion()
[icu] Return the version number associated with this UResourceBundle as an
VersionInfo object.
|
protected UResourceBundle |
handleGet(int index,
HashMap<String,String> aliasesVisited,
UResourceBundle requested)
[icu] Actual worker method for fetching a resource based on the given index.
|
protected UResourceBundle |
handleGet(String aKey,
HashMap<String,String> aliasesVisited,
UResourceBundle requested)
[icu] Actual worker method for fetching a resource based on the given key.
|
protected Enumeration<String> |
handleGetKeys()
[icu] Actual worker method for fetching the keys of resources contained in the resource.
|
protected Object |
handleGetObject(String aKey) |
protected String[] |
handleGetStringArray()
[icu] Actual worker method for fetching the array of strings in a resource.
|
protected Set<String> |
handleKeySet()
Deprecated.
This API is ICU internal only.
|
protected static UResourceBundle |
instantiateBundle(String baseName,
String localeName,
ClassLoader root,
boolean disableFallback)
[icu] Loads a new resource bundle for the given base name, locale and class loader.
|
protected boolean |
isTopLevelResource()
Deprecated.
This API is ICU internal only.
|
Set<String> |
keySet()
Deprecated.
This API is ICU internal only.
|
clearCache, clearCache, containsKey, getBaseBundleName, getBundle, getBundle, getBundle, getBundle, getBundle, getBundle, getObject, getString, getStringArray, setParent
public static final int NONE
public static final int STRING
public static final int BINARY
public static final int TABLE
public static final int INT
getInt()
,
Constant Field Valuespublic static final int ARRAY
public static final int INT_VECTOR
getIntVector()
,
Constant Field Valuespublic UResourceBundle()
public static UResourceBundle getBundleInstance(String baseName, String localeName)
baseName
- string containing the name of the data package.
If null the default ICU package name is used.localeName
- the locale for which a resource bundle is desiredMissingResourceException
- If no resource bundle for the specified base name
can be foundpublic static UResourceBundle getBundleInstance(String baseName, String localeName, ClassLoader root)
baseName
- string containing the name of the data package.
If null the default ICU package name is used.localeName
- the locale for which a resource bundle is desiredroot
- the class object from which to load the resource bundleMissingResourceException
- If no resource bundle for the specified base name
can be foundprotected static UResourceBundle getBundleInstance(String baseName, String localeName, ClassLoader root, boolean disableFallback)
baseName
- string containing the name of the data package.
If null the default ICU package name is used.localeName
- the locale for which a resource bundle is desiredroot
- the class object from which to load the resource bundledisableFallback
- Option to disable locale inheritance.
If true the fallback chain will not be built.MissingResourceException
- if no resource bundle for the specified base name can be foundpublic static UResourceBundle getBundleInstance(ULocale locale)
locale
- specifies the locale for which we want to open the resource.
If null the bundle for default locale is opened.public static UResourceBundle getBundleInstance(String baseName)
baseName
- string containing the name of the data package.
If null the default ICU package name is used.public static UResourceBundle getBundleInstance(String baseName, Locale locale)
baseName
- string containing the name of the data package.
If null the default ICU package name is used.locale
- specifies the locale for which we want to open the resource.
If null the bundle for default locale is opened.public static UResourceBundle getBundleInstance(String baseName, ULocale locale)
baseName
- string containing the name of the data package.
If null the default ICU package name is used.locale
- specifies the locale for which we want to open the resource.
If null the bundle for default locale is opened.public static UResourceBundle getBundleInstance(String baseName, Locale locale, ClassLoader loader)
baseName
- string containing the name of the data package.
If null the default ICU package name is used.locale
- specifies the locale for which we want to open the resource.
If null the bundle for default locale is opened.loader
- the loader to usepublic static UResourceBundle getBundleInstance(String baseName, ULocale locale, ClassLoader loader)
baseName
- string containing the name of the data package.
If null the default ICU package name is used.locale
- specifies the locale for which we want to open the resource.
If null the bundle for default locale is opened.loader
- the loader to usepublic abstract ULocale getULocale()
protected abstract String getLocaleID()
protected abstract String getBaseName()
protected abstract UResourceBundle getParent()
public Locale getLocale()
getLocale
in class ResourceBundle
protected static UResourceBundle instantiateBundle(String baseName, String localeName, ClassLoader root, boolean disableFallback)
baseName
- string containing the name of the data package.
If null the default ICU package name is used.localeName
- the locale for which a resource bundle is desiredroot
- the class object from which to load the resource bundledisableFallback
- disables loading of fallback lookup chainMissingResourceException
- If no resource bundle for the specified base name
can be foundpublic ByteBuffer getBinary()
MissingResourceException
- If no resource bundle can be found.UResourceTypeMismatchException
- If the resource has a type mismatch.getIntVector()
,
getInt()
public String getString()
MissingResourceException
- If resource bundle is missing.UResourceTypeMismatchException
- If resource bundle has a type mismatch.getBinary()
,
getIntVector()
,
getInt()
public String[] getStringArray()
MissingResourceException
- If resource bundle is missing.UResourceTypeMismatchException
- If resource bundle has a type mismatch.getString()
,
getIntVector()
public byte[] getBinary(byte[] ba)
ba
- The byte array to write the bytes to. A null variable is OK.MissingResourceException
- If resource bundle is missing.UResourceTypeMismatchException
- If resource bundle has a type mismatch.getIntVector()
,
getInt()
public int[] getIntVector()
MissingResourceException
- If resource bundle is missing.UResourceTypeMismatchException
- If resource bundle has a type mismatch.getBinary()
,
getInt()
public int getInt()
MissingResourceException
- If resource bundle is missing.UResourceTypeMismatchException
- If resource bundle type mismatch.getIntVector()
,
getBinary()
public int getUInt()
MissingResourceException
- If resource bundle is missing.UResourceTypeMismatchException
- If resource bundle type mismatch.getIntVector()
,
getBinary()
public UResourceBundle get(String aKey)
aKey
- a key associated with the wanted resourceMissingResourceException
- If resource bundle is missing.@Deprecated protected UResourceBundle findTopLevel(String aKey)
aKey
- the key associated with the wanted resourceget(String)
public String getString(int index)
index
- an index to the wanted string.IndexOutOfBoundsException
- If the index value is out of bounds of accepted values.UResourceTypeMismatchException
- If resource bundle type mismatch.public UResourceBundle get(int index)
index
- an index to the wanted resource.IndexOutOfBoundsException
- If the index value is out of bounds of accepted values.MissingResourceException
- If the resource bundle is missing.@Deprecated protected UResourceBundle findTopLevel(int index)
index
- the index of the resourceget(int)
public Enumeration<String> getKeys()
getKeys
in class ResourceBundle
@Deprecated public Set<String> keySet()
keySet
in class ResourceBundle
@Deprecated protected Set<String> handleKeySet()
handleKeySet
in class ResourceBundle
public int getSize()
public int getType()
INT
, ARRAY
,
BINARY
, INT_VECTOR
,
STRING
, TABLE
.public VersionInfo getVersion()
public UResourceBundleIterator getIterator()
public String getKey()
protected UResourceBundle handleGet(String aKey, HashMap<String,String> aliasesVisited, UResourceBundle requested)
aKey
- the key string of the resource to be fetchedaliasesVisited
- hashtable object to hold references of resources already seenrequested
- 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.protected UResourceBundle handleGet(int index, HashMap<String,String> aliasesVisited, UResourceBundle requested)
index
- the index of the resource to be fetchedaliasesVisited
- hashtable object to hold references of resources already seenrequested
- 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.protected String[] handleGetStringArray()
protected Enumeration<String> handleGetKeys()
protected Object handleGetObject(String aKey)
handleGetObject
in class ResourceBundle
@Deprecated protected boolean isTopLevelResource()
Copyright © 2016 Unicode, Inc. and others.