Example usage for java.text MessageFormat MessageFormat

List of usage examples for java.text MessageFormat MessageFormat

Introduction

In this page you can find the example usage for java.text MessageFormat MessageFormat.

Prototype

public MessageFormat(String pattern, Locale locale) 

Source Link

Document

Constructs a MessageFormat for the specified locale and pattern.

Usage

From source file:name.gumartinm.weather.information.service.ServiceCurrentParser.java

public String createURIAPICurrent(final String urlAPI, final String APIVersion, final double latitude,
        final double longitude) {

    final MessageFormat formatURIAPI = new MessageFormat(urlAPI, Locale.US);
    final Object[] values = new Object[3];
    values[0] = APIVersion;/*  ww  w  .  j  a  v a  2 s .  c  o m*/
    values[1] = latitude;
    values[2] = longitude;

    return formatURIAPI.format(values);
}

From source file:name.gumartinm.weather.information.service.ServiceForecastParser.java

public String createURIAPIForecast(final String urlAPI, final String APIVersion, final double latitude,
        final double longitude, final String resultsNumber) {

    final MessageFormat formatURIAPI = new MessageFormat(urlAPI, Locale.US);
    final Object[] values = new Object[4];
    values[0] = APIVersion;//  w  w w. j  ava 2s.c o  m
    values[1] = latitude;
    values[2] = longitude;
    values[3] = resultsNumber;

    return formatURIAPI.format(values);
}

From source file:DateServer.java

public void run() {
    while (true) {
        try {//from  w  ww . j a v a2s. co  m
            Socket s = ss.accept();

            ObjectInputStream ois;
            ois = new ObjectInputStream(s.getInputStream());
            Locale l = (Locale) ois.readObject();

            PrintWriter pw;
            pw = new PrintWriter(s.getOutputStream());

            MessageFormat mf;
            mf = new MessageFormat("The date is {0, date, long}", l);

            Object[] args = { new Date() };

            pw.println(mf.format(args));

            pw.close();
        } catch (Exception e) {
            System.err.println(e);
        }
    }
}

From source file:org.displaytag.decorator.MessageFormatColumnDecorator.java

/**
 * Instantiates a new MessageFormatColumnDecorator with a given pattern and locale.
 * @param pattern see <code>java.text.messageFormat</code>
 * @param locale current locale/*from   w w  w  . ja  v  a2  s .  com*/
 * @see java.text.messageFormat
 */
public MessageFormatColumnDecorator(String pattern, Locale locale) {
    this.format = new MessageFormat(pattern, locale);
}

From source file:org.callistasoftware.netcare.core.api.messages.DefaultSystemMessage.java

public DefaultSystemMessage(final String type, final boolean lowerCase, final Object... args) {
    this.code = this.getResourceBundle().getString(type);

    final String[] messages = new String[args.length];
    for (int i = 0; i < args.length; i++) {
        if (args[i] instanceof Number) {
            messages[i] = args[i].toString();
        } else {/*from   w  w w .j  av  a2s  . com*/
            messages[i] = lowerCase ? this.getResourceBundle().getString(args[i].toString()).toLowerCase()
                    : this.getResourceBundle().getString(args[i].toString());
            ;
        }
    }

    /*
     * Format message
     */
    final MessageFormat frm = new MessageFormat(this.getResourceBundle().getString(type),
            this.getResourceBundle().getLocale());
    this.message = new StringBuilder().append(frm.format(messages)).toString();
}

From source file:name.gumartinm.weather.information.activity.SpecificActivity.java

@Override
public void onResume() {
    super.onResume();

    // 1. Update title.
    final DatabaseQueries query = new DatabaseQueries(this);
    final WeatherLocation weatherLocation = query.queryDataBase();
    if (weatherLocation != null) {
        final ActionBar actionBar = this.getActionBar();
        final String[] array = new String[2];
        array[0] = weatherLocation.getCity();
        array[1] = weatherLocation.getCountry();
        final MessageFormat message = new MessageFormat("{0},{1}", Locale.US);
        final String cityCountry = message.format(array);
        actionBar.setTitle(cityCountry);
    }//w w w  . ja  v a  2 s  . c o m
}

From source file:com.icesoft.faces.utils.MessageUtils.java

public static FacesMessage getMessage(FacesContext facesContext, String messageId, Object params[]) {
    String messageInfo[] = new String[2];

    Locale locale = facesContext.getViewRoot().getLocale();
    String bundleName = facesContext.getApplication().getMessageBundle();
    //see if the message has been overridden by the application
    if (bundleName != null) {
        try {/*from   www  .  j  av a2 s .  c  o m*/
            loadMessageInfo(bundleName, locale, messageId, messageInfo);
        } catch (Exception e) {
            if (log.isWarnEnabled())
                log.warn(e + ", using " + ICE_MESSAGES_BUNDLE);
        }
    }

    //TODO Use defered evaluation of the parameters, like how
    // JSF 1.2's javax.faces.component.MessageFactory.
    // BindingFacesMessage does. ICE-2290.

    //if not overridden then check in Icefaces message bundle.
    if (messageInfo[SUMMARY] == null && messageInfo[DETAIL] == null) {
        loadMessageInfo(ICE_MESSAGES_BUNDLE, locale, messageId, messageInfo);
    }
    if (params != null) {
        MessageFormat format;
        for (int i = 0; i < messageInfo.length; i++) {
            if (messageInfo[i] != null) {
                format = new MessageFormat(messageInfo[i], locale);
                messageInfo[i] = format.format(params);
            }
        }
    }
    return new FacesMessage(messageInfo[SUMMARY], messageInfo[DETAIL]);
}

From source file:org.openvpms.esci.adapter.i18n.Messages.java

protected String getString(String key, Locale locale, Object... args) {
    String result = getValue(key, locale);
    if (result == null) {
        result = formatMissingKey(key, args);
    } else if (args.length != 0) {
        MessageFormat format = new MessageFormat(result, locale);
        try {//from   ww w. j  av a2 s  .c o m
            result = format.format(args);
        } catch (Throwable exception) {
            result = formatFailed(key, result, args, exception);
        }
    }
    return result;
}

From source file:com.krawler.common.locale.MessageSourceSupport.java

protected MessageFormat createMessageFormat(String msg, Locale locale) {
    return new MessageFormat((msg != null ? msg : ""), locale);
}

From source file:com.examples.with.different.packagename.concolic.MathRuntimeException.java

/**
 * Builds a message string by from a pattern and its arguments.
 * @param locale Locale in which the message should be translated
 * @param pattern format specifier/*from  w  w  w  .  j  a  v  a2s .  c o m*/
 * @param arguments format arguments
 * @return a message string
 */
private static String buildMessage(final Locale locale, final String pattern, final Object... arguments) {
    return (pattern == null) ? "" : new MessageFormat(translate(pattern, locale), locale).format(arguments);
}