Class ResourceBundleMessageSource

java.lang.Object
com.networknt.schema.i18n.ResourceBundleMessageSource
All Implemented Interfaces:
MessageSource

public class ResourceBundleMessageSource extends Object implements MessageSource
MessageSource that retrieves messages from a ResourceBundle.
  • Field Details

    • resourceBundleMap

      private final Map<String,Map<Locale,ResourceBundle>> resourceBundleMap
      Resource Bundle Cache. baseName -> locale -> resourceBundle.
    • messageMap

      private final Map<Locale,Map<String,String>> messageMap
      Message Cache. locale -> key -> message.
    • messageFormatMap

      private final Map<Locale,Map<String,MessageFormat>> messageFormatMap
      Message Format Cache. locale -> message -> messageFormat.

      Note that Message Format is not threadsafe.

    • baseNames

      private final List<String> baseNames
  • Constructor Details

    • ResourceBundleMessageSource

      public ResourceBundleMessageSource(String... baseName)
  • Method Details

    • getMessage

      public String getMessage(String key, Supplier<String> defaultMessage, Locale locale, Object... arguments)
      Description copied from interface: MessageSource
      Gets the message.
      Specified by:
      getMessage in interface MessageSource
      Parameters:
      key - to look up the message
      defaultMessage - the default message
      locale - the locale to use
      arguments - the message arguments
      Returns:
      the message
    • getMessageFormat

      protected MessageFormat getMessageFormat(Locale locale, String message)
    • getMessageFromCache

      protected String getMessageFromCache(Locale locale, String key)
      Gets the message from cache or the resource bundles. Returns an empty string if not found.
      Parameters:
      locale - the locale
      key - the message key
      Returns:
      the message
    • resolveMessage

      protected String resolveMessage(Locale locale, String key)
      Gets the message from the resource bundles. Returns an empty string if not found.
      Parameters:
      locale - the locale
      key - the message key
      Returns:
      the message
    • getResourceBundle

      protected Map<Locale,ResourceBundle> getResourceBundle(String baseName)
    • getResourceBundle

      protected ResourceBundle getResourceBundle(String baseName, Locale locale)