kiwi.util
Class LocaleData

java.lang.Object
  extended bykiwi.util.LocaleData

public class LocaleData
extends java.lang.Object

Locale-specific message bundle. This class serves as a lookup dictionary for localized messages, and provides some convenience methods for formatting the messages.

Author:
Mark Lindner, PING Software Group

Field Summary
static java.lang.String DEFAULT_DELIMITER
          The default message list delimiter.
private  java.util.Dictionary source
           
private  java.lang.Object[] unitArray
           
 
Constructor Summary
LocaleData(java.util.Dictionary source)
          Construct a new LocaleData object from the given dictionary.
LocaleData(java.io.InputStream instream)
          Construct a new LocaleData object from the given input stream.
 
Method Summary
 java.lang.String getMessage(java.lang.String key)
          Get a message for the specified key.
 java.lang.String getMessage(java.lang.String key, java.lang.Object arg)
          Get a message for the specified key, and format the message, substituting the specified argument for the message's first placeholder.
 java.lang.String getMessage(java.lang.String key, java.lang.Object[] args)
          Get a message for the specified key, and format the message, substituting the specified arguments for the message's placeholders.
 java.lang.String[] getMessageList(java.lang.String key)
          Get a message list for the specified key.
 java.lang.String[] getMessageList(java.lang.String key, java.lang.String delimiter)
          Get a message list for the specified key.
 boolean isMessageDefined(java.lang.String key)
          Determine if a message is defined for the specified key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_DELIMITER

public static final java.lang.String DEFAULT_DELIMITER
The default message list delimiter.

See Also:
Constant Field Values

unitArray

private final java.lang.Object[] unitArray

source

private java.util.Dictionary source
Constructor Detail

LocaleData

public LocaleData(java.io.InputStream instream)
           throws java.io.IOException
Construct a new LocaleData object from the given input stream.

Parameters:
instream - The stream to read the data from.
Throws:
java.io.IOException - If an error occurred while reading from the stream.

LocaleData

public LocaleData(java.util.Dictionary source)
Construct a new LocaleData object from the given dictionary.

Parameters:
source - A dictionary that contains the key/value pairs.
Since:
Kiwi 1.3
Method Detail

getMessage

public java.lang.String getMessage(java.lang.String key)
                            throws ResourceNotFoundException
Get a message for the specified key.

Parameters:
key - The key.
Returns:
A message for the specified key.
Throws:
ResourceNotFoundException - If the specified key was not found.

getMessage

public java.lang.String getMessage(java.lang.String key,
                                   java.lang.Object[] args)
Get a message for the specified key, and format the message, substituting the specified arguments for the message's placeholders. Messages may have placeholders of the form {n}, where n is a non-negative integer. For example, the message "My name is {0}, and I am {1} years old." and argument list { "Joe", new Integer(12) } would be formatted as My name is Joe, and I am 12 years old.

Parameters:
key - The key.
args - An array of arguments for the message.
Returns:
A fromatted message for the specified key.
Throws:
ResourceNotFoundException - If the specified key was not found.

getMessage

public java.lang.String getMessage(java.lang.String key,
                                   java.lang.Object arg)
Get a message for the specified key, and format the message, substituting the specified argument for the message's first placeholder. Messages may have* placeholders of the form {n}, where n is a non-negative integer. For example, the message "My name is {0}" and argument "Joe" would be formatted as My name is Joe.

Parameters:
key - The key.
Returns:
A fromatted message for the specified key.
Throws:
ResourceNotFoundException - If the specified key was not found.

getMessageList

public java.lang.String[] getMessageList(java.lang.String key)
                                  throws ResourceNotFoundException
Get a message list for the specified key. Retrieves a message for the specified key, and breaks the message on the default delimiter (",") constructing an array in the process.

Parameters:
key - The key.
Returns:
An array of messages for the specified key.
Throws:
ResourceNotFoundException - If the specified key was not found.

getMessageList

public java.lang.String[] getMessageList(java.lang.String key,
                                         java.lang.String delimiter)
                                  throws ResourceNotFoundException
Get a message list for the specified key. Retrieves a message for the specified key, and breaks the message on the specified delimiter constructing an array in the process.

Parameters:
key - The key.
delimiter - The delimiter to use.
Returns:
An array of messages for the specified key.
Throws:
kiwi.util.ResourceNotoundException - If the specified key was not found.
ResourceNotFoundException

isMessageDefined

public boolean isMessageDefined(java.lang.String key)
Determine if a message is defined for the specified key.

Parameters:
key - The key.
Returns:
true if the key exists, and false otherwise.