pivot.util
Class Resources

java.lang.Object
  extended by 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>

Reads a JSON resource at baseName using ClassLoader.getResourceAsStream(String). It applies localization to the resource using a method similar to that of ResourceBundle in that it loads the base resource, then applies a country specified resource over-writing the values in the base using the country specified. It then does the same for country/language specific.

Author:
brindy, gbrown
See Also:
ResourceBundle

Constructor Summary
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(java.lang.String baseName, java.util.Locale locale, java.nio.charset.Charset charset)
          Creates a new resource bundle.
Resources(java.lang.String baseName, java.util.Locale locale, java.lang.String charsetName)
           
Resources(java.lang.String baseName, java.lang.String charsetName)
           
 
Method Summary
 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.util.Locale getLocale()
           
 boolean isEmpty()
          Tests the emptiness of the dictionary.
 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
 

Constructor Detail

Resources

public Resources(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(java.lang.String baseName,
                 java.lang.String charsetName)
          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(java.lang.String baseName,
                 java.util.Locale locale,
                 java.lang.String charsetName)
          throws java.io.IOException,
                 SerializationException
Throws:
java.io.IOException
SerializationException

Resources

public Resources(java.lang.String baseName,
                 java.util.Locale locale,
                 java.nio.charset.Charset charset)
          throws java.io.IOException,
                 SerializationException
Creates a new resource bundle.

Parameters:
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 is null.
java.util.MissingResourceException - If no resource for the specified base name can be found.
Method Detail

getBaseName

public java.lang.String getBaseName()

getLocale

public java.util.Locale getLocale()

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 interface Dictionary<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. Use containsKey() to distinguish between these two cases.

put

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 interface Dictionary<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.

remove

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 interface Dictionary<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 interface Dictionary<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.

isEmpty

public boolean isEmpty()
Description copied from interface: Dictionary
Tests the emptiness of the dictionary.

Specified by:
isEmpty in interface Dictionary<java.lang.String,java.lang.Object>
Returns:
true if the dictionary contains no keys; false, otherwise.

iterator

public java.util.Iterator<java.lang.String> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.lang.String>