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 static String format(String pattern, Object... arguments) 

Source Link

Document

Creates a MessageFormat with the given pattern and uses it to format the given arguments.

Usage

From source file:at.alladin.rmbt.controlServer.QoSResultResource.java

@Post("json")
public String request(final String entity) {
    addAllowOrigin();/* w w w . j av a 2s  .  c  o  m*/

    JSONObject request = null;

    final ErrorList errorList = new ErrorList();
    final JSONObject answer = new JSONObject();
    String answerString;

    System.out.println(MessageFormat.format(labels.getString("NEW_QOS_TESTRESULT_DETAIL"), getIP()));

    if (entity != null && !entity.isEmpty())
        // try parse the string to a JSON object
        try {
            request = new JSONObject(entity);

            String lang = request.optString("language");

            // Load Language Files for Client

            final List<String> langs = Arrays
                    .asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*"));

            if (langs.contains(lang)) {
                errorList.setLanguage(lang);
                labels = (PropertyResourceBundle) ResourceBundle.getBundle("at.alladin.rmbt.res.SystemMessages",
                        new Locale(lang));
            } else
                lang = settings.getString("RMBT_DEFAULT_LANGUAGE");

            if (conn != null) {
                final String testUuid = request.optString("test_uuid");
                long ts = System.nanoTime();
                QoSUtil.evaluate(settings, conn, new TestUuid(testUuid, UuidType.TEST_UUID), answer, lang,
                        errorList);
                long endTs = System.nanoTime() - ts;
                answer.put("evaluation",
                        "Time needed to evaluate test result: " + ((float) endTs / 1000000f) + " ms");
            } else {
                errorList.addError("ERROR_DB_CONNECTION");
            }

        } catch (final JSONException e) {
            errorList.addError("ERROR_REQUEST_JSON");
            e.printStackTrace();
        } catch (SQLException e) {
            errorList.addError("ERROR_DB_CONNECTION");
            e.printStackTrace();
        } catch (HstoreParseException e) {
            errorList.addErrorString(e.getMessage());
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            errorList.addError("ERROR_REQUEST_JSON");
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (UnsupportedOperationException e) {
            e.printStackTrace();
            errorList.addError("ERROR_REQUEST_QOS_RESULT_DETAIL_NO_UUID");
        }

    else
        errorList.addErrorString("Expected request is missing.");

    try {
        answer.putOpt("error", errorList.getList());
    } catch (final JSONException e) {
        System.out.println("Error saving ErrorList: " + e.toString());
    }

    answerString = answer.toString();

    //System.out.println(answerString);

    return answerString;
}

From source file:com.intelius.iap4.TigerLineHit.java

private static String generateSelectQuery(String state) {
    if (state == null || state.length() != 2) {
        throw new IllegalArgumentException(state + " is not a valid 2 letter state code");
    }//  ww  w  . ja  v  a2  s  .  c  om
    return MessageFormat.format(TIGER_QUERY, state);
}

From source file:com.microsoft.tfs.client.common.ui.wit.form.FieldTracker.java

public synchronized void addField(final Field field) {
    if (contains(field, true)) {
        final String messageFormat = "Duplicate field {0} ignored by field tracker"; //$NON-NLS-1$
        final String message = MessageFormat.format(messageFormat, field.getReferenceName());
        log.warn(message);/*from   www .j ava2  s  . co m*/
        return;
    }

    fields.put(field, new FieldInfo(field));
    if (insertionOrder.contains(field)) {
        insertionOrder.remove(field);
    }
    insertionOrder.add(field);
}

From source file:de.edgesoft.edgeutils.commandline.CommandOption.java

/**
 * Returns formatted usage string./*from  w  w w  .  j  av a  2  s. c  o m*/
 * 
 * @return formatted usage string
 *  
 * @version 0.1
 * @since 0.1
 */
public String getUsage() {
    return MessageFormat.format((isRequired()) ? "{0}" : "[{0}]",
            MessageFormat.format("[-{0}|--{1}] {2}", getOpt(), getLongOpt(), getDescription()));
}

From source file:ch.cyberduck.core.cdn.DistributionUrlProvider.java

@Override
public DescriptiveUrlBag toUrl(final Path file) {
    final DescriptiveUrlBag list = new DescriptiveUrlBag();
    list.add(new DescriptiveUrl(this.toUrl(file, distribution.getOrigin()), DescriptiveUrl.Type.origin,
            MessageFormat.format(LocaleFactory.localizedString("{0} URL"),
                    LocaleFactory.localizedString("Origin", "Info"))));
    if (distribution.getUrl() != null) {
        list.add(new DescriptiveUrl(this.toUrl(file, distribution.getUrl()), DescriptiveUrl.Type.cdn,
                MessageFormat.format(LocaleFactory.localizedString("{0} URL"),
                        LocaleFactory.localizedString(distribution.getMethod().toString(), "S3"))));
    }/*from ww w  .  java  2s . c o  m*/
    if (distribution.getSslUrl() != null) {
        list.add(new DescriptiveUrl(this.toUrl(file, distribution.getSslUrl()), DescriptiveUrl.Type.cdn,
                String.format("%s (SSL)", MessageFormat.format(LocaleFactory.localizedString("{0} URL"),
                        LocaleFactory.localizedString(distribution.getMethod().toString(), "S3")))));
    }
    if (distribution.getStreamingUrl() != null) {
        list.add(new DescriptiveUrl(this.toUrl(file, distribution.getStreamingUrl()), DescriptiveUrl.Type.cdn,
                String.format("%s (Streaming)", MessageFormat.format(LocaleFactory.localizedString("{0} URL"),
                        LocaleFactory.localizedString(distribution.getMethod().toString(), "S3")))));
    }
    if (distribution.getiOSstreamingUrl() != null) {
        list.add(
                new DescriptiveUrl(this.toUrl(file, distribution.getiOSstreamingUrl()), DescriptiveUrl.Type.cdn,
                        String.format("%s (iOS Streaming)", MessageFormat.format(
                                LocaleFactory.localizedString("{0} URL"),
                                LocaleFactory.localizedString(distribution.getMethod().toString(), "S3")))));
    }
    list.addAll(this.toCnameUrl(file));
    return list;
}

From source file:com.microsoft.tfs.client.common.commands.vc.QueryExclusiveCheckoutCommand.java

@Override
public String getName() {
    if (itemSpecs.length == 1) {
        final String messageFormat = Messages.getString("QueryExclusiveCheckoutCommand.SingleItemTextFormat"); //$NON-NLS-1$
        return MessageFormat.format(messageFormat, itemSpecs[0].getItem());
    } else {/* w ww .ja v  a 2  s .c o m*/
        return (Messages.getString("QueryExclusiveCheckoutCommand.MultiItemText")); //$NON-NLS-1$
    }
}

From source file:net.refractions.udig.ui.internal.Messages.java

/**
 * Find the localized message for the given key. If arguments are given, then the
 * result message is formatted via {@link MessageFormat}.
 *
 * @param locale The locale to use to localize the given message.
 * @param key//from   w w w .  ja v  a2  s.  com
 * @param args If not null, then the message is formatted via {@link MessageFormat}
 * @return The message for the given key.
 */
public static String get(Locale locale, String key, Object... args) {
    try {
        // getBundle() caches the bundles
        ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale, Messages.class.getClassLoader());
        if (args == null || args.length == 0) {
            return bundle.getString(key);
        } else {
            String msg = bundle.getString(key);
            return MessageFormat.format(msg, args);
        }
    } catch (Exception e) {
        return StringUtils.substringAfterLast(key, "_");
    }
}

From source file:at.alladin.rmbt.controlServer.OpenTestQoSResource.java

@Post("json")
public String request(final String entity) {
    addAllowOrigin();/*from   w  w  w.j a  v  a2  s.  c  o  m*/

    final ErrorList errorList = new ErrorList();
    final JSONObject answer = new JSONObject();
    String answerString;

    System.out.println(MessageFormat.format(labels.getString("NEW_QOS_RESULT_REQUEST"), getIP()));

    try {
        String lang = null;
        String openUUID = getRequest().getAttributes().get("open_test_uuid").toString();
        if (getRequest().getAttributes().containsKey("lang")) {
            lang = getRequest().getAttributes().get("lang").toString();
        } else {
            List<Preference<Language>> languageList = getRequest().getClientInfo().getAcceptedLanguages();
            if (languageList != null && languageList.size() > 0) {
                lang = languageList.get(0).getMetadata().getName();
            }
        }

        // Load Language Files for Client

        final List<String> langs = Arrays.asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*"));

        if (langs.contains(lang)) {
            labels = (PropertyResourceBundle) ResourceBundle.getBundle("at.alladin.rmbt.res.SystemMessages",
                    new Locale(lang));
        } else {
            lang = settings.getString("RMBT_DEFAULT_LANGUAGE");
        }

        errorList.setLanguage(lang);

        if (conn != null) {
            QoSUtil.evaluate(settings, conn, new TestUuid(openUUID, UuidType.OPEN_TEST_UUID), answer, lang,
                    errorList);
        } else {
            errorList.addError("ERROR_DB_CONNECTION");
        }

    } catch (final JSONException e) {
        errorList.addError("ERROR_REQUEST_JSON");
        e.printStackTrace();
    } catch (SQLException e) {
        errorList.addError("ERROR_DB_CONNECTION");
        e.printStackTrace();
    } catch (HstoreParseException e) {
        errorList.addErrorString(e.getMessage());
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        errorList.addError("ERROR_REQUEST_JSON");
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnsupportedOperationException e) {
        errorList.addError("ERROR_REQUEST_QOS_RESOURCE_DETAIL_NO_UUID");
    }

    try {
        answer.putOpt("error", errorList.getList());
    } catch (final JSONException e) {
        System.out.println("Error saving ErrorList: " + e.toString());
    }

    answerString = answer.toString();

    return answerString;
}

From source file:com.asakusafw.yaess.tools.Explain.java

static int execute(String[] args) {
    assert args != null;
    Configuration conf;//from w w w .j a v  a  2s  .co  m
    try {
        conf = parseConfiguration(args);
    } catch (Exception e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(Integer.MAX_VALUE);
        formatter.printHelp(MessageFormat.format("java -classpath ... {0}", Explain.class.getName()), OPTIONS,
                true);
        e.printStackTrace(System.out);
        return 1;
    }
    try {
        explainBatch(conf.script);
    } catch (Exception e) {
        e.printStackTrace();
        return 1;
    }
    return 0;
}