Package org.apache.struts2.text

# Class DefaultTextProvider

java.lang.Object
org.apache.struts2.text.DefaultTextProvider

All Implemented Interfaces:
  `Serializable`, `TextProvider`, `Unchainable`

public class DefaultTextProvider extends Object implements TextProvider, Serializable, Unchainable
DefaultTextProvider gets texts from only the default resource bundles associated with the default bundles.

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected LocalizedTextProvider`
  `localizedTextProvider`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DefaultTextProvider()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getText(String key)`
  Gets a message based on a message key or if no message is found the provided key is returned.
  `String`
  `getText(String key, String defaultValue)`
  Gets a message based on a key, or, if the message is not found, a supplied default value is returned.
  `String`
  `getText(String key, String[] args)`
  Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or the provided key if no message is found.
  `String`
  `getText(String key, String defaultValue, String obj)`
  Gets a message based on a key using the supplied obj, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
  `String`
  `getText(String key, String defaultValue, String[] args)`
  Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
  `String`
  `getText(String key, String defaultValue, String[] args, ValueStack stack)`
  Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
  `String`
  `getText(String key, String defaultValue, List<?> args)`
  Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
  `String`
  `getText(String key, String defaultValue, List<?> args, ValueStack stack)`
  Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
  `String`
  `getText(String key, List<?> args)`
  Gets a message based on a key using the supplied args, as defined in `MessageFormat` or the provided key if no message is found.
  `ResourceBundle`
  `getTexts()`
  Get the resource bundle associated with the implementing class (usually an action).
  `ResourceBundle`
  `getTexts(String bundleName)`
  Get the named bundle, such as "com/acme/Foo".
  `boolean`
  `hasKey(String key)`
  Checks if a message key exists.
  `void`
  `setLocalizedTextProvider(LocalizedTextProvider localizedTextProvider)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### localizedTextProvider

    protected LocalizedTextProvider localizedTextProvider

- ## Constructor Details

  - ### DefaultTextProvider

    public DefaultTextProvider()

- ## Method Details

  - ### setLocalizedTextProvider

    public void setLocalizedTextProvider(LocalizedTextProvider localizedTextProvider)

  - ### hasKey

    public boolean hasKey(String key)
    Description copied from interface: `TextProvider`
    Checks if a message key exists.
    Specified by:
      `hasKey` in interface `TextProvider`
    Parameters:
      `key` - message key to check for
    Returns:
      boolean true if key exists, false otherwise.

  - ### getText

    public String getText(String key)
    Description copied from interface: `TextProvider`
    Gets a message based on a message key or if no message is found the provided key is returned.
    Specified by:
      `getText` in interface `TextProvider`
    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.

  - ### getText

    public String getText(String key, String defaultValue)
    Description copied from interface: `TextProvider`
    Gets a message based on a key, or, if the message is not found, a supplied default value is returned.
    Specified by:
      `getText` in interface `TextProvider`
    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

  - ### getText

    public String getText(String key, List<?> args)
    Description copied from interface: `TextProvider`
    Gets a message based on a key using the supplied args, as defined in `MessageFormat` or the provided key if no message is found.
    Specified by:
      `getText` in interface `TextProvider`
    Parameters:
      `key` - the resource bundle key that is to be searched for
      `args` - a list args to be used in a `MessageFormat` message
    Returns:
      the message as found in the resource bundle, or the provided key if none is found.

  - ### getText

    public String getText(String key, String[] args)
    Description copied from interface: `TextProvider`
    Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or the provided key if no message is found.
    Specified by:
      `getText` in interface `TextProvider`
    Parameters:
      `key` - the resource bundle key that is to be searched for
      `args` - an array args to be used in a `MessageFormat` message
    Returns:
      the message as found in the resource bundle, or the provided key if none is found.

  - ### getText

    public String getText(String key, String defaultValue, List<?> args)
    Description copied from interface: `TextProvider`
    Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
    Specified by:
      `getText` in interface `TextProvider`
    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 `MessageFormat` message
    Returns:
      the message as found in the resource bundle, or defaultValue if none is found

  - ### getText

    public String getText(String key, String defaultValue, String[] args)
    Description copied from interface: `TextProvider`
    Gets a message based on a key using the supplied args, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
    Specified by:
      `getText` in interface `TextProvider`
    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 `MessageFormat` message
    Returns:
      the message as found in the resource bundle, or defaultValue if none is found

  - ### getText

    public String getText(String key, String defaultValue, String obj)
    Description copied from interface: `TextProvider`
    Gets a message based on a key using the supplied obj, as defined in `MessageFormat`, or, if the message is not found, a supplied default value is returned.
    Specified by:
      `getText` in interface `TextProvider`
    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 `MessageFormat` message
    Returns:
      the message as found in the resource bundle, or defaultValue if none is found

  - ### getText

    public String getText(String key, String defaultValue, List<?> args, ValueStack stack)
    Description copied from interface: `TextProvider`
    Gets a message based on a key using the supplied args, as defined in `MessageFormat`, 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.
    Specified by:
      `getText` in interface `TextProvider`
    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 `MessageFormat` message
      `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

  - ### getText

    public String getText(String key, String defaultValue, String[] args, ValueStack stack)
    Description copied from interface: `TextProvider`
    Gets a message based on a key using the supplied args, as defined in `MessageFormat`, 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.
    Specified by:
      `getText` in interface `TextProvider`
    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 `MessageFormat` message
      `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

  - ### getTexts

    public ResourceBundle getTexts(String bundleName)
    Description copied from interface: `TextProvider`
    Get the named bundle, such as "com/acme/Foo".
    Specified by:
      `getTexts` in interface `TextProvider`
    Parameters:
      `bundleName` - the name of the resource bundle, such as `"com/acme/Foo"`.
    Returns:
      the bundle

  - ### getTexts

    public ResourceBundle getTexts()
    Description copied from interface: `TextProvider`
    Get the resource bundle associated with the implementing class (usually an action).
    Specified by:
      `getTexts` in interface `TextProvider`
    Returns:
      the bundle