org.loom.i18n
Class DefaultMessagesRepositoryFactory

java.lang.Object
  extended by org.loom.i18n.DefaultMessagesRepositoryFactory
All Implemented Interfaces:
MessagesRepositoryFactory

@Singleton
public class DefaultMessagesRepositoryFactory
extends java.lang.Object
implements MessagesRepositoryFactory

Default MessagesRepositoryFactory implementation. Searches for the specified properties files in the classpath.


Constructor Summary
DefaultMessagesRepositoryFactory()
           
 
Method Summary
 void addBrowserMessage(java.lang.String messageKey)
          Add a message key that should be forwarded to the browser.
protected  boolean checkResourceExists(java.lang.String resourceName)
           
 java.util.Set<java.lang.String> getBrowserMessages()
           
 java.util.Locale getDefaultLocale()
           
 java.util.List<java.lang.String> getLocations()
           
 MissingMessageHandler getMissingMessagesHandler()
           
protected  java.util.Locale getNearestSupportedLocale(java.util.Locale locale)
          Will look in the list of configured locations and return the first partial locale match
 MessagesRepository getRepository(java.util.Locale locale)
          Get a repository (if already created) or creates a new one if not.
 java.util.List<org.springframework.core.io.Resource> getResources(java.util.Locale locale)
           
protected  MessagesRepository initRepository(java.util.Locale locale)
          Initialize a new repository instance.
 void setBrowserMessages(java.util.Set<java.lang.String> browserKeys)
          Add a set of Json keys
 void setDefaultLocale(java.util.Locale defaultLocale)
           
 void setIncludeLoomResourcesInJson(boolean includeLoomResourcesInJson)
           
 void setLocations(java.util.List<java.lang.String> locations)
          Replace this factory locations with the provided list
 void setMissingMessagesHandler(MissingMessageHandler missingMessagesHandler)
           
 void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultMessagesRepositoryFactory

public DefaultMessagesRepositoryFactory()
Method Detail

getRepository

public MessagesRepository getRepository(java.util.Locale locale)
Get a repository (if already created) or creates a new one if not. The provided Locale will be compared to the properties files in the classpath, and a MessagesRepository instance will be created for the first Locale fragment that is a match for any properties file. For example, if messages_es and messages_en are found in the classpath and a request for es_ES_CA is received, a MessagesRepository for "es" (the first supported Locale) will be returned. If not found, a Messagesrepository for defaultLocale will be returned.

Specified by:
getRepository in interface MessagesRepositoryFactory

getResources

public java.util.List<org.springframework.core.io.Resource> getResources(java.util.Locale locale)
Parameters:
locale -
Returns:
the list of resources (properties files) used to produce a MessagesRepository for the specified Locale. All the returned Resources are confirmed to exist.

initRepository

protected MessagesRepository initRepository(java.util.Locale locale)
Initialize a new repository instance. This method makes a second check: if the properties files that will be used for this locale are the same on an already existing repository, return the existing repository instead.


getNearestSupportedLocale

protected java.util.Locale getNearestSupportedLocale(java.util.Locale locale)
Will look in the list of configured locations and return the first partial locale match

Returns:
the nearest Locale that is supported.

checkResourceExists

protected boolean checkResourceExists(java.lang.String resourceName)
Returns:
true if the resource exists

addBrowserMessage

public void addBrowserMessage(java.lang.String messageKey)
Add a message key that should be forwarded to the browser.

Specified by:
addBrowserMessage in interface MessagesRepositoryFactory
Parameters:
messageKey - the message key to be added

setBrowserMessages

public void setBrowserMessages(java.util.Set<java.lang.String> browserKeys)
Add a set of Json keys

Specified by:
setBrowserMessages in interface MessagesRepositoryFactory
Parameters:
browserKeys - the new set of JSON keys

getDefaultLocale

public java.util.Locale getDefaultLocale()
Specified by:
getDefaultLocale in interface MessagesRepositoryFactory
Returns:
the locale applied by default. Defaults to Locale.getDefaultLocale()

setDefaultLocale

public void setDefaultLocale(java.util.Locale defaultLocale)

setLocations

public void setLocations(java.util.List<java.lang.String> locations)
Replace this factory locations with the provided list

Parameters:
locations - new list of properties file locations

setResourceLoader

@Inject
public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)

getLocations

public java.util.List<java.lang.String> getLocations()

getBrowserMessages

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

getMissingMessagesHandler

public MissingMessageHandler getMissingMessagesHandler()

setMissingMessagesHandler

public void setMissingMessagesHandler(MissingMessageHandler missingMessagesHandler)

setIncludeLoomResourcesInJson

public void setIncludeLoomResourcesInJson(boolean includeLoomResourcesInJson)