org.universAAL.middleware.container.utils
Class Messages

Package class diagram package Messages
java.lang.Object
  extended by org.universAAL.middleware.container.utils.Messages

public class Messages
extends Object

The properties file consists of lines with key-value pairs (called 'messages'). In addition to simplify the reading of configuration files, this class also handles messages in different files representing the messages in different languages. When a message is not available in the localized language, the corresponding value for the default language is returned.
If the default file name is messages.properties, the file name for a different language include a language code as lowercase ISO 639 code, e.g. for english, the file name would be messages_en.properties.

Author:
mtazari, Carsten Stockloew, amedrano

Constructor Summary
Messages(File propertiesFile)
          Constructor: opens the file with the given descriptor and loads all messages.
Messages(File propertiesFile, Locale initialLocale)
          Constructor: opens the file with the given descriptor and loads all messages.
Messages(URL propertiesURL)
          Constructor: opens the file with the given descriptor and loads all messages.
Messages(URL propertiesURL, Locale initialLocale)
          Constructor: opens the file with the given descriptor and loads all messages.
 
Method Summary
 Locale getCurrentLocale()
          Get the current Locale used for messages.
 String getString(String key)
          Get the value for a given key.
 void setLocale(Locale loc)
          Try to change the locale for messages.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Messages

public Messages(File propertiesFile)
         throws IOException,
                IllegalArgumentException
Constructor: opens the file with the given descriptor and loads all messages. Initializes to default Locale.

Parameters:
propertiesFile - the properties file to use to load the messages.
Throws:
IOException - if the propertiesFile does not exist
IllegalArgumentException - if propertiesFile has incorrect extension

Messages

public Messages(File propertiesFile,
                Locale initialLocale)
         throws IOException,
                IllegalArgumentException
Constructor: opens the file with the given descriptor and loads all messages. Initializes a default Locale.

Parameters:
propertiesFile - the properties file to use to load the messages.
initialLocale - the initialLocale to be used.
Throws:
IOException - if the propertiesFile does not exist (but not if the internationalized file does not exist)
IllegalArgumentException - if propertiesFile has incorrect extension

Messages

public Messages(URL propertiesURL)
         throws IOException,
                IllegalArgumentException
Constructor: opens the file with the given descriptor and loads all messages. Initializes to default Locale.

Parameters:
propertiesURL - the properties file to use to load the messages.
Throws:
IOException - if the propertiesURL does not exist
IllegalArgumentException - if propertiesURL has incorrect extension

Messages

public Messages(URL propertiesURL,
                Locale initialLocale)
         throws IOException,
                IllegalArgumentException
Constructor: opens the file with the given descriptor and loads all messages. Initializes a default Locale.

Parameters:
propertiesURL - the properties file to use to load the messages.
initialLocale - the initialLocale to be used.
Throws:
IOException - if the propertiesURL does not exist (but not if the internationalized file does not exist)
IllegalArgumentException - if propertiesURL has incorrect extension
Method Detail

setLocale

public void setLocale(Locale loc)
Try to change the locale for messages.

Parameters:
loc -

getCurrentLocale

public Locale getCurrentLocale()
Get the current Locale used for messages.

Returns:
the current Locale, null if default.

getString

public String getString(String key)
Get the value for a given key.

Parameters:
key - The key.
Returns:
The value.


Copyright © 2014 universAAL Consortium. All Rights Reserved.