Java Resource Message getMessage(ResourceBundle messages, String messageKey)

Here you can find the source of getMessage(ResourceBundle messages, String messageKey)

Description

Returns message as String

License

Open Source License

Parameter

Parameter Description
messages the resource bundle
messageKey the message key

Return

the resolved message text

Declaration

final private static String getMessage(ResourceBundle messages,
        String messageKey) 

Method Source Code

//package com.java2s;
/*//w w  w . j  a  va 2 s . co  m
 Copyright 2010 Sun Microsystems, Inc.
 All rights reserved. Use is subject to license terms.

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; version 2 of the License.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 */

import java.util.*;
import java.text.MessageFormat;

public class Main {
    /**
     * Returns message as <code>String</code>
     * @param messages the resource bundle
     * @param messageKey the message key
     * @return the resolved message text
     */
    final private static String getMessage(ResourceBundle messages,
            String messageKey) {
        return messages.getString(messageKey);
    }

    /**
     * Formats message by adding array of arguments
     * @param messages the resource bundle
     * @param messageKey the message key
     * @param msgArgs an array of arguments to substitute into the message
     * @return the resolved message text
     */
    final private static String getMessage(ResourceBundle messages,
            String messageKey, Object[] msgArgs) {
        for (int i = 0; i < msgArgs.length; i++) {
            if (msgArgs[i] == null)
                msgArgs[i] = ""; // NOI18N
        }
        MessageFormat formatter = new MessageFormat(
                messages.getString(messageKey));
        return formatter.format(msgArgs);
    }

    /**
     * Formats message by adding an <code>Object</code> argument.
     * @param messages the resource bundle
     * @param messageKey the message key
     * @param arg the argument
     * @return the resolved message text
     */
    final private static String getMessage(ResourceBundle messages,
            String messageKey, Object arg) {
        Object[] args = { arg };
        return getMessage(messages, messageKey, args);
    }

    /**
     * Formats message by adding two <code>Object</code> arguments.
     * @param messages the resource bundle
     * @param messageKey the message key
     * @param arg1 the first argument
     * @param arg2 the second argument
     * @return the resolved message text
     */
    final private static String getMessage(ResourceBundle messages,
            String messageKey, Object arg1, Object arg2) {
        Object[] args = { arg1, arg2 };
        return getMessage(messages, messageKey, args);
    }

    /**
     * Formats message by adding an <code>int</code> as an argument.
     * @param messages the resource bundle
     * @param messageKey the message key
     * @param arg the argument
     * @return the resolved message text
     */
    final private static String getMessage(ResourceBundle messages,
            String messageKey, int arg) {
        Object[] args = { new Integer(arg) };
        return getMessage(messages, messageKey, args);
    }

    /**
     * Formats message by adding a <code>boolean</code> as an argument.
     * @param messages the resource bundle
     * @param messageKey the message key
     * @param arg the argument
     * @return the resolved message text
     */
    final private static String getMessage(ResourceBundle messages,
            String messageKey, boolean arg) {
        Object[] args = { String.valueOf(arg) };
        return getMessage(messages, messageKey, args);
    }
}

Related

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