| java.lang.Object com.opensymphony.xwork.util.LocalizedTextUtil
LocalizedTextUtil | public class LocalizedTextUtil (Code) | | Provides support for localization in XWork.
Resource bundles are searched in the following order:
- ActionClass.properties
- BaseClass.properties (all the way to Object.properties)
- Interface.properties (every interface and sub-interface)
- ModelDriven's model (if implements ModelDriven), for the model object repeat from 1
- package.properties (of the directory where class is located and every parent directory all the way to the root directory)
- search up the i18n message key hierarchy itself
- global resource properties (webwork.custom.i18n.resources) defined in webwork.properties
To clarify #5, while traversing the package hierarchy, WW will look for a file package.properties:
com/
acme/
package.properties
actions/
package.properties
FooAction.java
FooAction.properties
If FooAction.properties does not exist, com/acme/action/package.properties will be searched for, if
not found com/acme/package.properties, if not found com/package.properties, etc.
A global resource bundle could be specified through the 'webwork.custom.i18n.resources' property in
webwork.properties. The locale can be siwtched by 'webwork.locale' in the webwork.properties as well.
Struts users should be familiar with the application.properties resource bundle, where you can put all the messages
in the application that are going to be translated. WebWork, though, splits the resource bundles per action or model
class, and you may end up with duplicated messages in those resource bundles. A quick fix for that is to create a
file called ActionSupport.properties in com/opensymphony/xwork and put it on your classpath. This will only work well
if all your actions subclass ActionSupport.
author: Jason Carreira author: Mark Woon author: Rainer Hermanns author: tm_jee author: $Date: 2007-06-30 18:15:16 +0200 (Sat, 30 Jun 2007) $ $Id: LocalizedTextUtil.java 1536 2007-06-30 16:15:16Z tm_jee $ |
Inner Class :static class MessageFormatKey | |
Inner Class :static class GetDefaultMessageReturnArg | |
Method Summary | |
public static void | addDefaultResourceBundle(String resourceBundleName) Add's the bundle to the internal list of default bundles. | public static void | clearDefaultResourceBundles() Clears the internal list of resource bundles. | public static String | findDefaultText(String aTextName, Locale locale) Returns a localized message for the specified key, aTextName. | public static String | findDefaultText(String aTextName, Locale locale, Object[] params) Returns a localized message for the specified key, aTextName, substituting variables from the
array of params into the message. | public static ResourceBundle | findResourceBundle(String aBundleName, Locale locale) Finds the given resorce bundle by it's name.
Will use Thread.currentThread().getContextClassLoader() as the classloader.
Parameters: aBundleName - the name of the bundle (usually it's FQN classname). Parameters: locale - the locale. | public static String | findText(Class aClass, String aTextName, Locale locale) Calls
LocalizedTextUtil.findText(Class aClass,String aTextName,Locale locale,String defaultMessage,Object[] args) with aTextName as the default message. | public static String | findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args) Finds a localized text message for the given key, aTextName. | public static String | findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack) This method call will log a warning message (in debug level) if message is not found
Finds a localized text message for the given key, aTextName. | public static String | findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack, boolean warnIfNoMessageFound) Finds a localized text message for the given key, aTextName. | public static String | findText(ResourceBundle bundle, String aTextName, Locale locale) Finds a localized text message for the given key, aTextName, in the specified resource bundle
with aTextName as the default message.
If a message is found, it will also be interpolated. | public static String | findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args) Finds a localized text message for the given key, aTextName, in the specified resource
bundle.
If a message is found, it will also be interpolated. | public static String | findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack) This method will log a warning (in debug level) if no message is found.
Finds a localized text message for the given key, aTextName, in the specified resource
bundle.
If a message is found, it will also be interpolated. | public static String | findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack, boolean warnIfNoMessageFound) Finds a localized text message for the given key, aTextName, in the specified resource
bundle.
If a message is found, it will also be interpolated. | public static Locale | localeFromString(String localeStr, Locale defaultLocale) Builds a
java.util.Locale from a String of the form en_US_foo into a Locale
with language "en", country "US" and variant "foo". | public static void | reset() Clears all the internal lists. | public static void | setReloadBundles(boolean reloadBundles) Should resorce bundles be reloaded. |
addDefaultResourceBundle | public static void addDefaultResourceBundle(String resourceBundleName)(Code) | | Add's the bundle to the internal list of default bundles.
If the bundle already exists in the list it will be readded.
Parameters: resourceBundleName - the name of the bundle to add. |
clearDefaultResourceBundles | public static void clearDefaultResourceBundles()(Code) | | Clears the internal list of resource bundles.
|
findDefaultText | public static String findDefaultText(String aTextName, Locale locale)(Code) | | Returns a localized message for the specified key, aTextName. Neither the key nor the
message is evaluated.
Parameters: aTextName - the message key Parameters: locale - the locale the message should be for a localized message based on the specified key, or null if no localized message can be found for it |
findDefaultText | public static String findDefaultText(String aTextName, Locale locale, Object[] params)(Code) | | Returns a localized message for the specified key, aTextName, substituting variables from the
array of params into the message. Neither the key nor the message is evaluated.
Parameters: aTextName - the message key Parameters: locale - the locale the message should be for Parameters: params - an array of objects to be substituted into the message text A formatted message based on the specified key, or null if no localized message can be found for it |
findResourceBundle | public static ResourceBundle findResourceBundle(String aBundleName, Locale locale)(Code) | | Finds the given resorce bundle by it's name.
Will use Thread.currentThread().getContextClassLoader() as the classloader.
Parameters: aBundleName - the name of the bundle (usually it's FQN classname). Parameters: locale - the locale. the bundle, null if not found. |
findText | public static String findText(Class aClass, String aTextName, Locale locale)(Code) | | Calls
LocalizedTextUtil.findText(Class aClass,String aTextName,Locale locale,String defaultMessage,Object[] args) with aTextName as the default message.
See Also: LocalizedTextUtil.findText(Class aClass,String aTextName,Locale locale,String defaultMessage,Object[] args) |
findText | public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)(Code) | | Finds a localized text message for the given key, aTextName. Both the key and the message
itself is evaluated as required. The following algorithm is used to find the requested
message:
- Look for message in aClass' class hierarchy.
- Look for the message in a resource bundle for aClass
- If not found, look for the message in a resource bundle for any implemented interface
- If not found, traverse up the Class' hierarchy and repeat from the first sub-step
- If not found and aClass is a
ModelDriven Action, then look for message in
the model's class hierarchy (repeat sub-steps listed above).
- If not found, look for message in child property. This is determined by evaluating
the message key as an OGNL expression. For example, if the key is
user.address.state, then it will attempt to see if "user" can be resolved into an
object. If so, repeat the entire process fromthe beginning with the object's class as
aClass and "address.state" as the message key.
- If not found, look for the message in aClass' package hierarchy.
- If still not found, look for the message in the default resource bundles.
- Return defaultMessage
When looking for the message, if the key indexes a collection (e.g. user.phone[0]) and a
message for that specific key cannot be found, the general form will also be looked up
(i.e. user.phone[*]).
If a message is found, it will also be interpolated. Anything within ${...}
will be treated as an OGNL expression and evaluated as such.
Parameters: aClass - the class whose name to use as the start point for the search Parameters: aTextName - the key to find the text message for Parameters: locale - the locale the message should be for Parameters: defaultMessage - the message to be returned if no text message can be found in anyresource bundle the localized text, or null if none can be found and no defaultMessage is provided |
findText | public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack)(Code) | | This method call will log a warning message (in debug level) if message is not found
Finds a localized text message for the given key, aTextName. Both the key and the message
itself is evaluated as required. The following algorithm is used to find the requested
message:
- Look for message in aClass' class hierarchy.
- Look for the message in a resource bundle for aClass
- If not found, look for the message in a resource bundle for any implemented interface
- If not found, traverse up the Class' hierarchy and repeat from the first sub-step
- If not found and aClass is a
ModelDriven Action, then look for message in
the model's class hierarchy (repeat sub-steps listed above).
- If not found, look for message in child property. This is determined by evaluating
the message key as an OGNL expression. For example, if the key is
user.address.state, then it will attempt to see if "user" can be resolved into an
object. If so, repeat the entire process fromthe beginning with the object's class as
aClass and "address.state" as the message key.
- If not found, look for the message in aClass' package hierarchy.
- If still not found, look for the message in the default resource bundles.
- Return defaultMessage
When looking for the message, if the key indexes a collection (e.g. user.phone[0]) and a
message for that specific key cannot be found, the general form will also be looked up
(i.e. user.phone[*]).
If a message is found, it will also be interpolated. Anything within ${...}
will be treated as an OGNL expression and evaluated as such.
If a message is not found a WARN log will be logged.
Parameters: aClass - the class whose name to use as the start point for the search Parameters: aTextName - the key to find the text message for Parameters: locale - the locale the message should be for Parameters: defaultMessage - the message to be returned if no text message can be found in anyresource bundle Parameters: valueStack - the value stack to use to evaluate expressions instead of theone in the ActionContext ThreadLocal the localized text, or null if none can be found and no defaultMessage is provided |
findText | public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack, boolean warnIfNoMessageFound)(Code) | | Finds a localized text message for the given key, aTextName. Both the key and the message
itself is evaluated as required. The following algorithm is used to find the requested
message:
- Look for message in aClass' class hierarchy.
- Look for the message in a resource bundle for aClass
- If not found, look for the message in a resource bundle for any implemented interface
- If not found, traverse up the Class' hierarchy and repeat from the first sub-step
- If not found and aClass is a
ModelDriven Action, then look for message in
the model's class hierarchy (repeat sub-steps listed above).
- If not found, look for message in child property. This is determined by evaluating
the message key as an OGNL expression. For example, if the key is
user.address.state, then it will attempt to see if "user" can be resolved into an
object. If so, repeat the entire process fromthe beginning with the object's class as
aClass and "address.state" as the message key.
- If not found, look for the message in aClass' package hierarchy.
- If still not found, look for the message in the default resource bundles.
- Return defaultMessage
When looking for the message, if the key indexes a collection (e.g. user.phone[0]) and a
message for that specific key cannot be found, the general form will also be looked up
(i.e. user.phone[*]).
If a message is found, it will also be interpolated. Anything within ${...}
will be treated as an OGNL expression and evaluated as such.
If a message is not found a WARN log will be logged.
Parameters: aClass - the class whose name to use as the start point for the search Parameters: aTextName - the key to find the text message for Parameters: locale - the locale the message should be for Parameters: defaultMessage - the message to be returned if no text message can be found in anyresource bundle Parameters: valueStack - the value stack to use to evaluate expressions instead of theone in the ActionContext ThreadLocal Parameters: warnIfNoMessageFound - log warning message (in debug level) if message is not found. the localized text, or null if none can be found and no defaultMessage is provided |
findText | public static String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args)(Code) | | Finds a localized text message for the given key, aTextName, in the specified resource
bundle.
If a message is found, it will also be interpolated. Anything within ${...}
will be treated as an OGNL expression and evaluated as such.
If a message is not found a WARN log will be logged.
Parameters: bundle - the bundle Parameters: aTextName - the key Parameters: locale - the locale Parameters: defaultMessage - the default message to use if no message was found in the bundle Parameters: args - arguments for the message formatter. |
findText | public static String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack)(Code) | | This method will log a warning (in debug level) if no message is found.
Finds a localized text message for the given key, aTextName, in the specified resource
bundle.
If a message is found, it will also be interpolated. Anything within ${...}
will be treated as an OGNL expression and evaluated as such.
If a message is not found a WARN log will be logged.
Parameters: bundle - the bundle Parameters: aTextName - the key Parameters: locale - the locale Parameters: defaultMessage - the default message to use if no message was found in the bundle Parameters: args - arguments for the message formatter. Parameters: valueStack - the OGNL value stack. |
findText | public static String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args, OgnlValueStack valueStack, boolean warnIfNoMessageFound)(Code) | | Finds a localized text message for the given key, aTextName, in the specified resource
bundle.
If a message is found, it will also be interpolated. Anything within ${...}
will be treated as an OGNL expression and evaluated as such.
If a message is not found a WARN log will be logged.
Parameters: bundle - the bundle Parameters: aTextName - the key Parameters: locale - the locale Parameters: defaultMessage - the default message to use if no message was found in the bundle Parameters: args - arguments for the message formatter. Parameters: valueStack - the OGNL value stack. |
localeFromString | public static Locale localeFromString(String localeStr, Locale defaultLocale)(Code) | | Builds a
java.util.Locale from a String of the form en_US_foo into a Locale
with language "en", country "US" and variant "foo". This will parse the output of
java.util.Locale.toString .
Parameters: localeStr - The locale String to parse. Parameters: defaultLocale - The locale to use if localeStr is null. requested Locale |
reset | public static void reset()(Code) | | Clears all the internal lists.
|
setReloadBundles | public static void setReloadBundles(boolean reloadBundles)(Code) | | Should resorce bundles be reloaded.
In WW see webwork.i18n.reload property.
Parameters: reloadBundles - reload bundles? |
|
|