Java Resource Message getMessage(String value, Object... args)

Here you can find the source of getMessage(String value, Object... args)

Description

get Message

License

Open Source License

Declaration

public static String getMessage(String value, Object... args) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w.j a v  a  2s .c o  m*/
 * Copyright (C) 2006-2016 Talend Inc. - www.talend.com
 * 
 * This source code is available under agreement available at
 * %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
 * 
 * You should have received a copy of the agreement along with this program; if not, write to Talend SA 9 rue Pages
 * 92150 Suresnes, France
 */

import java.text.MessageFormat;

import java.util.MissingResourceException;

public class Main {
    public static String getMessage(String value, Object... args) {
        try {
            MessageFormat format = new MessageFormat(escape(value));
            value = format.format(args);
            return value;
        } catch (MissingResourceException e) {
            return "???" + value + "???";
        }
    }

    /**
     * Escape any single quote characters that are included in the specified message string.
     * 
     * @param string The string to be escaped
     */
    private static String escape(String string) {
        if ((string == null) || (string.indexOf('\'') < 0)) {
            return string;
        }
        int n = string.length();
        StringBuilder builder = new StringBuilder(n);
        for (int i = 0; i < n; i++) {
            char ch = string.charAt(i);
            if (ch == '\'') {
                builder.append('\'');
            }
            builder.append(ch);
        }
        return builder.toString();
    }
}

Related

  1. getMessage(String key, Object... values)
  2. getMessage(String key, String... fill)
  3. getMessage(String messageKey)
  4. getMessage(String messageKey, Object[] params)
  5. getMessage(String pkg, String name, Object[] args)
  6. getMessageCreateTime()
  7. getMessageFormat(final String bundleKey, final String messageKey, final Locale locale)
  8. getMessageFormattedTime(Date date)
  9. getMessageNoKey(String messageName)