Class ResourceMessageProvider
- All Implemented Interfaces:
MessageProvider
MessageProvider that stores messages in resource files- Author:
- Kuali Rice Team (rice.collab@kuali.org)
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected MessageHelper method to build aMessageobject from the given parametersprotected StringcleanResourceKey(String resourceKey) Removes any component declaration within the given resource keygetAllMessagesForComponent(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 namespaceprotected 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 callsgetMessage(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 keyRetrieves the list of configured bundle names for the applicationgetResourceBundleNamesForNamespace(String namespace) Retrieves the list of configured bundle names for the namespaceprotected 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 codeprotected List<ResourceBundle> getResourceBundlesForApplication(String localeCode) Retrieves the configuredResourceBundleinstances for the application using the given locale codeprotected List<ResourceBundle> getResourceBundlesForNamespace(String namespace, String localeCode) Retrieves the configuredResourceBundleinstances for the given namespace and locale
-
Field Details
-
cachedResourceBundles
-
-
Constructor Details
-
ResourceMessageProvider
public ResourceMessageProvider()
-
-
Method Details
-
getMessage
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 keyIf 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
- Specified by:
getMessagein interfaceMessageProvider- Parameters:
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 return- Returns:
- Message matching message object, or null if a message was not found
- See Also:
-
getAllMessagesForComponent
public 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 namespaceIf 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
- Specified by:
getAllMessagesForComponentin interfaceMessageProvider- Parameters:
namespace- namespace code the message belongs tocomponent- component code the namespace is associated withlocale- locale code for the message to return- Returns:
- Collection<Message> collection of messages that match, or empty collection if no messages are found
- See Also:
-
cleanResourceKey
Removes any component declaration within the given resource key- Parameters:
resourceKey- resource key to clean- Returns:
- String cleaned resource key
-
buildMessage
protected Message buildMessage(String namespace, String component, String key, String messageText, String locale) Helper method to build aMessageobject from the given parameters- Parameters:
namespace- namespace for the messagecomponent- component code for the messagekey- message keymessageText- text for the messagelocale- locale of the message- Returns:
- Message instance populated with parameters
-
getCachedResourceBundles
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- Parameters:
namespace- namespace to retrieve bundles forlocaleCode- locale code to use in selecting bundles- Returns:
- List<ResourceBundle> list of resource bundles for the namespace or empty list if none were found
-
getResourceBundlesForNamespace
Retrieves the configuredResourceBundleinstances for the given namespace and locale- Parameters:
namespace- namespace to retrieve bundles forlocaleCode- locale code to use in selecting bundles- Returns:
- List<ResourceBundle> list of resource bundles for the namespace or empty list if none were found
-
getResourceBundlesForApplication
Retrieves the configuredResourceBundleinstances for the application using the given locale code- Parameters:
localeCode- locale code to use in selecting bundles- Returns:
- List<ResourceBundle> list of resource bundles for the application or empty list if none were found
-
getResourceBundles
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 codeFor details on how resource bundles are selected given a bundle name and locale code see
ResourceBundle- Parameters:
resourceBundleNames- list of bundle names to get bundles forlocaleCode- locale code to use when selecting bundles- Returns:
- List<ResourceBundle> list of resource bundles (one for each bundle name if found)
-
getResourceBundleNamesForNamespace
Retrieves the list of configured bundle names for the namespaceResource bundle names are configured for a namespace using the property
resourceBundleNameson the correspondingModuleConfiguration- Parameters:
namespace- namespace to retrieve configured bundle names for- Returns:
- List<String> list of bundle names or null if module was not found for given namespace
-
getResourceBundleNamesForApplication
Retrieves the list of configured bundle names for the applicationResource bundle names are configured for the application using the configuration property
resourceBundleNames- Returns:
- List<String> list of bundle names configured for the application
-