Class ResourceMessageProvider

java.lang.Object
org.kuali.rice.krad.messages.providers.ResourceMessageProvider
All Implemented Interfaces:
MessageProvider

public class ResourceMessageProvider extends Object implements MessageProvider
Implementation of MessageProvider that stores messages in resource files
Author:
Kuali Rice Team (rice.collab@kuali.org)
  • Field Details

  • Constructor Details

    • ResourceMessageProvider

      public ResourceMessageProvider()
  • Method Details

    • getMessage

      public 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

      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

      Specified by:
      getMessage in interface MessageProvider
      Parameters:
      namespace - namespace code the message belongs to
      component - component code the namespace is associated with
      key - key that identifies the message within the namespace and component
      locale - 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 namespace

      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

      Specified by:
      getAllMessagesForComponent in interface MessageProvider
      Parameters:
      namespace - namespace code the message belongs to
      component - component code the namespace is associated with
      locale - 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

      protected String cleanResourceKey(String resourceKey)
      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 a Message object from the given parameters
      Parameters:
      namespace - namespace for the message
      component - component code for the message
      key - message key
      messageText - text for the message
      locale - locale of the message
      Returns:
      Message instance populated with parameters
    • getCachedResourceBundles

      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
      Parameters:
      namespace - namespace to retrieve bundles for
      localeCode - 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

      protected List<ResourceBundle> getResourceBundlesForNamespace(String namespace, String localeCode)
      Retrieves the configured ResourceBundle instances for the given namespace and locale
      Parameters:
      namespace - namespace to retrieve bundles for
      localeCode - 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

      protected List<ResourceBundle> getResourceBundlesForApplication(String localeCode)
      Retrieves the configured ResourceBundle instances 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 code

      For 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 for
      localeCode - locale code to use when selecting bundles
      Returns:
      List<ResourceBundle> list of resource bundles (one for each bundle name if found)
    • getResourceBundleNamesForNamespace

      protected List<String> getResourceBundleNamesForNamespace(String namespace)
      Retrieves the list of configured bundle names for the namespace

      Resource bundle names are configured for a namespace using the property resourceBundleNames on the corresponding ModuleConfiguration

      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

      protected List<String> getResourceBundleNamesForApplication()
      Retrieves the list of configured bundle names for the application

      Resource bundle names are configured for the application using the configuration property resourceBundleNames

      Returns:
      List<String> list of bundle names configured for the application