ucot
Class Messages

java.lang.Object
  extended by ucot.Messages

public class Messages
extends java.lang.Object

This class contains interface to the localised message strings.

Strings are readed using ResourceBundle that uses ucot/message.properties file (or its localized version).

Author:
pajumasu

Field Summary
private static java.lang.String BUNDLE_NAME
           
private static java.util.ResourceBundle RESOURCE_BUNDLE
           
 
Constructor Summary
Messages()
           
 
Method Summary
static java.lang.String formatMessage(java.lang.String messageString, java.lang.Object... args)
          Method formats messages with parameters to user readable format.
static java.lang.String getFormatedMessage(java.lang.String key, java.lang.Object... args)
          Gets string localized string and format the arguments using it.
static java.lang.String getString(java.lang.String key)
          Returns localized string for the given key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUNDLE_NAME

private static final java.lang.String BUNDLE_NAME
See Also:
Constant Field Values

RESOURCE_BUNDLE

private static final java.util.ResourceBundle RESOURCE_BUNDLE
Constructor Detail

Messages

public Messages()
Method Detail

getString

public static java.lang.String getString(java.lang.String key)

Returns localized string for the given key. If no string is found then !key! is returned (where key is the key-string that was given as parameter)

getString("FILE_NOT_FOUND"); would return some string definded for example in properties file or string "!FILE_NOT_FOUND!" if no matching key is located.

Parameters:
key - Key for the string required.
Returns:
localized string for the given key.

formatMessage

public static java.lang.String formatMessage(java.lang.String messageString,
                                             java.lang.Object... args)

Method formats messages with parameters to user readable format. MessageString is normal string that marks the places for the dynamic information with {}-marks and number in between them.

For example: formatMessage("File {0} not found.", new File("file.txt")); would return string: "File file.txt not found.".

To use with getString method you can do like this: System.out.println(formatMessage(getString("FILE_NOT_FOUND"), new File("file.txt")));. If there is property file that contains line: FILE_NOT_FOUND=File {0} not found. then it would return the same string: "File file.txt not found.".

Parameters:
messageString - Message format string.
args - Arguments for the string.
Returns:
Returns string that is builded using the arguments.

getFormatedMessage

public static java.lang.String getFormatedMessage(java.lang.String key,
                                                  java.lang.Object... args)

Gets string localized string and format the arguments using it.

Returns:
The formated and localized string.
See Also:
formatMessage(String, Object[]), getString(String)