org.springframework.context.support

## 类 MessageSourceSupport

- java.lang.Object
- - org.springframework.context.support.MessageSourceSupport

- 直接已知子类:
    AbstractMessageSource, DelegatingMessageSource

      public abstract class MessageSourceSupport
      extends Object

  Base class for message source implementations, providing support infrastructure such as `MessageFormat` handling but not implementing concrete methods defined in the `MessageSource`.

  `AbstractMessageSource` derives from this class, providing concrete `getMessage` implementations that delegate to a central template method for message code resolution.

  从以下版本开始:
    2.5.5
  作者:
    Juergen Hoeller

- - ### 字段概要

    字段
    限定符和类型 | 字段和说明
    --- | ---
    `protected Log` | `logger` Logger available to subclasses

  - ### 构造器概要

    构造器
    构造器和说明
    `MessageSourceSupport()`

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `protected MessageFormat` | `createMessageFormat(String msg, Locale locale)` Create a MessageFormat for the given message and Locale.
    `protected String` | `formatMessage(String msg, Object[] args, Locale locale)` Format the given message String, using cached MessageFormats.
    `protected boolean` | `isAlwaysUseMessageFormat()` Return whether to always apply the MessageFormat rules, parsing even messages without arguments.
    `protected String` | `renderDefaultMessage(String defaultMessage, Object[] args, Locale locale)` Render the given default message String.
    `protected Object[]` | `resolveArguments(Object[] args, Locale locale)` Template method for resolving argument objects.
    `void` | `setAlwaysUseMessageFormat(boolean alwaysUseMessageFormat)` Set whether to always apply the `MessageFormat` rules, parsing even messages without arguments.

    - ### 从类继承的方法 java.lang.Object

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

- - ### 字段详细资料

    - #### logger

          protected final Log logger

      Logger available to subclasses

  - ### 构造器详细资料

    - #### MessageSourceSupport

          public MessageSourceSupport()

  - ### 方法详细资料

    - #### setAlwaysUseMessageFormat

          public void setAlwaysUseMessageFormat(boolean alwaysUseMessageFormat)

      Set whether to always apply the `MessageFormat` rules, parsing even messages without arguments.

      Default is "false": Messages without arguments are by default returned as-is, without parsing them through MessageFormat. Set this to "true" to enforce MessageFormat for all messages, expecting all message texts to be written with MessageFormat escaping.

      For example, MessageFormat expects a single quote to be escaped as "''". If your message texts are all written with such escaping, even when not defining argument placeholders, you need to set this flag to "true". Else, only message texts with actual arguments are supposed to be written with MessageFormat escaping.

      另请参阅:
        `MessageFormat`

    - #### isAlwaysUseMessageFormat

          protected boolean isAlwaysUseMessageFormat()

      Return whether to always apply the MessageFormat rules, parsing even messages without arguments.

    - #### renderDefaultMessage

          protected String renderDefaultMessage(String defaultMessage,
                                                @Nullable
                                                Object[] args,
                                                Locale locale)

      Render the given default message String. The default message is passed in as specified by the caller and can be rendered into a fully formatted default message shown to the user.

      The default implementation passes the String to `formatMessage`, resolving any argument placeholders found in them. Subclasses may override this method to plug in custom processing of default messages.

      参数:
        `defaultMessage` - the passed-in default message String
        `args` - array of arguments that will be filled in for params within the message, or `null` if none.
        `locale` - the Locale used for formatting
      返回:
        the rendered default message (with resolved arguments)
      另请参阅:
        `formatMessage(String, Object[], java.util.Locale)`

    - #### formatMessage

          protected String formatMessage(String msg,
                                         @Nullable
                                         Object[] args,
                                         Locale locale)

      Format the given message String, using cached MessageFormats. By default invoked for passed-in default messages, to resolve any argument placeholders found in them.
      参数:
        `msg` - the message to format
        `args` - array of arguments that will be filled in for params within the message, or `null` if none
        `locale` - the Locale used for formatting
      返回:
        the formatted message (with resolved arguments)

    - #### createMessageFormat

          protected MessageFormat createMessageFormat(String msg,
                                                      Locale locale)

      Create a MessageFormat for the given message and Locale.
      参数:
        `msg` - the message to create a MessageFormat for
        `locale` - the Locale to create a MessageFormat for
      返回:
        the MessageFormat instance

    - #### resolveArguments

          protected Object[] resolveArguments(@Nullable
                                              Object[] args,
                                              Locale locale)

      Template method for resolving argument objects.

      The default implementation simply returns the given argument array as-is. Can be overridden in subclasses in order to resolve special argument types.

      参数:
        `args` - the original argument array
        `locale` - the Locale to resolve against
      返回:
        the resolved argument array