|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.opensymphony.xwork2.util.LocalizedTextUtil
public class LocalizedTextUtil
Provides support for localization in XWork. Resource bundles are searched in the following order:
Nested Class Summary | |
---|---|
(package private) static class |
LocalizedTextUtil.GetDefaultMessageReturnArg
|
(package private) static class |
LocalizedTextUtil.MessageFormatKey
|
Field Summary | |
---|---|
private static List |
DEFAULT_RESOURCE_BUNDLES
|
private static Logger |
LOG
|
private static Map |
messageFormats
|
private static Map<String,String> |
misses
|
private static boolean |
reloadBundles
|
Constructor Summary | |
---|---|
LocalizedTextUtil()
|
Method Summary | |
---|---|
static void |
addDefaultResourceBundle(String resourceBundleName)
Add's the bundle to the internal list of default bundles. |
private static MessageFormat |
buildMessageFormat(String pattern,
Locale locale)
|
static void |
clearDefaultResourceBundles()
Clears the internal list of resource bundles. |
private static void |
clearMap(Class cl,
Object obj,
String name)
|
private static void |
clearTomcatCache()
|
private static String |
createMissesKey(String aBundleName,
Locale locale)
Creates a key to used for lookup/storing in the bundle misses cache. |
static String |
findDefaultText(String aTextName,
Locale locale)
Returns a localized message for the specified key, aTextName. |
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. |
private static String |
findMessage(Class clazz,
String key,
String indexedKey,
Locale locale,
Object[] args,
Set checked,
ValueStack valueStack)
Traverse up class hierarchy looking for message. |
static ResourceBundle |
findResourceBundle(String aBundleName,
Locale locale)
Finds the given resorce bundle by it's name. |
static String |
findText(Class aClass,
String aTextName,
Locale locale)
Calls findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)
with aTextName as the default message. |
static String |
findText(Class aClass,
String aTextName,
Locale locale,
String defaultMessage,
Object[] args)
Finds a localized text message for the given key, aTextName. |
static String |
findText(Class aClass,
String aTextName,
Locale locale,
String defaultMessage,
Object[] args,
ValueStack valueStack)
Finds a localized text message for the given key, aTextName. |
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. |
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. |
static String |
findText(ResourceBundle bundle,
String aTextName,
Locale locale,
String defaultMessage,
Object[] args,
ValueStack valueStack)
Finds a localized text message for the given key, aTextName, in the specified resource bundle. |
private static LocalizedTextUtil.GetDefaultMessageReturnArg |
getDefaultMessage(String key,
Locale locale,
ValueStack valueStack,
Object[] args,
String defaultMessage)
Gets the default message. |
private static String |
getMessage(String bundleName,
Locale locale,
String key,
ValueStack valueStack,
Object[] args)
Gets the message from the named resource bundle. |
static Locale |
localeFromString(String localeStr,
Locale defaultLocale)
Builds a Locale from a String of the form en_US_foo into a Locale
with language "en", country "US" and variant "foo". |
private static void |
reloadBundles()
|
static void |
reset()
Clears all the internal lists. |
static void |
setReloadBundles(boolean reloadBundles)
Should resorce bundles be reloaded. |
private static boolean |
unableToFindTextForKey(LocalizedTextUtil.GetDefaultMessageReturnArg result)
Determines if we found the text in the bundles. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static List DEFAULT_RESOURCE_BUNDLES
private static final Logger LOG
private static boolean reloadBundles
private static final Map<String,String> misses
private static final Map messageFormats
Constructor Detail |
---|
public LocalizedTextUtil()
Method Detail |
---|
public static void clearDefaultResourceBundles()
public static void setReloadBundles(boolean reloadBundles)
reloadBundles
- reload bundles?public static void addDefaultResourceBundle(String resourceBundleName)
resourceBundleName
- the name of the bundle to add.public static Locale localeFromString(String localeStr, Locale defaultLocale)
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
Locale.toString()
.
localeStr
- The locale String to parse.defaultLocale
- The locale to use if localeStr is null.
public static String findDefaultText(String aTextName, Locale locale)
aTextName
- the message keylocale
- the locale the message should be for
public static String findDefaultText(String aTextName, Locale locale, Object[] params)
aTextName
- the message keylocale
- the locale the message should be forparams
- an array of objects to be substituted into the message text
public static ResourceBundle findResourceBundle(String aBundleName, Locale locale)
Thread.currentThread().getContextClassLoader()
as the classloader.
aBundleName
- the name of the bundle (usually it's FQN classname).locale
- the locale.
private static String createMissesKey(String aBundleName, Locale locale)
aBundleName
- the name of the bundle (usually it's FQN classname).locale
- the locale.
public static String findText(Class aClass, String aTextName, Locale locale)
findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)
with aTextName as the default message.
findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)
public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args)
ModelDriven
Action, then look for message in
the model's class hierarchy (repeat sub-steps listed above).${...}
will be treated as an OGNL expression and evaluated as such.
aClass
- the class whose name to use as the start point for the searchaTextName
- the key to find the text message forlocale
- the locale the message should be fordefaultMessage
- the message to be returned if no text message can be found in any
resource bundle
public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args, ValueStack valueStack)
ModelDriven
Action, then look for message in
the model's class hierarchy (repeat sub-steps listed above).${...}
will be treated as an OGNL expression and evaluated as such.
If a message is not found a WARN log will be logged.
aClass
- the class whose name to use as the start point for the searchaTextName
- the key to find the text message forlocale
- the locale the message should be fordefaultMessage
- the message to be returned if no text message can be found in any
resource bundlevalueStack
- the value stack to use to evaluate expressions instead of the
one in the ActionContext ThreadLocal
private static boolean unableToFindTextForKey(LocalizedTextUtil.GetDefaultMessageReturnArg result)
result
- the result so far
public static String findText(ResourceBundle bundle, String aTextName, Locale locale)
${...}
will be treated as an OGNL expression and evaluated as such.
findText(java.util.ResourceBundle, String, java.util.Locale, String, Object[])
public static String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args)
${...}
will be treated as an OGNL expression and evaluated as such.
If a message is not found a WARN log will be logged.
bundle
- the bundleaTextName
- the keylocale
- the localedefaultMessage
- the default message to use if no message was found in the bundleargs
- arguments for the message formatter.public static String findText(ResourceBundle bundle, String aTextName, Locale locale, String defaultMessage, Object[] args, ValueStack valueStack)
${...}
will be treated as an OGNL expression and evaluated as such.
If a message is not found a WARN log will be logged.
bundle
- the bundleaTextName
- the keylocale
- the localedefaultMessage
- the default message to use if no message was found in the bundleargs
- arguments for the message formatter.valueStack
- the OGNL value stack.private static LocalizedTextUtil.GetDefaultMessageReturnArg getDefaultMessage(String key, Locale locale, ValueStack valueStack, Object[] args, String defaultMessage)
private static String getMessage(String bundleName, Locale locale, String key, ValueStack valueStack, Object[] args)
private static MessageFormat buildMessageFormat(String pattern, Locale locale)
private static String findMessage(Class clazz, String key, String indexedKey, Locale locale, Object[] args, Set checked, ValueStack valueStack)
private static void reloadBundles()
private static void clearTomcatCache()
private static void clearMap(Class cl, Object obj, String name) throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException
NoSuchFieldException
IllegalAccessException
NoSuchMethodException
InvocationTargetException
public static void reset()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |