Package org.apache.pivot.util
Class Resources
- java.lang.Object
-
- org.apache.pivot.util.Resources
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.String>
,Dictionary<java.lang.String,java.lang.Object>
public class Resources extends java.lang.Object implements Dictionary<java.lang.String,java.lang.Object>, java.lang.Iterable<java.lang.String>
Represents a set of localizable resources.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.pivot.collections.Dictionary
Dictionary.Pair<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description static java.nio.charset.Charset
DEFAULT_CHARSET
-
Constructor Summary
Constructors Constructor Description Resources(java.lang.String baseName)
Resources(java.lang.String baseName, java.nio.charset.Charset charset)
Resources(java.lang.String baseName, java.util.Locale locale)
Resources(Resources parent, java.lang.String baseName)
Resources(Resources parent, java.lang.String baseName, java.nio.charset.Charset charset)
Resources(Resources parent, java.lang.String baseName, java.util.Locale locale)
Resources(Resources parent, java.lang.String baseName, java.util.Locale locale, java.nio.charset.Charset charset)
Creates a new resource bundle.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(java.lang.String key)
Tests the existence of a key in the dictionary.java.lang.Object
get(java.lang.String key)
Retrieves the value for the given key.java.lang.String
getBaseName()
java.nio.charset.Charset
getCharset()
java.util.Locale
getLocale()
Resources
getParent()
java.lang.String
getString(java.lang.String key)
Convenience method for the common case that the resource is a string (to avoid using casts).java.util.Iterator<java.lang.String>
iterator()
java.lang.Object
put(java.lang.String key, java.lang.Object value)
Sets the value of the given key, creating a new entry or replacing the existing value.java.lang.Object
remove(java.lang.String key)
Removes a key/value pair from the map.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.pivot.collections.Dictionary
containsAny, copy, getBoolean, getBoolean, getColor, getFirst, getFont, getInt, getInt, getString, putAll
-
-
-
-
Constructor Detail
-
Resources
public Resources(java.lang.String baseName) throws java.io.IOException, SerializationException
- Throws:
java.io.IOException
SerializationException
-
Resources
public Resources(Resources parent, java.lang.String baseName) throws java.io.IOException, SerializationException
- Throws:
java.io.IOException
SerializationException
-
Resources
public Resources(java.lang.String baseName, java.util.Locale locale) throws java.io.IOException, SerializationException
- Throws:
java.io.IOException
SerializationException
-
Resources
public Resources(Resources parent, java.lang.String baseName, java.util.Locale locale) throws java.io.IOException, SerializationException
- Throws:
java.io.IOException
SerializationException
-
Resources
public Resources(java.lang.String baseName, java.nio.charset.Charset charset) throws java.io.IOException, SerializationException
- Throws:
java.io.IOException
SerializationException
-
Resources
public Resources(Resources parent, java.lang.String baseName, java.nio.charset.Charset charset) throws java.io.IOException, SerializationException
- Throws:
java.io.IOException
SerializationException
-
Resources
public Resources(Resources parent, java.lang.String baseName, java.util.Locale locale, java.nio.charset.Charset charset) throws java.io.IOException, SerializationException
Creates a new resource bundle.- Parameters:
parent
- The parent resource defer to if a resource cannot be found in this instance or null.baseName
- The base name of this resource as a fully qualified class name.locale
- The locale to use when reading this resource.charset
- The character encoding to use when reading this resource.- Throws:
java.io.IOException
- If there is a problem when reading the resource.SerializationException
- If there is a problem deserializing the resource from its JSON format.java.lang.IllegalArgumentException
- If baseName or locale or charset is null.java.util.MissingResourceException
- If no resource for the specified base name can be found.
-
-
Method Detail
-
getParent
public Resources getParent()
-
getBaseName
public java.lang.String getBaseName()
-
getLocale
public java.util.Locale getLocale()
-
getCharset
public java.nio.charset.Charset getCharset()
-
getString
public java.lang.String getString(java.lang.String key)
Convenience method for the common case that the resource is a string (to avoid using casts).- Specified by:
getString
in interfaceDictionary<java.lang.String,java.lang.Object>
- Parameters:
key
- The key for the string resource.- Returns:
- The string value for that key, if any, or
null
if the key/value pair doesn't exist. If the resource object is not aString
then theObject.toString()
method will be called to return the value.
-
get
public java.lang.Object get(java.lang.String key)
Description copied from interface:Dictionary
Retrieves the value for the given key.- Specified by:
get
in interfaceDictionary<java.lang.String,java.lang.Object>
- Parameters:
key
- The key whose value is to be returned.- Returns:
- The value corresponding to
key
, or null if the key does not exist. Will also return null if the key refers to a null value. UseDictionary.containsKey(K)
to distinguish between these two cases.
-
put
@UnsupportedOperation public java.lang.Object put(java.lang.String key, java.lang.Object value)
Description copied from interface:Dictionary
Sets the value of the given key, creating a new entry or replacing the existing value.- Specified by:
put
in interfaceDictionary<java.lang.String,java.lang.Object>
- Parameters:
key
- The key whose value is to be set.value
- The value to be associated with the given key.- Returns:
- The value previously associated with the key.
-
remove
@UnsupportedOperation public java.lang.Object remove(java.lang.String key)
Description copied from interface:Dictionary
Removes a key/value pair from the map.- Specified by:
remove
in interfaceDictionary<java.lang.String,java.lang.Object>
- Parameters:
key
- The key whose mapping is to be removed.- Returns:
- The value that was removed.
-
containsKey
public boolean containsKey(java.lang.String key)
Description copied from interface:Dictionary
Tests the existence of a key in the dictionary.- Specified by:
containsKey
in interfaceDictionary<java.lang.String,java.lang.Object>
- Parameters:
key
- The key whose presence in the dictionary is to be tested.- Returns:
true
if the key exists in the dictionary;false
, otherwise.
-
iterator
public java.util.Iterator<java.lang.String> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.String>
-
-