org.jaffa.util
Class MessageHelper

java.lang.Object
  extended byorg.jaffa.util.MessageHelper

public class MessageHelper
extends Object

This is a helper class for getting messages from the Resource. It also performs token replacement

Author:
GautamJ

Constructor Summary
MessageHelper()
           
 
Method Summary
static String findMessage(Locale locale, String key, Object[] args)
          Gets the message for the input key from the default resources, as specified in the 'framework.messageResources.bundle' property of framework.properties files.
static String findMessage(MessageResources resources, Locale locale, String key, Object[] args)
          Gets the message for the input key from the resources.
static String findMessage(PageContext pageContext, String key, Object[] args)
          Gets the message for the input key from the resources (an attribute in the request stream).
static String findMessage(PageContext pageContext, String resources, String locale, String key, Object[] args)
          Gets the message for the input key from the resources (an attribute in the request stream).
static String findMessage(String key, Object[] args)
          Gets the message for the input key from the default resources, as specified in the 'framework.messageResources.bundle' property of framework.properties files.
static boolean hasTokens(String input)
          Returns a true if the input String consists of a tokenized string.
static String removeTokenMarkers(String input)
          This is a convenience method to remove the token markers from the input string.
static String replaceTokens(Locale locale, String message)
          Replace the tokens in the input message with appropriate values from the default resources, as specified in the 'framework.messageResources.bundle' property of framework.properties files.
static String replaceTokens(MessageResources resources, Locale locale, String message)
          Replace the tokens in the input message with appropriate values from the resources.
static String replaceTokens(PageContext pageContext, String message)
          Replace the tokens in the input message with appropriate values from the resources (an attribute in the request stream).
static String replaceTokens(PageContext pageContext, String resources, String locale, String message)
          Replace the tokens in the input message with appropriate values from the resources (an attribute in the request stream).
static String replaceTokens(String message)
          Replace the tokens in the input message with appropriate values from the default resources, as specified in the 'framework.messageResources.bundle' property of framework.properties files.
static String tokenize(String input)
          This will add the Token Markers around the input String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageHelper

public MessageHelper()
Method Detail

findMessage

public static String findMessage(String key,
                                 Object[] args)
Gets the message for the input key from the default resources, as specified in the 'framework.messageResources.bundle' property of framework.properties files. A null will be returned in case an invalid or if no ResourceBundle is specified in the 'framework.messageResources.bundle' property of framework.properties file. It uses the locale for the user from the thread variable, if available, else it uses the default locale for the JVM. It will also perform token replacement.

Parameters:
key - The key of the the message to be looked up.
args - An array of arguments to be added to the message.
Returns:
the message with the tokens replaced.

findMessage

public static String findMessage(Locale locale,
                                 String key,
                                 Object[] args)
Gets the message for the input key from the default resources, as specified in the 'framework.messageResources.bundle' property of framework.properties files. A null will be returned in case an invalid or if no ResourceBundle is specified in the 'framework.messageResources.bundle' property of framework.properties file. It will also perform token replacement.

Parameters:
locale - the Locale to be used when looking up the ResourceBundle.
key - The key of the the message to be looked up.
args - An array of arguments to be added to the message.
Returns:
the message with the tokens replaced.

findMessage

public static String findMessage(PageContext pageContext,
                                 String key,
                                 Object[] args)
Gets the message for the input key from the resources (an attribute in the request stream). It will also perform token replacement. This uses the default struts MessageResources and Locale.

Parameters:
pageContext - The servlet pageContext we are processing.
key - The key of the the message to be looked up.
args - An array of arguments to be added to the message.
Returns:
the message with the tokens replaced.

findMessage

public static String findMessage(PageContext pageContext,
                                 String resources,
                                 String locale,
                                 String key,
                                 Object[] args)
Gets the message for the input key from the resources (an attribute in the request stream). It will also perform token replacement.

Parameters:
pageContext - The servlet pageContext we are processing.
resources - The key that identifies that the MessageResources object in the pageContext
locale - The key that identifies that the Locale object in the pageContext
key - The key of the the message to be looked up.
args - An array of arguments to be added to the message.
Returns:
the message with the tokens replaced.

findMessage

public static String findMessage(MessageResources resources,
                                 Locale locale,
                                 String key,
                                 Object[] args)
Gets the message for the input key from the resources. It will also perform token replacement.

Parameters:
resources - The underlying resource bundle to look at.
locale - The requested message Locale.
key - The key of the the message to be looked up.
args - An array of arguments to be added to the message.
Returns:
the message with the tokens replaced.

replaceTokens

public static String replaceTokens(String message)
Replace the tokens in the input message with appropriate values from the default resources, as specified in the 'framework.messageResources.bundle' property of framework.properties files. A null will be returned in case an invalid or if no ResourceBundle is specified in the 'framework.messageResources.bundle' property of framework.properties file. It uses the locale for the user from the thread variable, if available, else it uses the default locale for the JVM. If the value for a token, is again a token, then it will recursively find the value.

Parameters:
message - Message to be looked up for token replacement.
Returns:
the message with the tokens replaced.

replaceTokens

public static String replaceTokens(Locale locale,
                                   String message)
Replace the tokens in the input message with appropriate values from the default resources, as specified in the 'framework.messageResources.bundle' property of framework.properties files. A null will be returned in case an invalid or if no ResourceBundle is specified in the 'framework.messageResources.bundle' property of framework.properties file. If the value for a token, is again a token, then it will recursively find the value.

Parameters:
locale - the Locale to be used when looking up the ResourceBundle.
message - Message to be looked up for token replacement.
Returns:
the message with the tokens replaced.

replaceTokens

public static String replaceTokens(PageContext pageContext,
                                   String message)
Replace the tokens in the input message with appropriate values from the resources (an attribute in the request stream). This uses the default struts MessageResources and Locale. If the value for a token, is again a token, then it will recursively find the value.

Parameters:
pageContext - The servlet pageContext we are processing.
message - Message to be looked up for token replacement.
Returns:
the message with the tokens replaced.

replaceTokens

public static String replaceTokens(PageContext pageContext,
                                   String resources,
                                   String locale,
                                   String message)
Replace the tokens in the input message with appropriate values from the resources (an attribute in the request stream). If the value for a token, is again a token, then it will recursively find the value.

Parameters:
pageContext - The servlet pageContext we are processing.
resources - The key that identifies that the MessageResources object in the pageContext
locale - The key that identifies that the Locale object in the pageContext
message - Message to be looked up for token replacement.
Returns:
the message with the tokens replaced.

replaceTokens

public static String replaceTokens(MessageResources resources,
                                   Locale locale,
                                   String message)
Replace the tokens in the input message with appropriate values from the resources. If the value for a token, is again a token, then it will recursively find the value. Note: Ensure that are no cyclic references from one token to another to the first token.

Parameters:
resources - The underlying resource bundle to look at.
locale - The requested message Locale.
message - Message to be looked up for token replacement.
Returns:
the message with the tokens replaced.

tokenize

public static String tokenize(String input)
This will add the Token Markers around the input String.

Parameters:
input - the string to be tokenized.
Returns:
the string with the Token Markers around it. A null is returned if the input is null. If the input begins or ends with the token marker, then it will be returned as is.

hasTokens

public static boolean hasTokens(String input)
Returns a true if the input String consists of a tokenized string.

Parameters:
input - the string to be checked for presence of tokens
Returns:
a true if the input String consists of a tokenized string.

removeTokenMarkers

public static String removeTokenMarkers(String input)
This is a convenience method to remove the token markers from the input string. This method will remove the markers at the beginning and at the end of the string only. Otherwise it'll simply return the input as is.

Parameters:
input - The string from which the token markers are to be removed.
Returns:
The input string minus its outer token markers, if any.


Copyright © 2002-2004 JAFFA Project.