Java Resource Message getMessage(Properties props, String key, Object param)

Here you can find the source of getMessage(Properties props, String key, Object param)

Description

get Message

License

Apache License

Declaration

public static String getMessage(Properties props, String key, Object param) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;

public class Main {

    public static String getMessage(ResourceBundle bundle, String key, Object[] params) {
        if ((bundle == null) || (key == null)) {
            return key;
        }/*from   w  w  w.  ja  v  a 2s.c  o  m*/

        try {
            String message = bundle.getString(key);

            return formatMessage(message, params);
        } catch (MissingResourceException e) {
            return key;
        }
    }

    public static String getMessage(ResourceBundle bundle, String key, Object param1) {
        return getMessage(bundle, key, new Object[] { param1 });
    }

    public static String getMessage(ResourceBundle bundle, String key, Object param1, Object param2) {
        return getMessage(bundle, key, new Object[] { param1, param2 });
    }

    public static String getMessage(ResourceBundle bundle, String key, Object param1, Object param2,
            Object param3) {
        return getMessage(bundle, key, new Object[] { param1, param2, param3 });
    }

    public static String getMessage(ResourceBundle bundle, String key, Object param1, Object param2, Object param3,
            Object param4) {
        return getMessage(bundle, key, new Object[] { param1, param2, param3, param4 });
    }

    public static String getMessage(ResourceBundle bundle, String key, Object param1, Object param2, Object param3,
            Object param4, Object param5) {
        return getMessage(bundle, key, new Object[] { param1, param2, param3, param4, param5 });
    }

    public static String getMessage(Properties props, String key, Object param) {
        return getMessage(props, key, new Object[] { param });
    }

    public static String getMessage(Properties props, String key, Object[] params) {
        if ((props == null) || (key == null)) {
            return key;
        }

        try {
            String message = props.getProperty(key);
            return formatMessage(message, params);
        } catch (MissingResourceException e) {
            return key;
        }
    }

    public static String formatMessage(String message, Object[] params) {
        if ((message == null) || (params == null) || (params.length == 0)) {
            return message;
        }

        return MessageFormat.format(message, params);
    }

    public static String formatMessage(String message, Object param1) {
        return formatMessage(message, new Object[] { param1 });
    }

    public static String formatMessage(String message, Object param1, Object param2) {
        return formatMessage(message, new Object[] { param1, param2 });
    }

    public static String formatMessage(String message, Object param1, Object param2, Object param3) {
        return formatMessage(message, new Object[] { param1, param2, param3 });
    }

    public static String formatMessage(String message, Object param1, Object param2, Object param3, Object param4) {
        return formatMessage(message, new Object[] { param1, param2, param3, param4 });
    }

    public static String formatMessage(String message, Object param1, Object param2, Object param3, Object param4,
            Object param5) {
        return formatMessage(message, new Object[] { param1, param2, param3, param4, param5 });
    }
}

Related

  1. getMessage(final Locale locale, final String messageKey)
  2. getMessage(final String bundleName, final Locale locale, final String key, final Object... params)
  3. getMessage(Locale locale, String key, Object... args)
  4. getMessage(Locale locale, String key, String... args)
  5. getMessage(Properties prop, String key, Object... args)
  6. getMessage(ResourceBundle bundle, Object key, Object[] params)
  7. getMessage(ResourceBundle bundle, String key, Object... params)
  8. getMessage(ResourceBundle bundle, String key, Object... params)
  9. getMessage(ResourceBundle messages, String messageKey)