Interface TextProvider
- All Known Subinterfaces:
- ResourceBundleTextProvider,- ValidatorContext
- All Known Implementing Classes:
- ActionSupport,- CompositeTextProvider,- CspReportAction,- DefaultActionSupport,- DefaultCspReportAction,- DefaultTextProvider,- DelegatingValidatorContext,- TextProviderSupport,- VisitorFieldValidator.AppendingValidatorContext
ResourceBundles and their underlying text messages.
 Implementing classes can delegate TextProviderSupport. Messages will be
 searched in multiple resource bundles, starting with the one associated with
 this particular class (action in most cases), continuing to try the message
 bundle associated with each superclass as well. It will stop once a bundle is
 found that contains the given text. This gives a cascading style that allow
 global texts to be defined for an application base class.
 
 You can override LocaleProvider.getLocale() to change the behaviour of how
 to choose locale for the bundles that are returned. Typically you would
 use the LocaleProvider interface to get the users configured locale.
 
When you want to use your own implementation for Struts 2 project you have to define following bean and constant in struts.xml: <bean class="org.demo.MyTextProvider" name="myTextProvider" type="org.apache.struts.TextProvider" /> <constant name="struts.textProvider" value="myTextProvider" />
if you want to also use your implementation for framework's messages define another constant (remember to put into it all framework messages) <constant name="system" value="myTextProvider" />
 Take a look on ActionSupport for example TextProvider implementation.
 
- Author:
- Jason Carreira, Rainer Hermanns
- See Also:
- 
Method SummaryModifier and TypeMethodDescriptionGets a message based on a message key or if no message is found the provided key is returned.Gets a message based on a key, or, if the message is not found, a supplied default value is returned.Gets a message based on a key using the supplied args, as defined inMessageFormat, or the provided key if no message is found.Gets a message based on a key using the supplied obj, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.Gets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.getText(String key, String defaultValue, String[] args, ValueStack stack) Gets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.Gets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.getText(String key, String defaultValue, List<?> args, ValueStack stack) Gets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.Gets a message based on a key using the supplied args, as defined inMessageFormator the provided key if no message is found.getTexts()Get the resource bundle associated with the implementing class (usually an action).Get the named bundle, such as "com/acme/Foo".booleanChecks if a message key exists.
- 
Method Details- 
hasKeyChecks if a message key exists.- Parameters:
- key- message key to check for
- Returns:
- boolean true if key exists, false otherwise.
 
- 
getTextGets a message based on a message key or if no message is found the provided key is returned.- Parameters:
- key- the resource bundle key that is to be searched for
- Returns:
- the message as found in the resource bundle, or the provided key if none is found.
 
- 
getTextGets a message based on a key, or, if the message is not found, a supplied default value is returned.- Parameters:
- key- the resource bundle key that is to be searched for
- defaultValue- the default value which will be returned if no message is found
- Returns:
- the message as found in the resource bundle, or defaultValue if none is found
 
- 
getTextGets a message based on a key using the supplied obj, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.- Parameters:
- key- the resource bundle key that is to be searched for
- defaultValue- the default value which will be returned if no message is found
- obj- obj to be used in a- MessageFormatmessage
- Returns:
- the message as found in the resource bundle, or defaultValue if none is found
 
- 
getTextGets a message based on a key using the supplied args, as defined inMessageFormator the provided key if no message is found.- Parameters:
- key- the resource bundle key that is to be searched for
- args- a list args to be used in a- MessageFormatmessage
- Returns:
- the message as found in the resource bundle, or the provided key if none is found.
 
- 
getTextGets a message based on a key using the supplied args, as defined inMessageFormat, or the provided key if no message is found.- Parameters:
- key- the resource bundle key that is to be searched for
- args- an array args to be used in a- MessageFormatmessage
- Returns:
- the message as found in the resource bundle, or the provided key if none is found.
 
- 
getTextGets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.- Parameters:
- key- the resource bundle key that is to be searched for
- defaultValue- the default value which will be returned if no message is found
- args- a list args to be used in a- MessageFormatmessage
- Returns:
- the message as found in the resource bundle, or defaultValue if none is found
 
- 
getTextGets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.- Parameters:
- key- the resource bundle key that is to be searched for
- defaultValue- the default value which will be returned if no message is found
- args- an array args to be used in a- MessageFormatmessage
- Returns:
- the message as found in the resource bundle, or defaultValue if none is found
 
- 
getTextGets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned. Instead of using the value stack in the ActionContext this version of the getText() method uses the provided value stack.- Parameters:
- key- the resource bundle key that is to be searched for
- defaultValue- the default value which will be returned if no message is found
- args- a list args to be used in a- MessageFormatmessage
- stack- the value stack to use for finding the text
- Returns:
- the message as found in the resource bundle, or defaultValue if none is found
 
- 
getTextGets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned. Instead of using the value stack in the ActionContext this version of the getText() method uses the provided value stack.- Parameters:
- key- the resource bundle key that is to be searched for
- defaultValue- the default value which will be returned if no message is found
- args- an array args to be used in a- MessageFormatmessage
- stack- the value stack to use for finding the text
- Returns:
- the message as found in the resource bundle, or defaultValue if none is found
 
- 
getTextsGet the named bundle, such as "com/acme/Foo".- Parameters:
- bundleName- the name of the resource bundle, such as- "com/acme/Foo".
- Returns:
- the bundle
 
- 
getTextsResourceBundle getTexts()Get the resource bundle associated with the implementing class (usually an action).- Returns:
- the bundle
 
 
-