Package com.networknt.schema.i18n
Class ResourceBundleMessageSource
java.lang.Object
com.networknt.schema.i18n.ResourceBundleMessageSource
- All Implemented Interfaces:
MessageSource
MessageSource
that retrieves messages from a ResourceBundle
.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map
<Locale, Map<String, MessageFormat>> Message Format Cache.Message Cache.private final Map
<String, Map<Locale, ResourceBundle>> Resource Bundle Cache. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the message.protected MessageFormat
getMessageFormat
(Locale locale, String message) protected String
getMessageFromCache
(Locale locale, String key) Gets the message from cache or the resource bundles.protected Map
<Locale, ResourceBundle> getResourceBundle
(String baseName) protected ResourceBundle
getResourceBundle
(String baseName, Locale locale) protected String
resolveMessage
(Locale locale, String key) Gets the message from the resource bundles.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.networknt.schema.i18n.MessageSource
getMessage, getMessage
-
Field Details
-
resourceBundleMap
Resource Bundle Cache. baseName -> locale -> resourceBundle. -
messageMap
Message Cache. locale -> key -> message. -
messageFormatMap
Message Format Cache. locale -> message -> messageFormat.Note that Message Format is not threadsafe.
-
baseNames
-
-
Constructor Details
-
ResourceBundleMessageSource
-
-
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 interfaceMessageSource
- Parameters:
key
- to look up the messagedefaultMessage
- the default messagelocale
- the locale to usearguments
- the message arguments- Returns:
- the message
-
getMessageFormat
-
getMessageFromCache
Gets the message from cache or the resource bundles. Returns an empty string if not found.- Parameters:
locale
- the localekey
- the message key- Returns:
- the message
-
resolveMessage
Gets the message from the resource bundles. Returns an empty string if not found.- Parameters:
locale
- the localekey
- the message key- Returns:
- the message
-
getResourceBundle
-
getResourceBundle
-