Here you can find the source of getMessage(ResourceBundle messages, String messageKey)
String
Parameter | Description |
---|---|
messages | the resource bundle |
messageKey | the message key |
final private static String getMessage(ResourceBundle messages, String messageKey)
//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); } }