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) 

Source Link

Document

Constructs a MessageFormat for the default java.util.Locale.Category#FORMAT FORMAT locale and the specified pattern.

Usage

From source file:net.sf.ginp.util.GinpUtil.java

/**
 * Get an Internationalized Message encoded with a Message Format.
 * @param key the message key/*from w  ww. j ava2s. c  o m*/
 * @param args keys for messageformat
 * @return the i18n message
 */
public static String message(final String key, final Object[] args) {
    String format = bundle.getString(key);
    MessageFormat msg = new MessageFormat(format);
    String formatted = msg.format(args);

    return formatted;
}

From source file:org.apache.hadoop.gateway.services.security.token.impl.JWTToken.java

public JWTToken(String alg, String[] claimsArray) {
    MessageFormat headerFormatter = new MessageFormat(headerTemplate);
    String[] algArray = new String[1];
    algArray[0] = alg;/*from w w  w .j a v a2 s  . c o m*/
    header = headerFormatter.format(algArray);

    MessageFormat claimsFormatter = new MessageFormat(claimTemplate);
    claims = claimsFormatter.format(claimsArray);
}

From source file:com.taobao.tddl.interact.rule.TableRule.java

private static String replaceWithParam(String template, String[] params) {
    if (params == null || template == null) {
        return template;
    }/*from   w  w  w. java2  s .  c  om*/
    if (params.length != 0 && params[0].indexOf(":") != -1) {
        // paramsNamedParam
        return replaceWithNamedParam(template, params);
    }
    return new MessageFormat(template).format(params);
}

From source file:org.vosao.i18n.Messages.java

public static String get(String key, Object... objects) {
    VosaoContext ctx = VosaoContext.getInstance();
    String pattern = "not found";
    if (isLocaleSupported(ctx.getLocale())) {
        pattern = getBundle(ctx.getRequest()).getString(key);
    } else {//from  ww  w  .  j  av  a 2 s . co m
        pattern = getDefaultBundle().getString(key);
    }
    if (objects != null) {
        MessageFormat formatter = new MessageFormat("");
        formatter.setLocale(ctx.getLocale());
        formatter.applyPattern(pattern);
        pattern = formatter.format(objects);
    }
    return pattern;
}

From source file:org.jbr.commons.container.SpringContainerSupport.java

protected void logApplicationContext() {
    final List<String> beanDefinitionNames = Arrays.asList(containerContext.getBeanDefinitionNames());
    Collections.sort(beanDefinitionNames);
    log.info("Application Context: " + containerContext.getDisplayName());
    log.info("Bean Definition Count = " + containerContext.getBeanDefinitionCount());
    final MessageFormat logMsgFormat = new MessageFormat("Bean : {0} : {1}");
    for (final String beanName : beanDefinitionNames) {
        if (log.isDebugEnabled()) {
            log.debug(MessageFormat.format("Bean : {0} :\n{1}",
                    new Object[] { beanName, XmlUtils.toXml(containerContext.getBean(beanName)) }));
        } else {/*from   w w  w  .  ja v a 2  s .co m*/
            log.info(logMsgFormat.format(new Object[] { beanName, containerContext.getType(beanName) }));
        }
    }
}

From source file:org.squale.squalecommon.util.messages.BaseMessages.java

/**
 * Retourne la chane de caractre identifie par la cl.
 * //from ww  w  .j a va2s.  c  o  m
 * @param pKey nom de la cl.
 * @param pValues les valeurs  insrer dans la chaine
 * @return la chane associe.
 */
protected String getBundleString(String pKey, Object[] pValues) {
    MessageFormat format = new MessageFormat(getBundleString(pKey));
    return format.format(pValues);
}

From source file:com.qcadoo.customTranslation.internal.CustomTranslationResolverImpl.java

@Override
public String getCustomTranslation(final String key, final Locale locale, final String[] args) {
    String translation = customTranslationCacheService.getCustomTranslation(key, locale.getLanguage());

    if (translation == null) {
        return null;
    } else {//from   www  . j av  a 2s  .c  o m
        translation = translation.replace("'", "''");

        Object[] argsToUse = args;

        if (!ObjectUtils.isEmpty(argsToUse)) {
            argsToUse = ArrayUtils.EMPTY_OBJECT_ARRAY;
        }

        MessageFormat messageFormat = new MessageFormat(translation);

        return messageFormat.format(argsToUse);
    }
}

From source file:net.gtaun.wl.lang.BeanMessageFormat.java

protected MessageFormat createFormat(String pattern) {
    // Should/could use ExtendedMessageFormat from commons.apache.org 
    return new MessageFormat(pattern);
}

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

public String getCaption() {
    String pattern;/*from  w  w w .  j a v a2 s  .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:net.sourceforge.vulcan.jabber.TemplateFormatter.java

static String substituteParameters(String template, String url, String users, String claimUser,
        BuildMessageDto message, String projectName, Integer buildNumber) {
    if (message == null) {
        message = blankMessage;/*from w w  w. j a  v  a2s  .c o m*/
    }

    final Object[] args = { isNotBlank(message.getMessage()) ? 1 : 0, message.getMessage(),
            isNotBlank(message.getFile()) ? 1 : 0, message.getFile(), message.getLineNumber() != null ? 1 : 0,
            message.getLineNumber() != null ? message.getLineNumber() : -1,
            isNotBlank(message.getCode()) ? 1 : 0, message.getCode(), isNotBlank(users) ? 1 : 0, users, url,
            projectName, buildNumber, isNotBlank(claimUser) ? 1 : 0, claimUser };

    template = template.replaceAll("'", "''");
    template = template.replaceAll("\\{(\\w+)\\?,(?!choice,)", "{$1NotBlank,choice,0#|1#");
    template = template.replaceAll("\\{(\\w+)\\?,choice,", "{$1NotBlank,choice,");

    final String[] paramNames = { "Message", "File", "LineNumber", "Code", "Users", "Link", "ProjectName",
            "BuildNumber" };

    for (String s : paramNames) {
        template = Pattern.compile("\\{" + s, Pattern.CASE_INSENSITIVE).matcher(template).replaceAll("{" + s);
    }

    template = template.replace("{MessageNotBlank", "{0").replace("{Message", "{1")
            .replace("{FileNotBlank", "{2").replace("{File", "{3").replace("{LineNumberNotBlank", "{4")
            .replace("{LineNumber", "{5").replace("{CodeNotBlank", "{6").replace("{Code", "{7")
            .replace("{UsersNotBlank", "{8").replace("{Users", "{9").replace("{Link", "{10")
            .replace("{ProjectName", "{11").replace("{BuildNumber", "{12").replace("{ClaimUserNotBlank", "{13")
            .replace("{ClaimUser", "{14");

    MessageFormat fmt = new MessageFormat(template);

    return fmt.format(args);
}