|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.util.MessagesMap
public class MessagesMap
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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
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<String,String> |
messages
The map of localized messages. |
protected static Map<Object,Map<String,String>> |
MESSAGES_CACHE
Cache of messages keyed by bundleName + Locale name. |
protected static Set<String> |
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. |
|
MessagesMap(Class<?> baseClass,
String globalResource,
Locale locale)
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)
|
protected ResourceBundle |
createResourceBundle(String resourceName,
Locale locale)
Return the ResourceBundle for the given resource name and locale. |
protected void |
ensureInitialized()
This method initializes and populates the internal messages map
and MESSAGES_CACHE if it is not already initialized. |
Set<Map.Entry<String,String>> |
entrySet()
|
String |
get(Object key)
Return localized resource message for the given key. |
boolean |
isEmpty()
|
Set<String> |
keySet()
|
protected void |
loadResourceValuesIntoMap(String resourceBundleName,
Map<String,String> map)
Load the values of the given resourceBundleName into the map. |
String |
put(String key,
String value)
This method is not supported and will throw UnsupportedOperationException if invoked. |
void |
putAll(Map<? extends String,? extends String> map)
This method is not supported and will throw UnsupportedOperationException if invoked. |
String |
remove(Object key)
This method is not supported and will throw UnsupportedOperationException if invoked. |
int |
size()
|
String |
toString()
|
Collection<String> |
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 |
---|
protected static final Set<String> NOT_FOUND_CACHE
protected static final Map<Object,Map<String,String>> MESSAGES_CACHE
protected static final Object CACHE_LOAD_LOCK
protected final Class<?> baseClass
protected final String globalBaseName
protected Map<String,String> messages
protected final Locale locale
Constructor Detail |
---|
public MessagesMap(Class<?> baseClass, String globalResource)
baseClass
- the target classglobalResource
- the global resource bundle namepublic MessagesMap(Class<?> baseClass, String globalResource, Locale locale)
baseClass
- the target classglobalResource
- the global resource bundle namelocale
- the resource bundle locale.Method Detail |
---|
public int size()
size
in interface Map<String,String>
Map.size()
public boolean isEmpty()
isEmpty
in interface Map<String,String>
Map.isEmpty()
public boolean containsKey(Object key)
containsKey
in interface Map<String,String>
Map.containsKey(Object)
public boolean containsValue(Object value)
containsValue
in interface Map<String,String>
Map.containsValue(Object)
public String get(Object key)
get
in interface Map<String,String>
MissingResourceException
- if the given key was not foundMap.get(Object)
public String put(String key, String value)
put
in interface Map<String,String>
Map.put(Object, Object)
public String remove(Object key)
remove
in interface Map<String,String>
Map.remove(Object)
public void putAll(Map<? extends String,? extends String> map)
putAll
in interface Map<String,String>
Map.putAll(Map)
public void clear()
clear
in interface Map<String,String>
Map.clear()
public Set<String> keySet()
keySet
in interface Map<String,String>
Map.keySet()
public Collection<String> values()
values
in interface Map<String,String>
Map.values()
public Set<Map.Entry<String,String>> entrySet()
entrySet
in interface Map<String,String>
Map.entrySet()
public String toString()
toString
in class Object
toString()
protected ResourceBundle createResourceBundle(String resourceName, Locale locale)
ResourceBundle.getBundle(java.lang.String, java.util.Locale, java.lang.ClassLoader)
.
You can create your own custom ResourceBundle by overriding this method.
In order for Click to use your custom MessagesMap implementation, you
need to provide your own MessagesMapService
or extend DefaultMessagesMapService
.
The method createMessagesMap
,
can be implemented to return your custom MessagesMap instances.
resourceName
- the resource bundle namelocale
- the resource bundle locale.
protected void ensureInitialized()
messages
map
and MESSAGES_CACHE
if it is not already initialized.
Please Note: populating MESSAGES_CACHE
is not thread safe
and access to the cache must be properly synchronized.
protected void loadResourceValuesIntoMap(String resourceBundleName, Map<String,String> map)
resourceBundleName
- the resource bundle namemap
- the map to load resource values into
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |