net.sf.click.util
Class MessagesMap

java.lang.Object
  extended bynet.sf.click.util.MessagesMap
All Implemented Interfaces:
Map

public class MessagesMap
extends Object
implements Map

Provides a localized read only messages Map for Page and Control classes.

A MessagesMap instance is available in each Velocity page using the name "messages".

For example suppose you have a localized page title, which is stored in the Page's properties file. You can access page "title" message in your page template via:

 $messages.title 
This is roughly equivalent to making the call:
 public void onInit() {
    ..
    addModel("title", getMessage("title");
 } 
Please note if the specified message does not exist in your Page's properties file, or if the Page does not have a properties file, then a MissingResourceException will be thrown.

The ClickServlet adds a MessagesMap instance to the Velocity Context before it is merged with the page template.

Author:
Malcolm.Edgar

Nested Class Summary
 
Nested classes inherited from class java.util.Map
Map.Entry
 
Field Summary
protected  Class baseClass
          The base class.
protected static Object CACHE_LOAD_LOCK
          The cache key set load lock.
protected  String globalBaseName
          The class global resource bundle base name.
protected  Locale locale
          The resource bundle locale.
protected  Map messages
          The map of localized messages.
protected static Map MESSAGES_CACHE
          Cache of messages keyed by bundleName + Locale name.
protected static Set NOT_FOUND_CACHE
          Cache of resource bundle and locales which were not found.
 
Constructor Summary
MessagesMap(Class baseClass, String globalResource)
          Create a resource bundle messages Map adaptor for the given object's class resource bundle, the global resource bundle and Context.
 
Method Summary
 void clear()
          This method is not supported and will throw UnsupportedOperationException if invoked.
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set entrySet()
           
 Object get(Object key)
          Return localized resource message for the given key.
 boolean isEmpty()
           
 Set keySet()
           
 Object put(Object key, Object value)
          This method is not supported and will throw UnsupportedOperationException if invoked.
 void putAll(Map map)
          This method is not supported and will throw UnsupportedOperationException if invoked.
 Object remove(Object key)
          This method is not supported and will throw UnsupportedOperationException if invoked.
 int size()
           
 String toString()
           
 Collection values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

NOT_FOUND_CACHE

protected static final Set NOT_FOUND_CACHE
Cache of resource bundle and locales which were not found.


MESSAGES_CACHE

protected static final Map MESSAGES_CACHE
Cache of messages keyed by bundleName + Locale name.


CACHE_LOAD_LOCK

protected static final Object CACHE_LOAD_LOCK
The cache key set load lock.


baseClass

protected final Class baseClass
The base class.


globalBaseName

protected final String globalBaseName
The class global resource bundle base name.


messages

protected Map messages
The map of localized messages.


locale

protected final Locale locale
The resource bundle locale.

Constructor Detail

MessagesMap

public MessagesMap(Class baseClass,
                   String globalResource)
Create a resource bundle messages Map adaptor for the given object's class resource bundle, the global resource bundle and Context.

Messages located in the object's resource bundle will override any messages defined in the global resource bundle.

Parameters:
baseClass - the target class
globalResource - the global resource bundle name
Method Detail

size

public int size()
Specified by:
size in interface Map
See Also:
Map.size()

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map
See Also:
Map.isEmpty()

containsKey

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

containsValue

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

get

public Object get(Object key)
Return localized resource message for the given key. If the message is not found a MissingResourceExcetion will be thrown.

Specified by:
get in interface Map
Throws:
MissingResourceException - if the given key was not found
See Also:
Map.get(Object)

put

public Object put(Object key,
                  Object value)
This method is not supported and will throw UnsupportedOperationException if invoked.

Specified by:
put in interface Map
See Also:
Map.put(Object, Object)

remove

public Object remove(Object key)
This method is not supported and will throw UnsupportedOperationException if invoked.

Specified by:
remove in interface Map
See Also:
Map.remove(Object)

putAll

public void putAll(Map map)
This method is not supported and will throw UnsupportedOperationException if invoked.

Specified by:
putAll in interface Map
See Also:
Map.putAll(Map)

clear

public void clear()
This method is not supported and will throw UnsupportedOperationException if invoked.

Specified by:
clear in interface Map
See Also:
Map.clear()

keySet

public Set keySet()
Specified by:
keySet in interface Map
See Also:
Map.keySet()

values

public Collection values()
Specified by:
values in interface Map
See Also:
Map.values()

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map
See Also:
Map.entrySet()

toString

public String toString()
See Also:
toString()