org.sakaiproject.util.java
Class ResourceLoader

java.lang.Object
  extended byorg.sakaiproject.util.java.DummyMap
      extended byorg.sakaiproject.util.java.ResourceLoader
All Implemented Interfaces:
Map

public class ResourceLoader
extends org.sakaiproject.util.java.DummyMap
implements Map

ResourceLoader provides an alternate implementation of org.util.ResourceBundle, dynamically selecting the prefered locale from either the user's session or from the user's sakai preferences

Version:
$Revision: $
Author:
Sugiura, Tatsuki (University of Nagoya)

Nested Class Summary
 
Nested classes inherited from class java.util.Map
Map.Entry
 
Field Summary
protected  String baseName
           
protected  Hashtable bundles
           
static String LOCALE_KEY
          Preferences key for user's regional language locale
protected static org.apache.commons.logging.Log M_log
           
static String SERVICE_NAME
          This string is used by the UserPrefsTool (imitating a service)
 
Constructor Summary
ResourceLoader()
          Default constructor (does nothing)
ResourceLoader(String name)
          Constructor: set baseName
 
Method Summary
 void clear()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set entrySet()
           
 Object get(Object key)
          Return (generic object) value for specified property in current locale specific ResourceBundle
protected  ResourceBundle getBundle()
          Return ResourceBundle for user's preferred locale
protected  Map getBundleAsMap()
           
 Object getFormattedMessage(Object key, Object[] args)
           
 Locale getLocale()
          Return user's prefered locale First: return locale from Sakai user preferences, if available Second: return locale from user session, if available Last: return system default locale
protected  Session getSession()
          Return user's current session
 String getString(String key)
          Return string value for specified property in current locale specific ResourceBundle
 boolean isEmpty()
           
 Set keySet()
           
protected  ResourceBundle loadBundle(Locale loc)
          Return ResourceBundle for specified locale
 void purgeCache()
          Clear bundles hashmap
 Object put(Object arg0, Object arg1)
           
 void putAll(Map arg0)
           
 Object remove(Object key)
           
 void setBaseName(String name)
          Set baseName
protected  void setBundle(Locale loc, ResourceBundle bundle)
          Add loc (key) and bundle (value) to this.bundles hash
 int size()
           
 Collection values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, equals, hashCode, isEmpty, put, putAll, remove, size
 

Field Detail

SERVICE_NAME

public static final String SERVICE_NAME
This string is used by the UserPrefsTool (imitating a service)


LOCALE_KEY

public static final String LOCALE_KEY
Preferences key for user's regional language locale

See Also:
Constant Field Values

M_log

protected static org.apache.commons.logging.Log M_log

baseName

protected String baseName

bundles

protected Hashtable bundles
Constructor Detail

ResourceLoader

public ResourceLoader()
Default constructor (does nothing)


ResourceLoader

public ResourceLoader(String name)
Constructor: set baseName

Parameters:
name - default ResourceBundle base filename
Method Detail

setBaseName

public void setBaseName(String name)
Set baseName

Parameters:
name - default ResourceBundle base filename

setBundle

protected void setBundle(Locale loc,
                         ResourceBundle bundle)
Add loc (key) and bundle (value) to this.bundles hash

Parameters:
loc - Language/Region Locale
bundle - properties bundle

getBundle

protected ResourceBundle getBundle()
Return ResourceBundle for user's preferred locale

Returns:
user's ResourceBundle object

getSession

protected Session getSession()
Return user's current session

Returns:
user's Session object

purgeCache

public void purgeCache()
Clear bundles hashmap


getLocale

public Locale getLocale()
Return user's prefered locale First: return locale from Sakai user preferences, if available Second: return locale from user session, if available Last: return system default locale

Returns:
user's Locale object

loadBundle

protected ResourceBundle loadBundle(Locale loc)
Return ResourceBundle for specified locale

Returns:
locale specific ResourceBundle

getString

public String getString(String key)
Return string value for specified property in current locale specific ResourceBundle

Parameters:
key - property key to look up in current ResourceBundle
Returns:
String value for specified property key

get

public Object get(Object key)
Return (generic object) value for specified property in current locale specific ResourceBundle

Specified by:
get in interface Map
Parameters:
key - property key to look up in current ResourceBundle
Returns:
value for specified property key

getFormattedMessage

public Object getFormattedMessage(Object key,
                                  Object[] args)

keySet

public Set keySet()
Specified by:
keySet in interface Map

values

public Collection values()
Specified by:
values in interface Map

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map

getBundleAsMap

protected Map getBundleAsMap()

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map

put

public Object put(Object arg0,
                  Object arg1)
Specified by:
put in interface Map

remove

public Object remove(Object key)
Specified by:
remove in interface Map

putAll

public void putAll(Map arg0)
Specified by:
putAll in interface Map

clear

public void clear()
Specified by:
clear in interface Map

size

public int size()
Specified by:
size in interface Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map