Class MessageSourceSupport
- java.lang.Object
-
- com.aspectran.core.support.i18n.message.MessageSourceSupport
-
- Direct Known Subclasses:
AbstractMessageSource
,DelegatingMessageSource
public class MessageSourceSupport extends java.lang.Object
Base class for message source implementations, providing support infrastructure such asMessageFormat
handling but not implementing concrete methods defined in theMessageSource
.AbstractMessageSource
derives from this class, providing concretegetMessage
implementations that delegate to a central template method for message code resolution.Created: 2016. 3. 12.
-
-
Constructor Summary
Constructors Constructor Description MessageSourceSupport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.text.MessageFormat
createMessageFormat(java.lang.String msg, java.util.Locale locale)
Create a MessageFormat for the given message and Locale.protected java.lang.String
formatMessage(java.lang.String msg, java.lang.Object[] args, java.util.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 java.lang.String
renderDefaultMessage(java.lang.String defaultMessage, java.lang.Object[] args, java.util.Locale locale)
Render the given default message String.protected java.lang.Object[]
resolveArguments(java.lang.Object[] args, java.util.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.
-
-
-
Field Detail
-
log
protected final Log log
Logger available to subclasses
-
-
Method Detail
-
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.
- Parameters:
alwaysUseMessageFormat
- whether always use message format- See Also:
MessageFormat
-
isAlwaysUseMessageFormat
protected boolean isAlwaysUseMessageFormat()
Return whether to always apply the MessageFormat rules, parsing even messages without arguments.- Returns:
- whether always use message format
-
renderDefaultMessage
protected java.lang.String renderDefaultMessage(java.lang.String defaultMessage, java.lang.Object[] args, java.util.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.- Parameters:
defaultMessage
- the passed-in default message Stringargs
- array of arguments that will be filled in for params within the message, ornull
if none.locale
- the Locale used for formatting- Returns:
- the rendered default message (with resolved arguments)
- See Also:
#formatMessage(String, Object[], java.util.Locale)
-
formatMessage
protected java.lang.String formatMessage(java.lang.String msg, java.lang.Object[] args, java.util.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.- Parameters:
msg
- the message to formatargs
- array of arguments that will be filled in for params within the message, ornull
if nonelocale
- the Locale used for formatting- Returns:
- the formatted message (with resolved arguments)
-
createMessageFormat
protected java.text.MessageFormat createMessageFormat(java.lang.String msg, java.util.Locale locale)
Create a MessageFormat for the given message and Locale.- Parameters:
msg
- the message to create a MessageFormat forlocale
- the Locale to create a MessageFormat for- Returns:
- the MessageFormat instance
-
resolveArguments
protected java.lang.Object[] resolveArguments(java.lang.Object[] args, java.util.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.
- Parameters:
args
- the original argument arraylocale
- the Locale to resolve against- Returns:
- the resolved argument array
-
-