org.apache.pivot.util
Class Resources

java.lang.Object
  extended by org.apache.pivot.util.Resources
All Implemented Interfaces:
Iterable<String>, Dictionary<String,Object>

public class Resources
extends Object
implements Dictionary<String,Object>, Iterable<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
static String DEFAULT_CHARSET_NAME
           
 
Constructor Summary
Resources(Resources parent, String baseName)
           
Resources(Resources parent, String baseName, Charset charset)
           
Resources(Resources parent, String baseName, Locale locale)
           
Resources(Resources parent, String baseName, Locale locale, Charset charset)
          Creates a new resource bundle.
Resources(String baseName)
           
Resources(String baseName, Charset charset)
           
Resources(String baseName, Locale locale)
           
 
Method Summary
 boolean containsKey(String key)
          Tests the existence of a key in the dictionary.
 Object get(String key)
          Retrieves the value for the given key.
 String getBaseName()
           
 Boolean getBoolean(String key)
           
 Charset getCharset()
           
 Double getDouble(String key)
           
 Float getFloat(String key)
           
 Integer getInteger(String key)
           
 List<?> getList(String key)
           
 Locale getLocale()
           
 Long getLong(String key)
           
 Map<String,?> getMap(String key)
           
 Number getNumber(String key)
           
 Resources getParent()
           
 Short getShort(String key)
           
 String getString(String key)
           
 String getString(String key, String... args)
          Gets a resource string with positional token substitution.
 Iterator<String> iterator()
           
 Object put(String key, Object value)
          Sets the value of the given key, creating a new entry or replacing the existing value.
 Object remove(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
 

Field Detail

DEFAULT_CHARSET_NAME

public static final String DEFAULT_CHARSET_NAME
See Also:
Constant Field Values
Constructor Detail

Resources

public Resources(String baseName)
          throws IOException,
                 SerializationException
Throws:
IOException
SerializationException

Resources

public Resources(Resources parent,
                 String baseName)
          throws IOException,
                 SerializationException
Throws:
IOException
SerializationException

Resources

public Resources(String baseName,
                 Locale locale)
          throws IOException,
                 SerializationException
Throws:
IOException
SerializationException

Resources

public Resources(Resources parent,
                 String baseName,
                 Locale locale)
          throws IOException,
                 SerializationException
Throws:
IOException
SerializationException

Resources

public Resources(String baseName,
                 Charset charset)
          throws IOException,
                 SerializationException
Throws:
IOException
SerializationException

Resources

public Resources(Resources parent,
                 String baseName,
                 Charset charset)
          throws IOException,
                 SerializationException
Throws:
IOException
SerializationException

Resources

public Resources(Resources parent,
                 String baseName,
                 Locale locale,
                 Charset charset)
          throws 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:
IOException - If there is a problem when reading the resource.
SerializationException - If there is a problem deserializing the resource from its JSON format.
IllegalArgumentException - If baseName or locale or charset is null.
MissingResourceException - If no resource for the specified base name can be found.
Method Detail

getParent

public Resources getParent()

getBaseName

public String getBaseName()

getLocale

public Locale getLocale()

getCharset

public Charset getCharset()

get

public Object get(String key)
Description copied from interface: Dictionary
Retrieves the value for the given key.

Specified by:
get in interface Dictionary<String,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. Use containsKey() to distinguish between these two cases.

getString

public String getString(String key)

getString

public String getString(String key,
                        String... args)
Gets a resource string with positional token substitution. Tokens of the form {N} (where N is the variable argument index) will be substituted with their corresponding String in the variable arguments array.

For example, if resource string foo were defined to be "{0} knows {1}, and {1} knows {0}.", then calling getString("foo", "Jane", "John") would yield the string "Jane knows John, and John knows Jane."

Parameters:
key - The resource key
args - Arguments referenced within the value of the resource string
Returns:
The resource string after positional substitution has been performed

getNumber

public Number getNumber(String key)

getShort

public Short getShort(String key)

getInteger

public Integer getInteger(String key)

getLong

public Long getLong(String key)

getFloat

public Float getFloat(String key)

getDouble

public Double getDouble(String key)

getBoolean

public Boolean getBoolean(String key)

getList

public List<?> getList(String key)

getMap

public Map<String,?> getMap(String key)

put

public Object put(String key,
                  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 interface Dictionary<String,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

public Object remove(String key)
Description copied from interface: Dictionary
Removes a key/value pair from the map.

Specified by:
remove in interface Dictionary<String,Object>
Parameters:
key - The key whose mapping is to be removed.
Returns:
The value that was removed.

containsKey

public boolean containsKey(String key)
Description copied from interface: Dictionary
Tests the existence of a key in the dictionary.

Specified by:
containsKey in interface Dictionary<String,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 Iterator<String> iterator()
Specified by:
iterator in interface Iterable<String>