Java Utililty Methods Resource Message

List of utility methods to do Resource Message

Description

The list of methods to do Resource Message are organized into topic(s).

Method

StringgetMessage(String pkg, String name, Object[] args)
Locate the given message and merge it with the given arguments using the MessageFormat class.
return getMessage(pkg, name, args, Locale.getDefault());
StringgetMessage(String value, Object... args)
get Message
try {
    MessageFormat format = new MessageFormat(escape(value));
    value = format.format(args);
    return value;
} catch (MissingResourceException e) {
    return "???" + value + "???";
StringgetMessageCreateTime()
get Message Create Time
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String nowTime = df.format(date);
return nowTime;
MessageFormatgetMessageFormat(final String bundleKey, final String messageKey, final Locale locale)
get Message Format
assert bundleKey != null;
assert messageKey != null;
assert locale != null;
Map<String, Map<Locale, MessageFormat>> messageKey2Locale2MessageFormat;
Map<Locale, MessageFormat> locale2MessageFormat;
MessageFormat messageFormat;
messageKey2Locale2MessageFormat = bundleKey2MessageKey2Locale2MessageFormat.get(bundleKey);
if (messageKey2Locale2MessageFormat == null) {
...
StringgetMessageFormattedTime(Date date)
get Message Formatted Time
return messageTimeFormatter.format(date);
StringgetMessageNoKey(String messageName)
This method does the same thing as getMessage() but does not prepend the message key to the message.
try {
    return findMessage(messageName);
} catch (Exception e) {
    return messageName;
TgetMessages(final Class cls)
This method returns a proxy implementing the specified interface.
T messages = (T) fMessages.get(cls);
if (messages == null) {
    messages = newMessages(cls);
    fMessages.put(cls, messages);
return messages;
StringgetMessageString(String bundleName, String key, Object[] params, Locale locale)
get Message String
String text;
ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale, getCurrentClassLoader(params));
try {
    text = bundle.getString(key);
} catch (MissingResourceException e) {
    text = key;
if (params != null) {
...
StringgetMessageString(String key, Locale locale)
Gets messages
ResourceBundle MESSAGE_RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, locale); 
return MESSAGE_RESOURCE_BUNDLE.getString(key);
StringgetMessageString(String key, Locale locale)
Gets messages
return getMessageString(key, locale, new Object[] {});