org.loom.i18n
Class MessagesRepository

java.lang.Object
  extended by org.loom.i18n.MessagesRepository

public class MessagesRepository
extends java.lang.Object

Repository for messages that may be translated. This repository is specific for a given Locale.


Field Summary
static java.lang.String DECIMAL_FORMAT_KEY
          Some important keys
static java.lang.String DECIMAL_SEPARATOR_KEY
           
static java.lang.String GROUPING_SEPARATOR_KEY
           
static java.lang.String JSNUMBER_FORMAT_KEY
           
 
Constructor Summary
MessagesRepository(java.util.Locale locale)
           
 
Method Summary
 void addBrowserMessage(java.lang.String browserMessage)
           
 void addBrowserMessages(java.util.Set<java.lang.String> browserMessages)
           
 void addProperties(java.util.Properties properties)
          Add all entries from a Properties file into this instance contents
 void addString(java.lang.String name, java.lang.String value)
          Add one entry to this MessagesRepository instance
 java.util.Map<java.lang.String,java.lang.String> asMap()
           
 java.text.DecimalFormatSymbols createDecimalFormatSymbols()
          Get the DecimalFormatSymbols associated to the current Locale.
 java.util.Set<java.lang.String> getBrowserMessages()
           
 byte[] getGzippedJson()
           
 java.util.Date getLastModified()
           
 java.util.Locale getLocale()
           
 java.lang.String getMD5()
           
 MissingMessageHandler getMissingMessagesHandler()
           
 java.lang.String getNullableString(java.lang.String key)
          Returns a key translated to the current locale.
 java.lang.String getRequiredString(java.lang.String key)
          Returns a key translated to the current locale.
 java.util.List<org.springframework.core.io.Resource> getResources()
           
 java.lang.String getString(java.lang.String key)
          Returns a key translated to the current locale.
 java.lang.String guessString(java.lang.String paramName)
          Returns a key translated to the current locale.
 void initialize()
          Initializes this MessagesRepository instance with the contents of the provided files
 void setIncludeLoomResourcesInJson(boolean includeLoomResourcesInJson)
           
 void setLastModified(java.util.Date lastModified)
           
 void setMissingMessagesHandler(MissingMessageHandler missingMessagesHandler)
           
 void setResources(java.util.List<org.springframework.core.io.Resource> resources)
           
 int size()
           
 java.lang.String toJSON()
           
 java.lang.String translateMessage(Message message)
          Returns the translated Message for the current Locale.
 java.lang.String translateMessages(java.util.List<Message> messages)
          Returns the list of messages
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DECIMAL_FORMAT_KEY

public static final java.lang.String DECIMAL_FORMAT_KEY
Some important keys

See Also:
Constant Field Values

DECIMAL_SEPARATOR_KEY

public static final java.lang.String DECIMAL_SEPARATOR_KEY
See Also:
Constant Field Values

GROUPING_SEPARATOR_KEY

public static final java.lang.String GROUPING_SEPARATOR_KEY
See Also:
Constant Field Values

JSNUMBER_FORMAT_KEY

public static final java.lang.String JSNUMBER_FORMAT_KEY
See Also:
Constant Field Values
Constructor Detail

MessagesRepository

public MessagesRepository(java.util.Locale locale)
Method Detail

getString

public java.lang.String getString(java.lang.String key)
Returns a key translated to the current locale. This method is similar in behaviour to ResourceBundle.getString(), but will return a [missing:key] if the key could not be found.


getNullableString

public java.lang.String getNullableString(java.lang.String key)
Returns a key translated to the current locale. This method is similar in behaviour to ResourceBundle.getString(), but will return null if the resource is not found


getRequiredString

public java.lang.String getRequiredString(java.lang.String key)
Returns a key translated to the current locale. This method throws an Exception if the key is missing


guessString

public java.lang.String guessString(java.lang.String paramName)
Returns a key translated to the current locale. If the key is a nested path like a.b.c, first tries a.b.c, then b.c, then c. If none of them returns a valid translation, returns the same as getString()


translateMessage

public java.lang.String translateMessage(Message message)
Returns the translated Message for the current Locale. Merges a Velocity template with the given args.

Parameters:
message - The message to be translated
Returns:
The translated message

initialize

public void initialize()
Initializes this MessagesRepository instance with the contents of the provided files


translateMessages

public java.lang.String translateMessages(java.util.List<Message> messages)
Returns the list of messages

Returns:
The translated messages

createDecimalFormatSymbols

public java.text.DecimalFormatSymbols createDecimalFormatSymbols()
Get the DecimalFormatSymbols associated to the current Locale. This method returns the DecimalFormatSymbols associated to the locale by the JVM, modified by the user if there is one decimalSeparator or groupingSeparator in the properties file.


toJSON

public java.lang.String toJSON()
Returns:
a JSON representation of the error messages and other i18n contents in this repository, to be used by the javascript validation library

getMD5

public java.lang.String getMD5()
Returns:
the MD5 hash of the string representation of the current contents

getLocale

public java.util.Locale getLocale()

getMissingMessagesHandler

public MissingMessageHandler getMissingMessagesHandler()

setMissingMessagesHandler

public void setMissingMessagesHandler(MissingMessageHandler missingMessagesHandler)

addProperties

public void addProperties(java.util.Properties properties)
Add all entries from a Properties file into this instance contents

Parameters:
properties -

addString

public void addString(java.lang.String name,
                      java.lang.String value)
Add one entry to this MessagesRepository instance


size

public int size()
Returns:
the size of its contents. This size may change with time, as guessed keys are added lazily.

asMap

public java.util.Map<java.lang.String,java.lang.String> asMap()
Returns:
an unmodifiable Map adapter to this instance. This Map will see changes made to this MessagesRepository class in real time, but cannot modify it.

getBrowserMessages

public java.util.Set<java.lang.String> getBrowserMessages()

addBrowserMessage

public void addBrowserMessage(java.lang.String browserMessage)

addBrowserMessages

public void addBrowserMessages(java.util.Set<java.lang.String> browserMessages)

getLastModified

public java.util.Date getLastModified()

setLastModified

public void setLastModified(java.util.Date lastModified)

getGzippedJson

public byte[] getGzippedJson()

getResources

public java.util.List<org.springframework.core.io.Resource> getResources()

setResources

public void setResources(java.util.List<org.springframework.core.io.Resource> resources)

setIncludeLoomResourcesInJson

public void setIncludeLoomResourcesInJson(boolean includeLoomResourcesInJson)