Class GlobalLocalizedTextProvider
- All Implemented Interfaces:
- Serializable,- LocalizedTextProvider
 Note that unlike StrutsLocalizedTextProvider, this class GlobalLocalizedTextProvider will
 only search the default bundles for localized text.
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final ConcurrentMap<String,ResourceBundle> protected booleanprotected booleanprotected booleanstatic final Stringstatic final String
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddDefaultResourceBundle(String bundleName) Adds the bundle to the internal list of default bundles.protected MessageFormatbuildMessageFormat(String pattern, Locale locale) protected voidclearBundle(String bundleName, Locale locale) Clear a specific bundle + locale combination from thebundlesMap.protected voidClears themissingBundlescontents.protected StringextractIndexedName(String textKey) findDefaultText(String textKey, Locale locale) Returns a localized message for the specified key, aTextName.findDefaultText(String textKey, Locale locale, Object[] params) Returns a localized message for the specified key, aTextName, substituting variables from the array of params into the message.protected StringfindMessage(Class<?> clazz, String key, String indexedKey, Locale locale, Object[] args, Set<String> checked, ValueStack valueStack) Traverse up class hierarchy looking for message.findResourceBundle(String bundleName, Locale locale) Finds the given resource bundle by it's name.CallsLocalizedTextProvider.findText(Class startClazz, String textKey, Locale locale, String defaultMessage, Object[] args)with textKey as the default message.Finds a localized text message for the given key, textKey.findText(Class<?> startClazz, String textKey, Locale locale, String defaultMessage, Object[] args, ValueStack valueStack) Finds a localized text message for the given key, textKey.findText(ResourceBundle bundle, String textKey, Locale locale) Finds a localized text message for the given key, aTextName, in the specified resource bundle with aTextName as the default message.findText(ResourceBundle bundle, String textKey, Locale locale, String defaultMessage, Object[] args) Finds a localized text message for the given key, aTextName, in the specified resource bundle.findText(ResourceBundle bundle, String textKey, Locale locale, String defaultMessage, Object[] args, ValueStack valueStack) Finds a localized text message for the given key, aTextName, in the specified resource bundle.protected StringformatWithNullDetection(MessageFormat mf, Object[] args) protected ClassLoaderprotected org.apache.struts2.text.AbstractLocalizedTextProvider.GetDefaultMessageReturnArggetDefaultMessage(String key, Locale locale, ValueStack valueStack, Object[] args, String defaultMessage) protected org.apache.struts2.text.AbstractLocalizedTextProvider.GetDefaultMessageReturnArggetDefaultMessageWithAlternateKey(String key, String alternateKey, Locale locale, ValueStack valueStack, Object[] args, String defaultMessage) A helper method that can be used by descendant classes to perform some common two-stage message lookup operations against the default resource bundles.protected StringgetMessage(String bundleName, Locale locale, String key, ValueStack valueStack, Object[] args) protected voidlogMissingText(Class<?> startClazz, String textKey, Locale locale, org.apache.struts2.text.AbstractLocalizedTextProvider.GetDefaultMessageReturnArg result, String indexedTextName) protected voidprotected voidreloadBundles(Map<String, Object> context) voidsetCustomI18NResources(String bundles) voidsetDelegatedClassLoader(ClassLoader classLoader) voidsetDevMode(String devMode) voidsetReloadBundles(String reloadBundles) voidsetSearchDefaultBundlesFirst(String searchDefaultBundlesFirst) Set thesearchDefaultBundlesFirstflag state.protected booleanunableToFindTextForKey(org.apache.struts2.text.AbstractLocalizedTextProvider.GetDefaultMessageReturnArg result) Determines if we found the text in the bundles.
- 
Field Details- 
XWORK_MESSAGES_BUNDLE- See Also:
 
- 
STRUTS_MESSAGES_BUNDLE- See Also:
 
- 
bundlesMap
- 
devModeprotected boolean devMode
- 
reloadBundlesprotected boolean reloadBundles
- 
searchDefaultBundlesFirstprotected boolean searchDefaultBundlesFirst
 
- 
- 
Constructor Details- 
GlobalLocalizedTextProviderpublic GlobalLocalizedTextProvider()
 
- 
- 
Method Details- 
findTextDescription copied from interface:LocalizedTextProviderCallsLocalizedTextProvider.findText(Class startClazz, String textKey, Locale locale, String defaultMessage, Object[] args)with textKey as the default message.- Parameters:
- startClazz- class name
- textKey- text name
- locale- the locale
- Returns:
- the localized text, or null if none can be found and no defaultMessage is provided
- See Also:
 
- 
findTextpublic String findText(Class<?> startClazz, String textKey, Locale locale, String defaultMessage, Object[] args) Description copied from interface:LocalizedTextProviderFinds a localized text message for the given key, textKey. Both the key and the message itself is evaluated as required. The following algorithm is used to find the requested message:- Look for the message in the default resource bundles.
- If not found, 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:
- startClazz- the class whose name to use as the start point for the search
- textKey- the key to find the text message for
- locale- the locale the message should be for
- defaultMessage- the message to be returned if no text message can be found in any resource bundle
- args- arguments resource bundle
- Returns:
- the localized text, or null if none can be found and no defaultMessage is provided
 
- 
findTextpublic String findText(Class<?> startClazz, String textKey, Locale locale, String defaultMessage, Object[] args, ValueStack valueStack) Description copied from interface:LocalizedTextProviderFinds a localized text message for the given key, textKey. Both the key and the message itself is evaluated as required. The following algorithm is used to find the requested message:- Look for the message in the default resource bundles.
- If not found, 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 DEBUG level log warning will be logged. - Parameters:
- startClazz- the class whose name to use as the start point for the search
- textKey- the key to find the text message for
- locale- the locale the message should be for
- defaultMessage- the message to be returned if no text message can be found in any resource bundle
- args- arguments
- valueStack- the value stack to use to evaluate expressions instead of the one in the ActionContext ThreadLocal
- Returns:
- the localized text, or null if none can be found and no defaultMessage is provided
 
- 
findTextDescription copied from interface:LocalizedTextProviderFinds 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. Anything within ${...}will be treated as an OGNL expression and evaluated as such.- Parameters:
- bundle- a resource bundle name
- textKey- text name
- locale- the locale
- Returns:
- the localized text, or null if none can be found and no defaultMessage is provided
- See Also:
 
- 
findTextpublic String findText(ResourceBundle bundle, String textKey, Locale locale, String defaultMessage, Object[] args) Description copied from interface:LocalizedTextProviderFinds 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
- textKey- the key
- locale- the locale
- defaultMessage- the default message to use if no message was found in the bundle
- args- arguments for the message formatter.
- Returns:
- the localized text, or null if none can be found and no defaultMessage is provided
 
- 
addDefaultResourceBundleDescription copied from interface:LocalizedTextProviderAdds the bundle to the internal list of default bundles. If the bundle already exists in the list it will be re-added.- Specified by:
- addDefaultResourceBundlein interface- LocalizedTextProvider
- Parameters:
- bundleName- the name of the bundle to add.
 
- 
getCurrentBundleNames
- 
getCurrentThreadContextClassLoader
- 
setCustomI18NResources
- 
findDefaultTextDescription copied from interface:LocalizedTextProviderReturns a localized message for the specified key, aTextName. Neither the key nor the message is evaluated.- Specified by:
- findDefaultTextin interface- LocalizedTextProvider
- Parameters:
- textKey- the message key
- locale- the locale the message should be for
- Returns:
- a localized message based on the specified key, or null if no localized message can be found for it
 
- 
findDefaultTextDescription copied from interface:LocalizedTextProviderReturns 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.- Specified by:
- findDefaultTextin interface- LocalizedTextProvider
- Parameters:
- textKey- the message key
- locale- the locale the message should be for
- params- an array of objects to be substituted into the message text
- Returns:
- A formatted message based on the specified key, or null if no localized message can be found for it
 
- 
findTextpublic String findText(ResourceBundle bundle, String textKey, Locale locale, String defaultMessage, Object[] args, ValueStack valueStack) Description copied from interface:LocalizedTextProviderFinds 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. - Specified by:
- findTextin interface- LocalizedTextProvider
- Parameters:
- bundle- the bundle
- textKey- the key
- locale- the locale
- defaultMessage- the default message to use if no message was found in the bundle
- args- arguments for the message formatter.
- valueStack- the OGNL value stack.
- Returns:
- the localized text, or null if none can be found and no defaultMessage is provided
 
- 
setDelegatedClassLoader- Parameters:
- classLoader- a- ClassLoaderto look up the bundle from if none can be found on the current thread's classloader
 
- 
clearBundleClear a specific bundle + locale combination from thebundlesMap. Intended for descendants to use clear a bundle + locale combination.- Parameters:
- bundleName- The bundle (combined with locale) to remove from the bundle map
- locale- Provides the locale to combine with the bundle to get the key
- Since:
- 6.0.0
 
- 
clearMissingBundlesCacheprotected void clearMissingBundlesCache()Clears themissingBundlescontents. This allows descendants to clear the "missing bundles cache" when desired (or needed).Note: This method may be used when the bundlesMapstate has changed in such a way that bundles that were previously "missing" may now be available (e.g. after callingLocalizedTextProvider.addDefaultResourceBundle(java.lang.String)when theAbstractLocalizedTextProviderhas already been used for failed bundle lookups of a given key, or some transitory state made a bundle lookup fail.- Since:
- 6.0.0
 
- 
reloadBundlesprotected void reloadBundles()
- 
reloadBundles
- 
buildMessageFormat
- 
formatWithNullDetection
- 
setReloadBundles
- 
setDevMode
- 
setSearchDefaultBundlesFirstSet thesearchDefaultBundlesFirstflag state. This flag may be used by descendant TextProvider implementations to determine if default bundles should be searched for messages first (before the standard flow of theLocalizedTextProviderimplementation the descendant provides).- Parameters:
- searchDefaultBundlesFirst- provide- String"true" or "false" to set the flag state accordingly.
- Since:
- 6.0.0
 
- 
findResourceBundleDescription copied from interface:LocalizedTextProviderFinds the given resource bundle by it's name.Will use Thread.currentThread().getContextClassLoader()as the classloader.- Specified by:
- findResourceBundlein interface- LocalizedTextProvider
- Parameters:
- bundleName- the name of the bundle (usually it's FQN classname).
- locale- the locale.
- Returns:
- the bundle, null if not found.
 
- 
unableToFindTextForKeyprotected boolean unableToFindTextForKey(org.apache.struts2.text.AbstractLocalizedTextProvider.GetDefaultMessageReturnArg result) Determines if we found the text in the bundles.- Parameters:
- result- the result so far
- Returns:
- true if we could not find the text, false if the text was found (=success).
 
- 
getDefaultMessageprotected org.apache.struts2.text.AbstractLocalizedTextProvider.GetDefaultMessageReturnArg getDefaultMessage(String key, Locale locale, ValueStack valueStack, Object[] args, String defaultMessage) - Returns:
- the default message.
 
- 
getDefaultMessageWithAlternateKeyprotected org.apache.struts2.text.AbstractLocalizedTextProvider.GetDefaultMessageReturnArg getDefaultMessageWithAlternateKey(String key, String alternateKey, Locale locale, ValueStack valueStack, Object[] args, String defaultMessage) A helper method that can be used by descendant classes to perform some common two-stage message lookup operations against the default resource bundles. The default resource bundles are searched for a value using key first, then alternateKey when the first search fails, then utilizing defaultMessage (which may benull) if both key lookup operations fail.A known use case is when a key indexes a collection (e.g. user.phone[0]) for which some specific keys may exist, but not all, along with a general key (e.g. user.phone[*]). In such cases the specific key would be passed in the key parameter and the general key would be passed in the alternateKey parameter. - Parameters:
- key- the initial key to search for a value within the default resource bundles.
- alternateKey- the alternate (fall-back) key to search for a value within the default resource bundles, if the initial key lookup fails.
- locale- the- Localeto be used for the default resource bundle lookup.
- valueStack- the- ValueStackassociated with the operation.
- args- the argument array for parameterized messages (may be- null).
- defaultMessage- the default message- Stringto use if both key lookup operations fail.
- Returns:
- the AbstractLocalizedTextProvider.GetDefaultMessageReturnArgresult containing the processed message lookup (by key first, then alternateKey if key's lookup fails). If both key lookup operations fail, defaultMessage is used for processing. If defaultMessage isnullthen the return result may benull.
 
- 
getMessageprotected String getMessage(String bundleName, Locale locale, String key, ValueStack valueStack, Object[] args) - Returns:
- the message from the named resource bundle.
 
- 
findMessageprotected String findMessage(Class<?> clazz, String key, String indexedKey, Locale locale, Object[] args, Set<String> checked, ValueStack valueStack) Traverse up class hierarchy looking for message. Looks at class, then implemented interface, before going up hierarchy.- Returns:
- the message
 
- 
extractIndexedName
- 
logMissingText
 
-