Expresso 5-6

com.jcorporate.expresso.core.i18n
Class Messages

java.lang.Object
  extended bycom.jcorporate.expresso.core.i18n.Messages

public class Messages
extends Object

Messages.java The Messages object provides a way to gain access to the appropriate local-language version of a message, and to provide substitution of parameters in the message string if necessary. The appropriate local language is determined by means of the following:

Created on January 10, 2001, 8:35 AM

Author:
Michael Nash

Field Summary
static String LOCALE_KEY
           
 
Constructor Summary
Messages()
          Creates new Class
 
Method Summary
static void establishLocale(HttpServletRequest req)
          Figure out a Locale by reading the current request.
static Locale getDefaultLocale()
          get default locale (much better to get it from user's request!!)
static Locale getLocale(HttpServletRequest req)
           
static String getString(HttpServletRequest req, String stringCode)
           
static String getString(HttpServletRequest req, String stringCode, String firstReplace)
          Return a string out of our message bundle
 String getString(HttpServletRequest req, String stringCode, String firstReplace, String secondReplace)
          Return a string out of our message bundle
 String getString(HttpServletRequest req, String stringCode, String firstReplace, String secondReplace, String thirdReplace)
          Convenience method to return a string out of our message bundle, using the thres string arguments as the replacement arguments
static String getString(Locale l, String stringCode)
           
static String getString(Locale l, String stringCode, Object[] args)
           
static String getString(Stack schemaStack, Locale ourLocale, String stringCode, Object[] args)
          Convenience method that gets a string using the schemaStack, looping through stack until the key is found
static String getString(String stringCode)
          Convenience method to return a specified string from the default schema, with no arguments
static String getString(String schemaClass, HttpServletRequest req, String stringCode, Object[] args)
          Convenience method to use the current default schema
static String getString(String schemaClass, Locale l, String stringCode)
          getString(schema, locale, stringCode)
static String getString(String schemaClass, Locale l, String stringCode, Object[] args)
          The "full" form of getString must specify a schema, language and country.
static String getString(String stringCode, Object[] args)
          Convenience method that gets a string with arguments using the default schema (e.g. no specific schema specified) but with the specified arguments
static String getString(String schemaClass, String stringCode)
          get string translation
static String getString(String schemaClass, String stringCode, Object[] args)
          If we have no information about what language we should be using, we use the defaults out of the properties file if present.
static String getStringByPath(String bundlePath, String language, String country, String stringCode, Object[] args)
          Variation on the above gets a string from a specified message bundle path
static String getStringForUser(int uid, String dbName, String schemaClass, String stringCode, Object[] args)
          use locale based on user ID, which is set as user preference; use with discrimination--it may be better to get locale from request
static String getStringRequired(Stack schemaStack, Locale ourLocale, String stringCode, Object[] args)
          Convenience method that gets a string using the schemaStack, looping through it until the key is found
static String getStringRequired(String schemaClass, Locale l, String stringCode, Object[] args)
          Return a string out of our message bundle associated with the specified schemaClass, throwing an exception if it's not found
static String getStringRequired(String schemaClass, String stringCode)
          Return a string out of our message bundle associated with the specified schemaClass, throwing an exception if it's not found
static String getStringUnrequired(Stack schemaStack, Locale ourLocale, String stringCode, Object[] args)
          Convenience method that gets a string using the schemaStack, looping through it until the key is found
static void setDefaultSchema(String newDefault)
          Set the default schema to a class name of a Schema object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALE_KEY

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

Messages

public Messages()
Creates new Class

Method Detail

getString

public static String getString(String schemaClass,
                               Locale l,
                               String stringCode,
                               Object[] args)
The "full" form of getString must specify a schema, language and country. If we don't have one of these things, we use the convenience methods to determine them

Parameters:
schemaClass - the schema class
l - the Locale
stringCode - the string code
args - any arguments.
Returns:
translated string, or if not found, the stringCode

getStringRequired

public static String getStringRequired(String schemaClass,
                                       Locale l,
                                       String stringCode,
                                       Object[] args)
                                throws IllegalArgumentException
Return a string out of our message bundle associated with the specified schemaClass, throwing an exception if it's not found

Parameters:
schemaClass - the schema class
l - the Locale
stringCode - the string code
args - any arguments.
Returns:
java.lang.String
Throws:
IllegalArgumentException - if the given string code doesn't exist in the given bundle.

getStringRequired

public static String getStringRequired(String schemaClass,
                                       String stringCode)
Return a string out of our message bundle associated with the specified schemaClass, throwing an exception if it's not found

Parameters:
schemaClass - the schema class
stringCode - the string code
Returns:
java.lang.String
Throws:
IllegalArgumentException - if the given string code doesn't exist in the given bundle.

getStringRequired

public static String getStringRequired(Stack schemaStack,
                                       Locale ourLocale,
                                       String stringCode,
                                       Object[] args)
                                throws IllegalArgumentException
Convenience method that gets a string using the schemaStack, looping through it until the key is found

Parameters:
schemaStack - A Stack of schemas
ourLocale - The specified Locale Object
stringCode - The string code to retrieve
args - the formatting arguments for the String
Returns:
The properly formatted string as read from the messages bundle or the key if not found
Throws:
IllegalArgumentException - if the given string code doesn't exist in any schema in stack.

getStringUnrequired

public static String getStringUnrequired(Stack schemaStack,
                                         Locale ourLocale,
                                         String stringCode,
                                         Object[] args)
                                  throws IllegalArgumentException
Convenience method that gets a string using the schemaStack, looping through it until the key is found

Parameters:
schemaStack - A Stack of schemas
ourLocale - The specified Locale Object
stringCode - The string code to retrieve
args - the formatting arguments for the String
Returns:
The properly formatted string as read from the messages bundle or the key if not found
Throws:
IllegalArgumentException

getStringByPath

public static String getStringByPath(String bundlePath,
                                     String language,
                                     String country,
                                     String stringCode,
                                     Object[] args)
Variation on the above gets a string from a specified message bundle path

Parameters:
bundlePath -
language -
country -
stringCode -
args -
Returns:

setDefaultSchema

public static void setDefaultSchema(String newDefault)
Set the default schema to a class name of a Schema object

Parameters:
newDefault -

getString

public static String getString(String stringCode)
Convenience method to return a specified string from the default schema, with no arguments

Parameters:
stringCode -
Returns:

getString

public static String getString(String stringCode,
                               Object[] args)
Convenience method that gets a string with arguments using the default schema (e.g. no specific schema specified) but with the specified arguments

Parameters:
stringCode -
args -
Returns:

getString

public static String getString(String schemaClass,
                               String stringCode)
get string translation

Parameters:
schemaClass - name of schema
stringCode - The string code to retrieve
Returns:
translated string, or if not found, the stringCode

getString

public static String getString(Stack schemaStack,
                               Locale ourLocale,
                               String stringCode,
                               Object[] args)
Convenience method that gets a string using the schemaStack, looping through stack until the key is found

Parameters:
schemaStack - A Stack of schemas
ourLocale - The specified Locale Object
stringCode - The string code to retrieve
args - the formatting arguments for the String
Returns:
The properly formatted string as read from the messages bundle or the key if not found

getString

public static String getString(String schemaClass,
                               HttpServletRequest req,
                               String stringCode,
                               Object[] args)
                        throws ServletException
Convenience method to use the current default schema

Parameters:
schemaClass -
req -
stringCode -
args -
Returns:
translated string, or if not found, the stringCode
Throws:
ServletException

getString

public static String getString(Locale l,
                               String stringCode)

getString

public static String getString(Locale l,
                               String stringCode,
                               Object[] args)

getString

public static String getString(String schemaClass,
                               Locale l,
                               String stringCode)
getString(schema, locale, stringCode)

Returns:
translated string, or if not found, the stringCode

establishLocale

public static void establishLocale(HttpServletRequest req)
                            throws ServletException
Figure out a Locale by reading the current request. If there is a currently logged-in user, use that users UserPreference settings to determine the language. If there is no logged-in user, use the browser settings if available. If no user and no browser settings, use the context's default language. If there is no context default setting, use english. At the end of calling this method, the session will contain a locale object for this user, one way or another :-)

Throws:
ServletException

getLocale

public static Locale getLocale(HttpServletRequest req)
                        throws ServletException
Throws:
ServletException

getString

public static String getString(String schemaClass,
                               String stringCode,
                               Object[] args)
If we have no information about what language we should be using, we use the defaults out of the properties file if present. If there are no defaults in the property file, we use english

Parameters:
schemaClass -
stringCode -
args -
Returns:
translated string, or if not found, the stringCode

getDefaultLocale

public static Locale getDefaultLocale()
get default locale (much better to get it from user's request!!)

Returns:
locale based on 'default' config context
See Also:
getLocale(javax.servlet.http.HttpServletRequest)

getStringForUser

public static String getStringForUser(int uid,
                                      String dbName,
                                      String schemaClass,
                                      String stringCode,
                                      Object[] args)
use locale based on user ID, which is set as user preference; use with discrimination--it may be better to get locale from request

Parameters:
uid -
dbName -
schemaClass -
stringCode -
args -
Returns:
translated string, or if not found, the stringCode
See Also:
getString(java.util.Locale, String)

getString

public static String getString(HttpServletRequest req,
                               String stringCode)
                        throws ServletException
Parameters:
req -
stringCode -
Returns:
translated string, or if not found, the stringCode
Throws:
ServletException

getString

public static String getString(HttpServletRequest req,
                               String stringCode,
                               String firstReplace)
                        throws ServletException
Return a string out of our message bundle

Parameters:
req -
stringCode -
firstReplace -
Returns:
Throws:
ServletException

getString

public String getString(HttpServletRequest req,
                        String stringCode,
                        String firstReplace,
                        String secondReplace)
                 throws ServletException
Return a string out of our message bundle

Parameters:
req -
stringCode -
firstReplace -
secondReplace -
Returns:
Throws:
ServletException

getString

public String getString(HttpServletRequest req,
                        String stringCode,
                        String firstReplace,
                        String secondReplace,
                        String thirdReplace)
                 throws ServletException
Convenience method to return a string out of our message bundle, using the thres string arguments as the replacement arguments

Parameters:
req -
stringCode -
firstReplace -
secondReplace -
thirdReplace -
Returns:
Throws:
ServletException

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.