org.moyoman.framework
Class MessageTool

java.lang.Object
  |
  +--org.moyoman.framework.MessageTool

public class MessageTool
extends Object

This class provides methods for updating message files, and creating new ones. The writer of a message updating/translation user interface would use the api of this class to accomplish the back end work.


Constructor Summary
MessageTool()
           
 
Method Summary
static Message createLanguage(String langName, String displayName)
          Create a new language.
static String[] getIncompleteLanguages()
          Return those languages that do not have all messages defined.
static String getMessage(String displayableLanguageName, String symbolicMessageName)
          Get a message for the given language and message type.
static String[] getMissingMessages(String langName)
          Return those messages which are undefined for the specified language.
static void main(String[] args)
          This is used for unit testing, as well as illustrating how to translate a language.
static void removeMessage(String langName, String key)
          Remove the message type from the specified language.
static void reset(String langName)
          Undo all changes made to the specified language since the last reset() or save() call.
static void save(String langName)
          Save the results of a particular language to permanent storage.
static void setMessage(String langName, String name, String value)
          Set the message for the given language and message type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageTool

public MessageTool()
Method Detail

main

public static void main(String[] args)
This is used for unit testing, as well as illustrating how to translate a language.

Parameters:
args - An array of command line arguments, which are not used.

createLanguage

public static Message createLanguage(String langName,
                                     String displayName)
                              throws DataAlreadyExistsException
Create a new language.

Parameters:
langName - - The language name, which should only contain ASCII letters and numbers, or a hyphen or underscore, e.g, chinese_prc
displayName - - This is the string to be displayed to the user. It can be any Unicode string, but should end in an English translation in parentheses if not understandable to an English speaker, e.g, (Chinese-Singapore).
Returns:
A Message object if the creation was successful.
Throws:
DataAlreadyExistsException - Thrown if either the country of displayName parameters are not unique.

getMessage

public static String getMessage(String displayableLanguageName,
                                String symbolicMessageName)
                         throws NoSuchDataException
Get a message for the given language and message type.

Parameters:
displayableLanguageName - - The displayable name of the language.
symbolicMessageName - - The symbolic name of the message type.
Returns:
A String which is the localized message.
Throws:
NoSuchDataException - Thrown if the localized message does not exist.

setMessage

public static void setMessage(String langName,
                              String name,
                              String value)
                       throws IllegalArgumentException
Set the message for the given language and message type.

Parameters:
langName - - The displayable name of the language.
name - - The symbolic name of the message type.
value - - The localized message.
Throws:
IllegalArgumentException - Thrown if any of the parameters are incorrect.

save

public static void save(String langName)
                 throws InternalErrorException
Save the results of a particular language to permanent storage.

Parameters:
langName - The displayable name of the language.
Throws:
InternalErrorException - Thrown if an error occurs for any reason.

getIncompleteLanguages

public static String[] getIncompleteLanguages()
Return those languages that do not have all messages defined.

Returns:
An array of String objects which are the displayable names of the incomplete languages.

getMissingMessages

public static String[] getMissingMessages(String langName)
                                   throws NoSuchDataException
Return those messages which are undefined for the specified language. The specified languages is compared against the default language, and any missing symbols are returned.

Parameters:
langName - - The displayable name of the language in question.
Returns:
An array of String objects, which are the symbols missing.
Throws:
NoSuchDataException - Thrown if the language is unknown.

removeMessage

public static void removeMessage(String langName,
                                 String key)
Remove the message type from the specified language.

Parameters:
langName - The displayable language name.
key - The symbolic message name.

reset

public static void reset(String langName)
                  throws InternalErrorException
Undo all changes made to the specified language since the last reset() or save() call.

Parameters:
langName - The displayable language name.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.