Class UResourceBundle
- java.lang.Object
-
- java.util.ResourceBundle
-
- com.ibm.icu.util.UResourceBundle
-
public abstract class UResourceBundle extends java.util.ResourceBundle
.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
-
-
Field Summary
Fields Modifier and Type Field Description static int
ARRAY
Resource type constant for arrays of resources.static int
BINARY
Resource type constant for binary data.static int
INT
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
Resource type constant for "no resource".static int
STRING
Resource type constant for strings.static int
TABLE
Resource type constant for tables of key-value pairs.
-
Constructor Summary
Constructors Constructor Description UResourceBundle()
Sole constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected UResourceBundle
findTopLevel(int index)
Deprecated.This API is ICU internal only.protected UResourceBundle
findTopLevel(java.lang.String aKey)
Deprecated.This API is ICU internal only.UResourceBundle
get(int index)
Returns the resource in a given resource at the specified index.UResourceBundle
get(java.lang.String aKey)
Returns a resource in a given resource that has a given key.protected abstract java.lang.String
getBaseName()
Returns the base name of the resource bundlejava.nio.ByteBuffer
getBinary()
Returns a binary data item from a binary resource, as a read-only ByteBuffer.byte[]
getBinary(byte[] ba)
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(ULocale locale)
Creates a UResourceBundle for the locale specified, from which users can extract resources by using their corresponding keys.static UResourceBundle
getBundleInstance(java.lang.String baseName)
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(java.lang.String baseName, ULocale locale)
Creates a UResourceBundle, from which users can extract resources by using their corresponding keys.static UResourceBundle
getBundleInstance(java.lang.String baseName, ULocale locale, java.lang.ClassLoader loader)
Creates a UResourceBundle, from which users can extract resources by using their corresponding keys.
Note: Please use this API for loading non-ICU resources.static UResourceBundle
getBundleInstance(java.lang.String baseName, java.lang.String localeName)
Creates a resource bundle using the specified base name and locale.static UResourceBundle
getBundleInstance(java.lang.String baseName, java.lang.String localeName, java.lang.ClassLoader root)
Creates a resource bundle using the specified base name, locale, and class root.protected static UResourceBundle
getBundleInstance(java.lang.String baseName, java.lang.String localeName, java.lang.ClassLoader root, boolean disableFallback)
Creates a resource bundle using the specified base name, locale, and class root.static UResourceBundle
getBundleInstance(java.lang.String baseName, java.util.Locale locale)
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(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader loader)
Creates a UResourceBundle for the specified locale and specified base name, from which users can extract resources by using their corresponding keys.int
getInt()
Returns a signed integer from a resource.int[]
getIntVector()
Returns a 32 bit integer array from a resource.UResourceBundleIterator
getIterator()
Returns the iterator which iterates over this resource bundlejava.lang.String
getKey()
Returns the key associated with a given resource.java.util.Enumeration<java.lang.String>
getKeys()
Returns the keys in this bundle as an enumerationjava.util.Locale
getLocale()
Returns the locale of this bundleprotected abstract java.lang.String
getLocaleID()
Returns the localeIDprotected abstract UResourceBundle
getParent()
Returns the parent bundleint
getSize()
Returns the size of a resource.java.lang.String
getString()
Returns a string from a string resource typejava.lang.String
getString(int index)
Returns the string in a given resource at the specified index.java.lang.String[]
getStringArray()
Returns a string array from a array resource typeint
getType()
Returns the type of a resource.int
getUInt()
Returns a unsigned integer from a resource.abstract ULocale
getULocale()
Returns the RFC 3066 conformant locale id of this resource bundle.VersionInfo
getVersion()
Return the version number associated with this UResourceBundle as an VersionInfo object.protected UResourceBundle
handleGet(int index, java.util.HashMap<java.lang.String,java.lang.String> aliasesVisited, UResourceBundle requested)
Actual worker method for fetching a resource based on the given index.protected UResourceBundle
handleGet(java.lang.String aKey, java.util.HashMap<java.lang.String,java.lang.String> aliasesVisited, UResourceBundle requested)
Actual worker method for fetching a resource based on the given key.protected java.util.Enumeration<java.lang.String>
handleGetKeys()
Actual worker method for fetching the keys of resources contained in the resource.protected java.lang.Object
handleGetObject(java.lang.String aKey)
protected java.lang.String[]
handleGetStringArray()
Actual worker method for fetching the array of strings in a resource.protected java.util.Set<java.lang.String>
handleKeySet()
Deprecated.This API is ICU internal only.protected static UResourceBundle
instantiateBundle(java.lang.String baseName, java.lang.String localeName, java.lang.ClassLoader root, boolean disableFallback)
Loads a new resource bundle for the given base name, locale and class loader.protected boolean
isTopLevelResource()
Deprecated.This API is ICU internal only.java.util.Set<java.lang.String>
keySet()
Deprecated.This API is ICU internal only.
-
-
-
Field Detail
-
NONE
public static final int NONE
Resource type constant for "no resource".- See Also:
- Constant Field Values
-
STRING
public static final int STRING
Resource type constant for strings.- See Also:
- Constant Field Values
-
BINARY
public static final int BINARY
Resource type constant for binary data.- See Also:
- Constant Field Values
-
TABLE
public static final int TABLE
Resource type constant for tables of key-value pairs.- See Also:
- Constant Field Values
-
INT
public static final int INT
Resource type constant for a single 28-bit integer, interpreted as signed or unsigned by the getInt() function.- See Also:
getInt()
, Constant Field Values
-
ARRAY
public static final int ARRAY
Resource type constant for arrays of resources.- See Also:
- Constant Field Values
-
INT_VECTOR
public static final int INT_VECTOR
Resource type constant for vectors of 32-bit integers.- See Also:
getIntVector()
, Constant Field Values
-
-
Method Detail
-
getBundleInstance
public static UResourceBundle getBundleInstance(java.lang.String baseName, java.lang.String localeName)
Creates a resource bundle using the specified base name and locale. ICU_DATA_CLASS is used as the default root.- Parameters:
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 desired- Returns:
- a resource bundle for the given base name and locale
- Throws:
java.util.MissingResourceException
- If no resource bundle for the specified base name can be found
-
getBundleInstance
public static UResourceBundle getBundleInstance(java.lang.String baseName, java.lang.String localeName, java.lang.ClassLoader root)
Creates a resource bundle using the specified base name, locale, and class root.- Parameters:
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 bundle- Returns:
- a resource bundle for the given base name and locale
- Throws:
java.util.MissingResourceException
- If no resource bundle for the specified base name can be found
-
getBundleInstance
protected static UResourceBundle getBundleInstance(java.lang.String baseName, java.lang.String localeName, java.lang.ClassLoader root, boolean disableFallback)
Creates a resource bundle using the specified base name, locale, and class root.- Parameters:
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 inheritence. If true the fallback chain will not be built.- Returns:
- a resource bundle for the given base name and locale
- Throws:
java.util.MissingResourceException
- if no resource bundle for the specified base name can be found
-
getBundleInstance
public static UResourceBundle getBundleInstance(ULocale locale)
Creates a UResourceBundle for the locale specified, from which users can extract resources by using their corresponding keys.- Parameters:
locale
- specifies the locale for which we want to open the resource. If null the bundle for default locale is opened.- Returns:
- a resource bundle for the given locale
-
getBundleInstance
public static UResourceBundle getBundleInstance(java.lang.String baseName)
Creates a UResourceBundle for the default locale and specified base name, from which users can extract resources by using their corresponding keys.- Parameters:
baseName
- string containing the name of the data package. If null the default ICU package name is used.- Returns:
- a resource bundle for the given base name and default locale
-
getBundleInstance
public static UResourceBundle getBundleInstance(java.lang.String baseName, java.util.Locale locale)
Creates a UResourceBundle for the specified locale and specified base name, from which users can extract resources by using their corresponding keys.- Parameters:
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.- Returns:
- a resource bundle for the given base name and locale
-
getBundleInstance
public static UResourceBundle getBundleInstance(java.lang.String baseName, ULocale locale)
Creates a UResourceBundle, from which users can extract resources by using their corresponding keys.- Parameters:
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.- Returns:
- a resource bundle for the given base name and locale
-
getBundleInstance
public static UResourceBundle getBundleInstance(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader loader)
Creates a UResourceBundle for the specified locale and specified base name, from which users can extract resources by using their corresponding keys.- Parameters:
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 use- Returns:
- a resource bundle for the given base name and locale
-
getBundleInstance
public static UResourceBundle getBundleInstance(java.lang.String baseName, ULocale locale, java.lang.ClassLoader loader)
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- Parameters:
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 use- Returns:
- a resource bundle for the given base name and locale
-
getULocale
public abstract ULocale getULocale()
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.- Returns:
- the locale of this resource bundle
-
getLocaleID
protected abstract java.lang.String getLocaleID()
Returns the localeID- Returns:
- The string representation of the localeID
-
getBaseName
protected abstract java.lang.String getBaseName()
Returns the base name of the resource bundle- Returns:
- The string representation of the base name
-
getParent
protected abstract UResourceBundle getParent()
Returns the parent bundle- Returns:
- The parent bundle
-
getLocale
public java.util.Locale getLocale()
Returns the locale of this bundle- Overrides:
getLocale
in classjava.util.ResourceBundle
- Returns:
- the locale of this resource bundle
-
instantiateBundle
protected static UResourceBundle instantiateBundle(java.lang.String baseName, java.lang.String localeName, java.lang.ClassLoader root, boolean disableFallback)
Loads a new resource bundle for the given base name, locale and class loader. Optionally will disable loading of fallback bundles.- Parameters:
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 chain- Returns:
- a resource bundle for the given base name and locale
- Throws:
java.util.MissingResourceException
- If no resource bundle for the specified base name can be found
-
getBinary
public java.nio.ByteBuffer getBinary()
Returns a binary data item from a binary resource, as a read-only ByteBuffer.- Returns:
- a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
- Throws:
java.util.MissingResourceException
- If no resource bundle can be found.UResourceTypeMismatchException
- If the resource has a type mismatch.- See Also:
getIntVector()
,getInt()
-
getString
public java.lang.String getString()
Returns a string from a string resource type- Returns:
- a string
- Throws:
java.util.MissingResourceException
- If resource bundle is missing.UResourceTypeMismatchException
- If resource bundle has a type mismatch.- See Also:
getBinary()
,getIntVector()
,getInt()
-
getStringArray
public java.lang.String[] getStringArray()
Returns a string array from a array resource type- Returns:
- a string
- Throws:
java.util.MissingResourceException
- If resource bundle is missing.UResourceTypeMismatchException
- If resource bundle has a type mismatch.- See Also:
getString()
,getIntVector()
-
getBinary
public byte[] getBinary(byte[] ba)
Returns a binary data from a binary resource, as a byte array with a copy of the bytes from the resource bundle.- Parameters:
ba
- The byte array to write the bytes to. A null variable is OK.- Returns:
- an array of bytes containing the binary data from the resource.
- Throws:
java.util.MissingResourceException
- If resource bundle is missing.UResourceTypeMismatchException
- If resource bundle has a type mismatch.- See Also:
getIntVector()
,getInt()
-
getIntVector
public int[] getIntVector()
Returns a 32 bit integer array from a resource.- Returns:
- a pointer to a chunk of unsigned bytes which live in a memory mapped/DLL file.
- Throws:
java.util.MissingResourceException
- If resource bundle is missing.UResourceTypeMismatchException
- If resource bundle has a type mismatch.- See Also:
getBinary()
,getInt()
-
getInt
public int getInt()
Returns a signed integer from a resource.- Returns:
- an integer value
- Throws:
java.util.MissingResourceException
- If resource bundle is missing.UResourceTypeMismatchException
- If resource bundle type mismatch.- See Also:
getIntVector()
,getBinary()
-
getUInt
public int getUInt()
Returns a unsigned integer from a resource. This integer is originally 28 bit and the sign gets propagated.- Returns:
- an integer value
- Throws:
java.util.MissingResourceException
- If resource bundle is missing.UResourceTypeMismatchException
- If resource bundle type mismatch.- See Also:
getIntVector()
,getBinary()
-
get
public UResourceBundle get(java.lang.String aKey)
Returns a resource in a given resource that has a given key.- Parameters:
aKey
- a key associated with the wanted resource- Returns:
- a resource bundle object representing the resource
- Throws:
java.util.MissingResourceException
- If resource bundle is missing.
-
findTopLevel
@Deprecated protected UResourceBundle findTopLevel(java.lang.String aKey)
Deprecated.This API is ICU internal only.Returns a resource in a given resource that has a given key, or null if the resource is not found.- Parameters:
aKey
- the key associated with the wanted resource- Returns:
- the resource, or null
- See Also:
get(String)
-
getString
public java.lang.String getString(int index)
Returns the string in a given resource at the specified index.- Parameters:
index
- an index to the wanted string.- Returns:
- a string which lives in the resource.
- Throws:
java.lang.IndexOutOfBoundsException
- If the index value is out of bounds of accepted values.UResourceTypeMismatchException
- If resource bundle type mismatch.
-
get
public UResourceBundle get(int index)
Returns the resource in a given resource at the specified index.- Parameters:
index
- an index to the wanted resource.- Returns:
- the sub resource UResourceBundle object
- Throws:
java.lang.IndexOutOfBoundsException
- If the index value is out of bounds of accepted values.java.util.MissingResourceException
- If the resource bundle is missing.
-
findTopLevel
@Deprecated protected UResourceBundle findTopLevel(int index)
Deprecated.This API is ICU internal only.Returns a resource in a given resource that has a given index, or null if the resource is not found.- Parameters:
index
- the index of the resource- Returns:
- the resource, or null
- See Also:
get(int)
-
getKeys
public java.util.Enumeration<java.lang.String> getKeys()
Returns the keys in this bundle as an enumeration- Specified by:
getKeys
in classjava.util.ResourceBundle
- Returns:
- an enumeration containing key strings, which is empty if this is not a bundle or a table resource
-
keySet
@Deprecated public java.util.Set<java.lang.String> keySet()
Deprecated.This API is ICU internal only.Returns a Set of all keys contained in this ResourceBundle and its parent bundles.- Overrides:
keySet
in classjava.util.ResourceBundle
- Returns:
- a Set of all keys contained in this ResourceBundle and its parent bundles, which is empty if this is not a bundle or a table resource
-
handleKeySet
@Deprecated protected java.util.Set<java.lang.String> handleKeySet()
Deprecated.This API is ICU internal only.Returns a Set of the keys contained only in this ResourceBundle. This does not include further keys from parent bundles.- Overrides:
handleKeySet
in classjava.util.ResourceBundle
- Returns:
- a Set of the keys contained only in this ResourceBundle, which is empty if this is not a bundle or a table resource
-
getSize
public int getSize()
Returns the size of a resource. Size for scalar types is always 1, and for vector/table types is the number of child resources.
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.- Returns:
- number of resources in a given resource.
-
getType
public int getType()
- Returns:
- type of the given resource.
-
getVersion
public VersionInfo getVersion()
Return the version number associated with this UResourceBundle as an VersionInfo object.- Returns:
- VersionInfo object containing the version of the bundle
-
getIterator
public UResourceBundleIterator getIterator()
Returns the iterator which iterates over this resource bundle- Returns:
- UResourceBundleIterator that iterates over the resources in the bundle
-
getKey
public java.lang.String getKey()
Returns the key associated with a given resource. Not all the resources have a key - only those that are members of a table.- Returns:
- a key associated to this resource, or null if it doesn't have a key
-
handleGet
protected UResourceBundle handleGet(java.lang.String aKey, java.util.HashMap<java.lang.String,java.lang.String> aliasesVisited, UResourceBundle requested)
Actual worker method for fetching a resource based on the given key. Sub classes must override this method if they support resources with keys.- Parameters:
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.- Returns:
- UResourceBundle a resource associated with the key
-
handleGet
protected UResourceBundle handleGet(int index, java.util.HashMap<java.lang.String,java.lang.String> aliasesVisited, UResourceBundle requested)
Actual worker method for fetching a resource based on the given index. Sub classes must override this method if they support arrays of resources.- Parameters:
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.- Returns:
- UResourceBundle a resource associated with the index
-
handleGetStringArray
protected java.lang.String[] handleGetStringArray()
Actual worker method for fetching the array of strings in a resource. Sub classes must override this method if they support arrays of strings.- Returns:
- String[] An array of strings containing strings
-
handleGetKeys
protected java.util.Enumeration<java.lang.String> handleGetKeys()
Actual worker method for fetching the keys of resources contained in the resource. Sub classes must override this method if they support keys and associated resources.- Returns:
- Enumeration An enumeration of all the keys in this resource.
-
handleGetObject
protected java.lang.Object handleGetObject(java.lang.String aKey)
- Specified by:
handleGetObject
in classjava.util.ResourceBundle
-
isTopLevelResource
@Deprecated protected boolean isTopLevelResource()
Deprecated.This API is ICU internal only.Is this a top-level resource, that is, a whole bundle?- Returns:
- true if this is a top-level resource
-
-