public class HstRepositoryResourceBundleMessageSource
extends org.springframework.context.support.ResourceBundleMessageSource
MessageSource
implementation that
accesses Config.get(javax.servlet.ServletRequest, String)
to read the default
LocalizationContext
which can be set by HST-2 Container (LocalizationValve
).
(if isLocalizationContextResourceBundleEnabled()
returns true (by default))
to resolve MessageFormat
.
If falls back to the super class,
ResourceBundleMessageSource
, if nothing found (from HST-2 Dynamic Resource Bundles).Constructor and Description |
---|
HstRepositoryResourceBundleMessageSource()
Zero-argument default constructor.
|
Modifier and Type | Method and Description |
---|---|
protected ResourceBundle |
findDefaultResourceBundle()
Finds the default
LocalizationContext 's ResourceBundle set by HST-2 Container in the frontend pipeline. |
protected MessageFormat |
getMessageFormat(ResourceBundle bundle,
String code,
Locale locale)
Return a MessageFormat for the given bundle and code,
fetching already generated MessageFormats from the cache.
|
protected MessageFormat |
getMessageFormatFromDefaultResourceBundle(ResourceBundle defaultResourceBundle,
String code,
Locale locale)
Invokes
RepositoryResourceBundleMessageFormatProvider.registerBundle(String, Locale, ResourceBundle)
or RepositoryResourceBundleMessageFormatProvider.registerPreviewBundle(String, Locale, ResourceBundle)
depending on the current request context in order to register the bundle or remove any existing outdated bundle. |
protected ResourceBundle |
getResourceBundle(String basename,
Locale locale)
If
isRepositoryResourceBundleEnabled() returns true, then it first looks up
resource bundle from the repository. |
RepositoryResourceBundleMessageFormatProvider |
getResourceBundleMessageFormatProvider()
Returns
RepositoryResourceBundleMessageFormatProvider internally used for
maintaining repository-based resource bundles and message formats from them. |
protected String |
getStringOrNull(ResourceBundle bundle,
String key) |
boolean |
isLocalizationContextResourceBundleEnabled()
Returns true if the default resource bundle should be found from
LocalizationContext
by calling on Config.get(javax.servlet.ServletRequest, String) . |
boolean |
isRepositoryResourceBundleEnabled()
Returns true if the repository resource bundle documents should be looked up
in
getResourceBundle(String, Locale) . |
protected MessageFormat |
resolveCode(String code,
Locale locale)
If
isLocalizationContextResourceBundleEnabled() returns true,
then it tries to find the default resource bundle from LocalizationContext first. |
protected String |
resolveCodeWithoutArguments(String code,
Locale locale)
If
isLocalizationContextResourceBundleEnabled() returns true,
then it tries to find the default resource bundle from LocalizationContext first. |
void |
setLocalizationContextResourceBundleEnabled(boolean localizationContextResourceBundleEnabled)
Sets the flag whether or not the default resource bundle should be found from
LocalizationContext
by calling on Config.get(javax.servlet.ServletRequest, String) . |
void |
setRepositoryResourceBundleEnabled(boolean repositoryResourceBundleEnabled)
Sets the flag whether or not the repository resource bundle documents should be looked up
in
getResourceBundle(String, Locale) . |
void |
setResourceBundleMessageFormatProvider(RepositoryResourceBundleMessageFormatProvider resourceBundleMessageFormatProvider)
Sets
RepositoryResourceBundleMessageFormatProvider internally to be used for
maintaining repository-based resource bundles and message formats from them. |
doGetBundle, getBundleClassLoader, loadBundle, loadBundle, setBeanClassLoader, setBundleClassLoader, toString
addBasenames, getBasenameSet, getCacheMillis, getDefaultEncoding, isFallbackToSystemLocale, setBasename, setBasenames, setCacheMillis, setCacheSeconds, setDefaultEncoding, setFallbackToSystemLocale
getCommonMessages, getDefaultMessage, getDefaultMessage, getMessage, getMessage, getMessage, getMessageFromParent, getMessageInternal, getParentMessageSource, isUseCodeAsDefaultMessage, resolveArguments, setCommonMessages, setParentMessageSource, setUseCodeAsDefaultMessage
public HstRepositoryResourceBundleMessageSource()
public boolean isLocalizationContextResourceBundleEnabled()
LocalizationContext
by calling on Config.get(javax.servlet.ServletRequest, String)
.LocalizationContext
by calling on Config.get(javax.servlet.ServletRequest, String)
public void setLocalizationContextResourceBundleEnabled(boolean localizationContextResourceBundleEnabled)
LocalizationContext
by calling on Config.get(javax.servlet.ServletRequest, String)
.localizationContextResourceBundleEnabled
- the flag whether or not the default resource bundle should be found from LocalizationContext
by calling on Config.get(javax.servlet.ServletRequest, String)
public boolean isRepositoryResourceBundleEnabled()
getResourceBundle(String, Locale)
.getResourceBundle(String, Locale)
public void setRepositoryResourceBundleEnabled(boolean repositoryResourceBundleEnabled)
getResourceBundle(String, Locale)
.repositoryResourceBundleEnabled
- the flag whether or not the repository resource bundle documents should be looked up
in getResourceBundle(String, Locale)
public RepositoryResourceBundleMessageFormatProvider getResourceBundleMessageFormatProvider()
RepositoryResourceBundleMessageFormatProvider
internally used for
maintaining repository-based resource bundles and message formats from them.RepositoryResourceBundleMessageFormatProvider
internally used for
maintaining repository-based resource bundles and message formats from thempublic void setResourceBundleMessageFormatProvider(RepositoryResourceBundleMessageFormatProvider resourceBundleMessageFormatProvider)
RepositoryResourceBundleMessageFormatProvider
internally to be used for
maintaining repository-based resource bundles and message formats from them.resourceBundleMessageFormatProvider
- RepositoryResourceBundleMessageFormatProvider
internally to be used for
maintaining repository-based resource bundles and message formats from themprotected String resolveCodeWithoutArguments(String code, Locale locale)
isLocalizationContextResourceBundleEnabled()
returns true,
then it tries to find the default resource bundle from LocalizationContext
first.
Otherwise or if not found, it proceeds with the default behavior.resolveCodeWithoutArguments
in class org.springframework.context.support.ResourceBundleMessageSource
code
- message codelocale
- message localeprotected MessageFormat resolveCode(String code, Locale locale)
isLocalizationContextResourceBundleEnabled()
returns true,
then it tries to find the default resource bundle from LocalizationContext
first.
Otherwise or if not found, it proceeds with the default behavior.resolveCode
in class org.springframework.context.support.ResourceBundleMessageSource
code
- message codelocale
- message localeprotected ResourceBundle getResourceBundle(String basename, Locale locale)
isRepositoryResourceBundleEnabled()
returns true, then it first looks up
resource bundle from the repository.
Otherwise or if not found, it proceeds with the default behavior.getResourceBundle
in class org.springframework.context.support.ResourceBundleMessageSource
basename
- resource bundle basenamelocale
- resource bundle localeprotected MessageFormat getMessageFormat(ResourceBundle bundle, String code, Locale locale) throws MissingResourceException
getMessageFormat
in class org.springframework.context.support.ResourceBundleMessageSource
bundle
- resource bundlecode
- message codelocale
- message localeMissingResourceException
protected MessageFormat getMessageFormatFromDefaultResourceBundle(ResourceBundle defaultResourceBundle, String code, Locale locale)
RepositoryResourceBundleMessageFormatProvider.registerBundle(String, Locale, ResourceBundle)
or RepositoryResourceBundleMessageFormatProvider.registerPreviewBundle(String, Locale, ResourceBundle)
depending on the current request context in order to register the bundle or remove any existing outdated bundle.
And, it invokes getMessageFormat(ResourceBundle, String, Locale)
to return a MessageFormat.defaultResourceBundle
- default resource bundlecode
- message codelocale
- message localeprotected ResourceBundle findDefaultResourceBundle()
LocalizationContext
's ResourceBundle
set by HST-2 Container in the frontend pipeline.
It tries to find it from the JSTL LocalizationContext
. However, JstlView
(and JstlUtils
) of Spring Framework
may replace the LocalizationContext
by its MessageSourceResourceBundle
.
In that case, it tries to resolve the default resource bundle(s) configured in HST-2 configurations again.
protected String getStringOrNull(ResourceBundle bundle, String key)
getStringOrNull
in class org.springframework.context.support.ResourceBundleMessageSource
Copyright © 2019. All rights reserved.