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:org.apache.kylin.storage.jdbc.ITJDBCResourceStoreTest.java

@Before
public void setup() throws Exception {
    this.createTestMetadata();
    kylinConfig = KylinConfig.getInstanceFromEnv();
    KylinConfig configBackup = KylinConfig.createKylinConfig(kylinConfig);
    Statement statement = null;//www.j ava  2  s . c o m
    Connection conn = null;
    metadataUrlBackup = kylinConfig.getMetadataUrl();
    kylinConfig.setMetadataUrl(mainIdentifier + jdbcMetadataUrlNoIdentifier);
    JDBCSqlQueryFormat sqlQueryFormat = JDBCSqlQueryFormatProvider
            .createJDBCSqlQueriesFormat(KylinConfig.getInstanceFromEnv().getMetadataDialect());
    try {
        connectionManager = JDBCConnectionManager.getConnectionManager();
        conn = connectionManager.getConn();
        statement = conn.createStatement();
        String sql = new MessageFormat(sqlQueryFormat.getTestDropSql(), Locale.ROOT)
                .format(mainIdentifier, new StringBuffer(), new FieldPosition(0)).toString();
        statement.executeUpdate(sql);
        sql = new MessageFormat(sqlQueryFormat.getTestDropSql(), Locale.ROOT)
                .format(copyIdentifier, new StringBuffer(), new FieldPosition(0)).toString();
        statement.executeUpdate(sql);
        jdbcConnectable = true;
        ResourceTool.copy(configBackup, kylinConfig);
    } catch (RuntimeException ex) {
        logger.info("Init connection manager failed, skip test cases");
    } finally {
        JDBCConnectionManager.closeQuietly(statement);
        JDBCConnectionManager.closeQuietly(conn);
    }
}

From source file:org.apache.myfaces.renderkit.html.HtmlFormatRenderer.java

private String getOutputFormatText(FacesContext facesContext, UIComponent htmlOutputFormat) {
    String pattern = RendererUtils.getStringValue(facesContext, htmlOutputFormat);
    Object[] args;/*from ww  w . j a va2 s.  c  o m*/
    if (htmlOutputFormat.getChildCount() == 0) {
        args = EMPTY_ARGS;
    } else {
        List argsList = new ArrayList();
        for (Iterator it = htmlOutputFormat.getChildren().iterator(); it.hasNext();) {
            UIComponent child = (UIComponent) it.next();
            if (child instanceof UIParameter) {
                argsList.add(((UIParameter) child).getValue());
            }
        }
        args = argsList.toArray(new Object[argsList.size()]);
    }

    MessageFormat format = new MessageFormat(pattern, facesContext.getViewRoot().getLocale());
    try {
        return format.format(args);
    } catch (Exception e) {
        log.error("Error formatting message of component " + htmlOutputFormat.getClientId(facesContext));
        return "";
    }
}

From source file:org.dstadler.commons.logging.jdk.PatternFormatter.java

public final void setExceptionPattern(String exceptionFormatIn) {
    String exceptionFormat = exceptionFormatIn.replace("%LOGGER%", "{0}");
    exceptionFormat = exceptionFormat.replace("%LEVEL%", "{1}");
    exceptionFormat = exceptionFormat.replace("%TIME%", "{2}");
    exceptionFormat = exceptionFormat.replace("%MESSAGE%", "{3}");
    exceptionFormat = exceptionFormat.replace("%SOURCECLASS%", "{4}");
    exceptionFormat = exceptionFormat.replace("%SOURCEMETHOD%", "{5}");
    exceptionFormat = exceptionFormat.replace("%EXCEPTION%", "{6}");
    exceptionFormat = exceptionFormat.replace("%STACKTRACE%", "{7}");

    this.exceptionPattern = exceptionFormat;

    exceptionMessageFormat = new MessageFormat(logPattern, Locale.ROOT);
}

From source file:org.orekit.errors.OrekitException.java

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

From source file:org.openspaces.core.internal.commons.math.MathException.java

/**
 * Gets the message in a specified locale.
 *
 * @param locale Locale in which the message should be translated
 * @return localized message//from   w w w  .  ja va  2s.  co m
 * @since 1.2
 */
public String getMessage(final Locale locale) {
    return (pattern == null) ? "" : new MessageFormat(translate(pattern, locale), locale).format(arguments);
}

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

/**
 * The pattern to use to generate the subtotal labels.  The grouping value of the cell will be the first arg.
 * The default value is "{0} Total"./*from w w  w .  ja v  a  2s  . c  o  m*/
 * @param pattern
 * @param locale
 */
public void setSubtotalLabel(String pattern, Locale locale) {
    this.subtotalDesc = new MessageFormat(pattern, locale);
}

From source file:org.mycore.frontend.cli.MCRCommand.java

public MCRCommand(Method cmd) {
    className = cmd.getDeclaringClass().getName();
    methodName = cmd.getName();//from  w w w  .j av  a  2 s.  c  om
    parameterTypes = cmd.getParameterTypes();
    org.mycore.frontend.cli.annotation.MCRCommand cmdAnnotation = cmd
            .getAnnotation(org.mycore.frontend.cli.annotation.MCRCommand.class);
    help = cmdAnnotation.help();
    messageFormat = new MessageFormat(cmdAnnotation.syntax(), Locale.ROOT);
    setMethod(cmd);

    for (int i = 0; i < parameterTypes.length; i++) {
        Class<?> paramtype = parameterTypes[i];
        if (ClassUtils.isAssignable(paramtype, Integer.class, true)
                || ClassUtils.isAssignable(paramtype, Long.class, true)) {
            messageFormat.setFormat(i, NumberFormat.getIntegerInstance(Locale.ROOT));
        } else if (!String.class.isAssignableFrom(paramtype)) {
            unsupportedArgException(className + "." + methodName, paramtype.getName());
        }
    }

    int pos = cmdAnnotation.syntax().indexOf("{");
    suffix = pos == -1 ? cmdAnnotation.syntax() : cmdAnnotation.syntax().substring(0, pos);
}

From source file:net.sradonia.i18n.StringBundle.java

/**
 * Replaces {x} with the x-th element of the params array.
 * //from   www . ja va 2s . c  o  m
 * @param value
 *            the value
 * @param params
 *            the params
 * @return the resulting value
 */
private String replaceParams(String value, Object... params) {
    if (params == null || params.length == 0) {
        return value;
    } else {
        if (params.length == 1 && params[0] instanceof Collection<?>)
            params = ((Collection<?>) params[0]).toArray();
        return new MessageFormat(value, bundle.getLocale()).format(params, new StringBuffer(), null).toString();
    }
}

From source file:org.apache.myfaces.renderkit.html.ext.HtmlMessageRenderer.java

protected String getSummary(FacesContext facesContext, UIComponent message, FacesMessage facesMessage,
        String msgClientId) {/*www  .j a v  a 2  s. c  o m*/
    String msgSummary = facesMessage.getSummary();
    if (msgSummary == null)
        return null;

    String inputLabel = null;
    if (msgClientId != null)
        inputLabel = findInputLabel(facesContext, msgClientId);
    if (inputLabel == null)
        inputLabel = "";

    if (((message instanceof HtmlMessages && ((HtmlMessages) message).isReplaceIdWithLabel())
            || (message instanceof HtmlMessage && ((HtmlMessage) message).isReplaceIdWithLabel()))
            && inputLabel.length() != 0)
        msgSummary = msgSummary.replaceAll(findInputId(facesContext, msgClientId), inputLabel);

    String summaryFormat;
    if (message instanceof HtmlMessage) {
        summaryFormat = ((HtmlMessage) message).getSummaryFormat();
    } else {
        summaryFormat = (String) message.getAttributes().get("summaryFormat");
    }

    if (summaryFormat == null)
        return msgSummary;

    MessageFormat format = new MessageFormat(summaryFormat, facesContext.getViewRoot().getLocale());

    return format.format(new Object[] { msgSummary, inputLabel });
}

From source file:org.springframework.context.support.MessageSourceSupport.java

/**
 * Create a MessageFormat for the given message and Locale.
 * @param msg the message to create a MessageFormat for
 * @param locale the Locale to create a MessageFormat for
 * @return the MessageFormat instance//w ww.  j  a v a  2s .c om
 */
protected MessageFormat createMessageFormat(String msg, Locale locale) {
    return new MessageFormat(msg, locale);
}