com.arsdigita.globalization
Class GlobalizedMessage

java.lang.Object
  extended bycom.arsdigita.globalization.GlobalizedMessage

public class GlobalizedMessage
extends Object

Represents a key into a ResourceBundle, a target ResourceBundle, and possibly an array of arguments to interpolate into the retrieved message using the MessageFormat class.

This class should be used in any situation where the application needs to output localizeable objects.

Version:
$Revision: #12 $ $Date: 2004/04/07 $
See Also:
MessageFormat, Locale, ResourceBundle

Field Summary
static String versionId
           
 
Constructor Summary
GlobalizedMessage(String key)
           Constructor.
GlobalizedMessage(String key, Object[] args)
           Constructor.
GlobalizedMessage(String key, String bundleName)
           Constructor.
GlobalizedMessage(String key, String bundleName, Object[] args)
           Constructor.
 
Method Summary
 String getKey()
           Get the key for this GlobalizedMessage.
 Object localize()
          
Localize this message.
 Object localize(javax.servlet.http.HttpServletRequest request)
          
Localize this message according the specified request.
 Object localize(Locale locale)
           Localize this message with the provided locale.
 String toString()
           For debugging, not for localizing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

versionId

public static final String versionId
See Also:
Constant Field Values
Constructor Detail

GlobalizedMessage

public GlobalizedMessage(String key)

Constructor. Takes in a key to be used to look up a message in the ResourceBundle for the current running application. The base name of the ResourceBundle to do the lookup in is retrieved from the ApplicationContext.

Parameters:
key - The key to use to look up a message in the ResourceBundle.

GlobalizedMessage

public GlobalizedMessage(String key,
                         String bundleName)

Constructor. Takes in a key to be used to look up a message in the ResourceBundle specified.

Parameters:
key - The key to use to look up a message in the ResourceBundle.
bundleName - The base name of the target ResourceBundle.

GlobalizedMessage

public GlobalizedMessage(String key,
                         Object[] args)

Constructor. Takes in a key to be used to look up a message in the ResourceBundle for the current running application. The base name of the ResourceBundle to do the lookup in is retrieved from the ApplicationContext. Also takes in an Object[] of arguments to interpolate into the retrieved message using the MessageFormat class.

Parameters:
key - The key to use to look up a message in the ResourceBundle.
args - An Object[] of arguments to interpolate into the retrieved message.

GlobalizedMessage

public GlobalizedMessage(String key,
                         String bundleName,
                         Object[] args)

Constructor. Takes in a key to be used to look up a message in the ResourceBundle specified. Also takes in an Object[] of arguments to interpolate into the retrieved message using the MessageFormat class.

Parameters:
key - The key to use to look up a message in the ResourceBundle.
bundleName - The base name of the target ResourceBundle.
args - An Object[] of arguments to interpolate into the retrieved message.
Method Detail

getKey

public final String getKey()

Get the key for this GlobalizedMessage.

Returns:
String The key for this GlobalizedMessage.

localize

public Object localize()


Localize this message. If no message is found the key is returned as the message. This is done so that developers or translators can see the messages that still need localization.

Any arguments this message has are interpolated into it using the java.text.MessageFormat class.

Returns:
Object Represents the localized version of this message. The reason this method returns an Object and not a String is because we might want to localize resources other than strings, such as icons or sound bites. Maybe this class should have been called GlobalizedObject?

localize

public Object localize(javax.servlet.http.HttpServletRequest request)


Localize this message according the specified request. If no message is found the key is returned as the message. This is done so that developers or translators can see the messages that still need localization.

Any arguments this message has are interpolated into it using the java.text.MessageFormat class.

Returns:
Object Represents the localized version of this message. The reason this method returns an Object and not a String is because we might want to localize resources other than strings, such as icons or sound bites. Maybe this class should have been called GlobalizedObject?

localize

public Object localize(Locale locale)

Localize this message with the provided locale. If no message is found the key is returned as the message. This is done so that developers or translators can see the messages that still need localization.

Any arguments this message has are interpolated into it using the java.text.MessageFormat class.

Parameters:
locale - The locale to try to use to localize this message.
Returns:
Object Represents the localized version of this message. The reason this method returns an Object and not a String is because we might want to localize resources other than strings, such as icons or sound bites. Maybe this class should have been called GlobalizedObject?

toString

public String toString()

For debugging, not for localizing.

Returns:
The contents in String form for debugging.


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC