com.scooterframework.i18n
Class MessageResourcesManager

java.lang.Object
  extended by com.scooterframework.i18n.MessageResourcesManager

public class MessageResourcesManager
extends java.lang.Object

MessageResourcesManager is responsible for managing loading a locale's messages. It loads message resource files from the designated config/locales directory path based on the given base name.

The way this class loads messages is the same as Java's ResourceBundle operates. It first looks through the specified Locale's language, country and variant, then through the default Locale's language, country and variant and finally using just the base:

      base + "_" + localeLanguage + "_" + localeCountry + "_" + localeVariant
      base + "_" + localeLanguage + "_" + localeCountry
      base + "_" + localeLanguage
      base + "_" + defaultLanguage + "_" + defaultCountry + "_" + defaultVariant
      base + "_" + defaultLanguage + "_" + defaultCountry
      base + "_" + defaultLanguage
      base
 


Field Summary
protected  LogUtil log
           
 
Constructor Summary
MessageResourcesManager(java.lang.String configPath, java.lang.String baseName)
           
 
Method Summary
 java.util.Map<java.lang.String,java.io.File> getAllFiles()
          Returns all message properties files as a map with file name as key and file object as value.
 java.util.Set<java.util.Map.Entry<java.lang.String,java.util.Locale>> getAllLoadedLocalesSet()
           
 java.lang.String getConfigPath()
          Returns path to the directory where all message files are stored.
 java.lang.String getMessage(java.lang.String key, java.util.Locale locale)
          Returns a message associated with the key and the values in a specific locale.
 void loadLocale(java.util.Locale locale)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected LogUtil log
Constructor Detail

MessageResourcesManager

public MessageResourcesManager(java.lang.String configPath,
                               java.lang.String baseName)
Method Detail

getConfigPath

public java.lang.String getConfigPath()
Returns path to the directory where all message files are stored.


getAllFiles

public java.util.Map<java.lang.String,java.io.File> getAllFiles()
Returns all message properties files as a map with file name as key and file object as value.

Returns:
map of files

getAllLoadedLocalesSet

public java.util.Set<java.util.Map.Entry<java.lang.String,java.util.Locale>> getAllLoadedLocalesSet()

getMessage

public java.lang.String getMessage(java.lang.String key,
                                   java.util.Locale locale)
Returns a message associated with the key and the values in a specific locale.

If there is no message associated with the key in messages property files, this method returns null.

Parameters:
key - a message key in messages resource files
locale - a specific locale object
Returns:
a message string

loadLocale

public void loadLocale(java.util.Locale locale)