com.opensymphony.xwork2

## Class CompositeTextProvider

- java.lang.Object
- - com.opensymphony.xwork2.CompositeTextProvider

- All Implemented Interfaces:
    TextProvider

      public class CompositeTextProvider
      extends Object
      implements TextProvider

  This is a composite `TextProvider` that takes in an array or `List` of `TextProvider`s, it will consult each of them in order to get a composite result. To know how each method behaves, please refer to the javadoc for each methods.
  Author:
    tmjee

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `CompositeTextProvider(List<TextProvider> textProviders)` Instantiates a `CompositeTextProvider` with some predefined `textProviders`.
    `CompositeTextProvider(TextProvider[] textProviders)` Instantiates a `CompositeTextProvider` with some predefined `textProviders`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getText(String key)` It will consult each `TextProvider`s and return the first valid message for this `key`
    `String` | `getText(String key, List<?> args)` It will consult each `TextProvider`s and return the first valid message for this `key`.
    `String` | `getText(String key, String defaultValue)` It will consult each `TextProvider`s and return the first valid message for this `key` before returning `defaultValue` if every else fails.
    `String` | `getText(String key, String[] args)` It will consult each `TextProvider`s and return the first valid message for this `key`.
    `String` | `getText(String key, String defaultValue, List<?> args)` It will consult each `TextProvider`s and return the first valid message for this `key`, before returning `defaultValue`
    `String` | `getText(String key, String defaultValue, List<?> args, ValueStack stack)` It will consult each `TextProvider`s and return the first valid message for this `key`, before returning `defaultValue`
    `String` | `getText(String key, String defaultValue, String obj)` It will consult each `TextProvider`s and return the first valid message for this `key`, before returning `defaultValue` if every else fails.
    `String` | `getText(String key, String defaultValue, String[] args)` It will consult each `TextProvider`s and return the first valid message for this `key`, before returning `defaultValue`.
    `String` | `getText(String key, String defaultValue, String[] args, ValueStack stack)` It will consult each `TextProvider`s and return the first valid message for this `key`, before returning `defaultValue`
    `ResourceBundle` | `getTexts()` It will consult each `TextProvider`s and return the first non-null `ResourceBundle`.
    `ResourceBundle` | `getTexts(String bundleName)` It will consult each `TextProvider`s and return the first non-null `ResourceBundle`.
    `boolean` | `hasKey(String key)` It will consult each individual `TextProvider`s and return true if either one of the `TextProvider`" has such a `key` else false.

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

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

- - ### Constructor Detail

    - #### CompositeTextProvider

          public CompositeTextProvider(List<TextProvider> textProviders)

      Instantiates a `CompositeTextProvider` with some predefined `textProviders`.
      Parameters:
        `textProviders` - list of text providers

    - #### CompositeTextProvider

          public CompositeTextProvider(TextProvider[] textProviders)

      Instantiates a `CompositeTextProvider` with some predefined `textProviders`.
      Parameters:
        `textProviders` - array of text providers

  - ### Method Detail

    - #### hasKey

          public boolean hasKey(String key)

      It will consult each individual `TextProvider`s and return true if either one of the `TextProvider`" has such a `key` else false.
      Specified by:
        `hasKey` in interface `TextProvider`
      Parameters:
        `key` - The key to lookup in resource bundles.
      Returns:
        `true`, if the requested key is found in one of the resource bundles.
      See Also:
        `TextProvider.hasKey(String)`

    - #### getText

          public String getText(String key)

      It will consult each `TextProvider`s and return the first valid message for this `key`
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - The key to lookup in resource bundles.
      Returns:
        The i18n text for the requested key.
      See Also:
        `TextProvider.getText(String)`

    - #### getText

          public String getText(String key,
                                String defaultValue)

      It will consult each `TextProvider`s and return the first valid message for this `key` before returning `defaultValue` if every else fails.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - the message key
        `defaultValue` - the default value
      Returns:
        the first valid message for the key or default value
      See Also:
        `TextProvider.getText(String, String)`

    - #### getText

          public String getText(String key,
                                String defaultValue,
                                String obj)

      It will consult each `TextProvider`s and return the first valid message for this `key`, before returning `defaultValue` if every else fails.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - the message key
        `defaultValue` - the default value
        `obj` - object
      Returns:
        the first valid message for the key or default value
      See Also:
        `TextProvider.getText(String, String, String)`

    - #### getText

          public String getText(String key,
                                List<?> args)

      It will consult each `TextProvider`s and return the first valid message for this `key`.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - the message key
        `args` - additional arguments
      Returns:
        the first valid message for the key
      See Also:
        `TextProvider.getText(String, java.util.List)`

    - #### getText

          public String getText(String key,
                                String[] args)

      It will consult each `TextProvider`s and return the first valid message for this `key`.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - the message key
        `args` - additional arguments
      Returns:
        the first valid message for the key or default value
      See Also:
        `TextProvider.getText(String, String[])`

    - #### getText

          public String getText(String key,
                                String defaultValue,
                                List<?> args)

      It will consult each `TextProvider`s and return the first valid message for this `key`, before returning `defaultValue`
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - the message key
        `defaultValue` - the default value
        `args` - additional arguments
      Returns:
        the first valid message for the key or default value
      See Also:
        `TextProvider.getText(String, String, java.util.List)`

    - #### getText

          public String getText(String key,
                                String defaultValue,
                                String[] args)

      It will consult each `TextProvider`s and return the first valid message for this `key`, before returning `defaultValue`.
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - the message key
        `defaultValue` - the default value
        `args` - additional arguments
      Returns:
        the first valid message for the key or default value
      See Also:
        `TextProvider.getText(String, String, String[])`

    - #### getText

          public String getText(String key,
                                String defaultValue,
                                List<?> args,
                                ValueStack stack)

      It will consult each `TextProvider`s and return the first valid message for this `key`, before returning `defaultValue`
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - the message key
        `defaultValue` - the default value
        `args` - additional arguments
        `stack` - the value stack
      Returns:
        the first valid message for the key or default value
      See Also:
        `TextProvider.getText(String, String, java.util.List, com.opensymphony.xwork2.util.ValueStack)`

    - #### getText

          public String getText(String key,
                                String defaultValue,
                                String[] args,
                                ValueStack stack)

      It will consult each `TextProvider`s and return the first valid message for this `key`, before returning `defaultValue`
      Specified by:
        `getText` in interface `TextProvider`
      Parameters:
        `key` - the message key
        `defaultValue` - the default value
        `args` - additional arguments
        `stack` - the value stack
      Returns:
        the first valid message for the key or default value
      See Also:
        `TextProvider.getText(String, String, String[], com.opensymphony.xwork2.util.ValueStack)`

    - #### getTexts

          public ResourceBundle getTexts(String bundleName)

      It will consult each `TextProvider`s and return the first non-null `ResourceBundle`.
      Specified by:
        `getTexts` in interface `TextProvider`
      Parameters:
        `bundleName` - the bundle name
      Returns:
        the resource bundle found for bundle name
      See Also:
        `TextProvider.getTexts(String)`

    - #### getTexts

          public ResourceBundle getTexts()

      It will consult each `TextProvider`s and return the first non-null `ResourceBundle`.
      Specified by:
        `getTexts` in interface `TextProvider`
      Returns:
        the resource bundle
      See Also:
        `TextProvider.getTexts()`

Copyright © 2000–2026 Apache Software Foundation. All rights reserved.