Example usage for java.text MessageFormat format

List of usage examples for java.text MessageFormat format

Introduction

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

Prototype

public final String format(Object obj) 

Source Link

Document

Formats an object to produce a string.

Usage

From source file:com.haulmont.timesheets.entity.ExtUser.java

@Override
public String getCaption() {
    if (StringUtils.isNotEmpty(firstName) || StringUtils.isNotEmpty(lastName)) {
        String pattern = "{0} {1}";
        MessageFormat fmt = new MessageFormat(pattern);
        return StringUtils.trimToEmpty(fmt.format(
                new Object[] { StringUtils.trimToEmpty(firstName), StringUtils.trimToEmpty(lastName) }));
    }/*from   www  .j  a  v a2  s .c  om*/
    return super.getCaption();
}

From source file:net.contextfw.web.application.component.Script.java

public void build(DOMBuilder b, Gson gson, ScriptContext scriptContext) {

    Object[] arguments = getArguments(scriptContext);

    if (arguments == null) {
        b.text(getScript(scriptContext));
    } else {/*www . j  a v a2 s  .  c  o m*/
        MessageFormat format = new MessageFormat(getScript(scriptContext));
        b.text(format.format(getStringParams(gson, arguments)));
    }
}

From source file:com.haulmont.timesheets.entity.Tag.java

public String getCaption() {
    String pattern;//from  w  ww .j av a 2s  . co m
    Object[] params;
    if (tagType != null) {
        pattern = "{0} [{1}]";
        params = new Object[] { StringUtils.trimToEmpty(name), StringUtils.trimToEmpty(tagType.getName()) };
    } else {
        pattern = "{0}";
        params = new Object[] { StringUtils.trimToEmpty(name) };
    }
    MessageFormat fmt = new MessageFormat(pattern);
    return StringUtils.trimToEmpty(fmt.format(params));
}

From source file:DateServer.java

public void run() {
    while (true) {
        try {/*from ww w. j  ava2 s  .c o 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:br.com.sicoob.cro.cop.util.BatchPropertiesUtil.java

/**
 * Passa os argumentos para a string da mensagem.
 *
 * @param key Chave./*from w ww  .j  a  va  2 s.  c  o m*/
 * @param replace Argumentos.
 * @return String formatada.
 */
private String applyArguments(String key, String... replace) {
    MessageFormat format = new MessageFormat("");
    format.applyPattern((String) properties.get(key));
    return format.format(replace);
}

From source file:ca.uhn.fhir.i18n.HapiLocalizer.java

public String getMessage(String theQualifiedKey, Object... theParameters) {
    if (theParameters != null && theParameters.length > 0) {
        MessageFormat format = myKeyToMessageFormat.get(theQualifiedKey);
        if (format != null) {
            return format.format(theParameters).toString();
        }/*from  w ww.j av a2  s . c o m*/

        String formatString = findFormatString(theQualifiedKey);

        format = new MessageFormat(formatString.trim());
        myKeyToMessageFormat.put(theQualifiedKey, format);
        return format.format(theParameters).toString();
    } else {
        String retVal = findFormatString(theQualifiedKey);
        return retVal;
    }
}

From source file:com.safetys.framework.jmesa.core.message.ResourceBundleMessages.java

public String getMessage(String code, Object[] args) {
    String result = findResource(customResourceBundle, code);

    if (result == null) {
        result = findResource(defaultResourceBundle, code);
    }//from  ww w.j  a v a  2s.co m

    if (result != null && args != null) {
        MessageFormat formatter = new MessageFormat("");
        formatter.setLocale(locale);
        formatter.applyPattern(result);
        result = formatter.format(args);
    }

    return result;
}

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;//from w w w . ja  va  2  s  .  c om
    values[1] = latitude;
    values[2] = longitude;

    return formatURIAPI.format(values);
}

From source file:cloud.google.oauth2.MyWayAuthentication.java

public String getAssertion(long exp, long iat) throws Exception {
    String header = "{\"alg\":\"RS256\",\"typ\":\"JWT\"}";
    String claimTemplate = "'{'\"iss\": \"{0}\", \"scope\": \"{1}\", \"aud\": \"{2}\", \"exp\": {3}, \"iat\": {4}'}'";
    StringBuffer token = new StringBuffer();

    /**/*  ww w .  j  a va  2s.  c om*/
     * Encode the JWT Header and add it to our string to sign
     * */
    token.append(Base64.encodeBase64URLSafeString(header.getBytes("UTF-8")));

    /**
     * Separate with a period
     * */
    token.append(".");

    /**
     * Create the JWT Claims Object
     * */
    String[] claimArray = new String[6];
    claimArray[0] = this.iss;
    claimArray[1] = GCDStatic.getScope();
    claimArray[2] = GCDStatic.getAud();
    claimArray[3] = "" + exp;
    claimArray[4] = "" + iat;

    MessageFormat claims = new MessageFormat(claimTemplate);
    String payload = claims.format(claimArray);

    /**
     * Add the encoded claims object
     * */
    token.append(Base64.encodeBase64URLSafeString(payload.getBytes("UTF-8")));

    /**
     * Load the private key
     * */
    PrivateKey privateKey = getPrivateKey(this.keystoreLoc, GCDStatic.getPassword());
    byte[] sig = signData(token.toString().getBytes("UTF-8"), privateKey);

    String signedPayload = Base64.encodeBase64URLSafeString(sig);

    /**
     * Separate with a period
     * */
    token.append(".");

    /**
     * Add the encoded signature
     * */
    token.append(signedPayload);

    return token.toString();
}

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  ww . j a  v a2s.c o  m*/
            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();
}