public class ResourceMessageProvider extends Object implements MessageProvider
MessageProvider
that stores messages in resource filesModifier and Type | Field and Description |
---|---|
protected Map<String,List<ResourceBundle>> |
cachedResourceBundles |
Constructor and Description |
---|
ResourceMessageProvider() |
Modifier and Type | Method and Description |
---|---|
protected Message |
buildMessage(String namespace,
String component,
String key,
String messageText,
String locale)
Helper method to build a
Message object from the given parameters |
protected String |
cleanResourceKey(String resourceKey)
Removes any component declaration within the given resource key
|
Collection<Message> |
getAllMessagesForComponent(String namespace,
String component,
String locale)
Iterates through the resource bundles for the give namespace (or the application if namespace is not given)
and finds all messages that match the given namespace
|
protected List<ResourceBundle> |
getCachedResourceBundles(String namespace,
String localeCode)
Retrieves the list of resource bundles for the given namespace or locale from cache if present, otherwise
the list is retrieved and then stored in cache for subsequent calls
|
Message |
getMessage(String namespace,
String component,
String key,
String locale)
Iterates through the resource bundles for the give namespace (or the application if namespace is not given)
and finds the message that matches the given key
|
protected List<String> |
getResourceBundleNamesForApplication()
Retrieves the list of configured bundle names for the application
|
protected List<String> |
getResourceBundleNamesForNamespace(String namespace)
Retrieves the list of configured bundle names for the namespace
|
protected List<ResourceBundle> |
getResourceBundles(List<String> resourceBundleNames,
String localeCode)
Helper method to build a list of resource bundles for the given list of bundle names and locale code
|
protected List<ResourceBundle> |
getResourceBundlesForApplication(String localeCode)
Retrieves the configured
ResourceBundle instances for the application using the given locale code |
protected List<ResourceBundle> |
getResourceBundlesForNamespace(String namespace,
String localeCode)
Retrieves the configured
ResourceBundle instances for the given namespace and locale |
protected Map<String,List<ResourceBundle>> cachedResourceBundles
public ResourceMessageProvider()
public Message getMessage(String namespace, String component, String key, String locale)
If the message is found in more than one bundle, the text from the bundle that is loaded last will be used
If the given component code is the default component, resource keys that do not have a component defined and match the given key will also be considered matches
getMessage
in interface MessageProvider
namespace
- namespace code the message belongs tocomponent
- component code the namespace is associated withkey
- key that identifies the message within the namespace and componentlocale
- locale code for the message to returnMessageProvider.getMessage(java.lang.String, java.lang.String,
java.lang.String, java.lang.String)
public Collection<Message> getAllMessagesForComponent(String namespace, String component, String locale)
If the same resource key is found in more than one bundle, the text from the bundle that is loaded last will be used
If the given component code is the default component, resource keys that do not have a component defined and match the given key will also be considered matches
getAllMessagesForComponent
in interface MessageProvider
namespace
- namespace code the message belongs tocomponent
- component code the namespace is associated withlocale
- locale code for the message to returnMessageProvider.getAllMessagesForComponent(java.lang.String, java.lang.String,
java.lang.String)
protected String cleanResourceKey(String resourceKey)
resourceKey
- resource key to cleanprotected Message buildMessage(String namespace, String component, String key, String messageText, String locale)
Message
object from the given parametersnamespace
- namespace for the messagecomponent
- component code for the messagekey
- message keymessageText
- text for the messagelocale
- locale of the messageprotected List<ResourceBundle> getCachedResourceBundles(String namespace, String localeCode)
namespace
- namespace to retrieve bundles forlocaleCode
- locale code to use in selecting bundlesprotected List<ResourceBundle> getResourceBundlesForNamespace(String namespace, String localeCode)
ResourceBundle
instances for the given namespace and localenamespace
- namespace to retrieve bundles forlocaleCode
- locale code to use in selecting bundlesprotected List<ResourceBundle> getResourceBundlesForApplication(String localeCode)
ResourceBundle
instances for the application using the given locale codelocaleCode
- locale code to use in selecting bundlesprotected List<ResourceBundle> getResourceBundles(List<String> resourceBundleNames, String localeCode)
For details on how resource bundles are selected given a bundle name and locale code see
ResourceBundle
resourceBundleNames
- list of bundle names to get bundles forlocaleCode
- locale code to use when selecting bundlesprotected List<String> getResourceBundleNamesForNamespace(String namespace)
Resource bundle names are configured for a namespace using the property resourceBundleNames
on the corresponding ModuleConfiguration
namespace
- namespace to retrieve configured bundle names forprotected List<String> getResourceBundleNamesForApplication()
Resource bundle names are configured for the application using the configuration property
resourceBundleNames
Copyright © 2005–2016 The Kuali Foundation. All rights reserved.