public abstract class AbstractResourceBasedMessageSource extends AbstractMessageSource
MessageSource
implementations based on
resource bundle conventions, such as ResourceBundleMessageSource
and ReloadableResourceBundleMessageSource
. Provides common
configuration methods and corresponding semantic definitions.ResourceBundleMessageSource
,
ReloadableResourceBundleMessageSource
logger
Constructor and Description |
---|
AbstractResourceBasedMessageSource() |
Modifier and Type | Method and Description |
---|---|
void |
addBasenames(String... basenames)
Add the specified basenames to the existing basename configuration.
|
Set<String> |
getBasenameSet()
Return this
MessageSource 's basename set, containing entries
in the order of registration. |
protected long |
getCacheMillis()
Return the number of milliseconds to cache loaded properties files.
|
protected String |
getDefaultEncoding()
Return the default charset to use for parsing properties files, if any.
|
protected Locale |
getDefaultLocale()
Determine a default Locale to fall back to: either a locally specified default
Locale or the system Locale, or
null for no fallback locale at all. |
protected boolean |
isFallbackToSystemLocale()
Deprecated.
as of 5.2.2, in favor of
getDefaultLocale() |
void |
setBasename(String basename)
Set a single basename, following the basic ResourceBundle convention
of not specifying file extension or language codes.
|
void |
setBasenames(String... basenames)
Set an array of basenames, each following the basic ResourceBundle convention
of not specifying file extension or language codes.
|
void |
setCacheMillis(long cacheMillis)
Set the number of milliseconds to cache loaded properties files.
|
void |
setCacheSeconds(int cacheSeconds)
Set the number of seconds to cache loaded properties files.
|
void |
setDefaultEncoding(String defaultEncoding)
Set the default charset to use for parsing properties files.
|
void |
setDefaultLocale(Locale defaultLocale)
Specify a default Locale to fall back to, as an alternative to falling back
to the system Locale.
|
void |
setFallbackToSystemLocale(boolean fallbackToSystemLocale)
Set whether to fall back to the system Locale if no files for a specific
Locale have been found.
|
getCommonMessages, getDefaultMessage, getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, resolveArguments, resolveCode, resolveCodeWithoutArguments, setCommonMessages, setParentMessageSource, setUseCodeAsDefaultMessage
createMessageFormat, formatMessage, isAlwaysUseMessageFormat, renderDefaultMessage, setAlwaysUseMessageFormat
public void setBasename(String basename)
MessageSource
implementation.
Regular and XMl properties files are supported: e.g. "messages" will find a "messages.properties", "messages_en.properties" etc arrangement as well as "messages.xml", "messages_en.xml" etc.
basename
- the single basenamesetBasenames(java.lang.String...)
,
ResourceEditor
,
ResourceBundle
public void setBasenames(String... basenames)
MessageSource
implementation.
Regular and XMl properties files are supported: e.g. "messages" will find a "messages.properties", "messages_en.properties" etc arrangement as well as "messages.xml", "messages_en.xml" etc.
The associated resource bundles will be checked sequentially when resolving a message code. Note that message definitions in a previous resource bundle will override ones in a later bundle, due to the sequential lookup.
Note: In contrast to addBasenames(java.lang.String...)
, this replaces existing entries
with the given names and can therefore also be used to reset the configuration.
basenames
- an array of basenamessetBasename(java.lang.String)
,
ResourceBundle
public void addBasenames(String... basenames)
Note: If a given basename already exists, the position of its entry will remain as in the original set. New entries will be added at the end of the list, to be searched after existing basenames.
setBasenames(java.lang.String...)
,
ResourceBundle
public Set<String> getBasenameSet()
MessageSource
's basename set, containing entries
in the order of registration.
Calling code may introspect this set as well as add or remove entries.
addBasenames(java.lang.String...)
public void setDefaultEncoding(@Nullable String defaultEncoding)
The effective default is the java.util.Properties
default encoding: ISO-8859-1. A null
value indicates
the platform default encoding.
Only applies to classic properties files, not to XML files.
defaultEncoding
- the default charset@Nullable protected String getDefaultEncoding()
public void setFallbackToSystemLocale(boolean fallbackToSystemLocale)
Falling back to the system Locale is the default behavior of
java.util.ResourceBundle
. However, this is often not desirable
in an application server environment, where the system Locale is not relevant
to the application at all: set this flag to "false" in such a scenario.
setDefaultLocale(java.util.Locale)
@Deprecated protected boolean isFallbackToSystemLocale()
getDefaultLocale()
public void setDefaultLocale(@Nullable Locale defaultLocale)
Default is to fall back to the system Locale. You may override this with
a locally specified default Locale here, or enforce no fallback locale at all
through disabling "fallbackToSystemLocale"
.
setFallbackToSystemLocale(boolean)
,
getDefaultLocale()
@Nullable protected Locale getDefaultLocale()
null
for no fallback locale at all.setDefaultLocale(java.util.Locale)
,
setFallbackToSystemLocale(boolean)
,
Locale.getDefault()
public void setCacheSeconds(int cacheSeconds)
java.util.ResourceBundle
).
Note that depending on your ClassLoader, expiration might not work reliably
since the ClassLoader may hold on to a cached version of the bundle file.
Prefer ReloadableResourceBundleMessageSource
over
ResourceBundleMessageSource
in such a scenario, in combination with
a non-classpath location.
public void setCacheMillis(long cacheMillis)
setCacheSeconds(int)
.
java.util.ResourceBundle
).
setCacheSeconds(int)
protected long getCacheMillis()