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.NewsResource.java

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

    JSONObject request = null;

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

    System.out.println(MessageFormat.format(labels.getString("NEW_NEWS"), 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 = ResourceManager.getSysMsgBundle(new Locale(lang));
            } else
                lang = settings.getString("RMBT_DEFAULT_LANGUAGE");

            String sqlLang = lang;
            if (!sqlLang.equals("de"))
                sqlLang = "en";

            if (conn != null) {
                final long lastNewsUid = request.optLong("lastNewsUid");
                final String plattform = request.optString("plattform");
                final int softwareVersionCode = request.optInt("softwareVersionCode", -1);
                String uuid = request.optString("uuid");

                final JSONArray newsList = new JSONArray();

                try {

                    final PreparedStatement st = conn.prepareStatement("SELECT uid,title_" + sqlLang
                            + " AS title, text_" + sqlLang + " AS text FROM news " + " WHERE"
                            + " (uid > ? OR force = true)" + " AND active = true"
                            + " AND (plattform IS NULL OR plattform = ?)"
                            + " AND (max_software_version_code IS NULL OR ? <= max_software_version_code)"
                            + " AND (min_software_version_code IS NULL OR ? >= min_software_version_code)"
                            + " AND (uuid IS NULL OR uuid::TEXT = ?)" + //convert to text so that empty uuid-strings are tolerated
                            " ORDER BY time ASC");
                    st.setLong(1, lastNewsUid);
                    st.setString(2, plattform);
                    st.setInt(3, softwareVersionCode);
                    st.setInt(4, softwareVersionCode);
                    st.setString(5, uuid);

                    final ResultSet rs = st.executeQuery();

                    while (rs.next()) {
                        final JSONObject jsonItem = new JSONObject();

                        jsonItem.put("uid", rs.getInt("uid"));
                        jsonItem.put("title", rs.getString("title"));
                        jsonItem.put("text", rs.getString("text"));

                        newsList.put(jsonItem);
                    }

                    rs.close();
                    st.close();
                } catch (final SQLException e) {
                    e.printStackTrace();
                    errorList.addError("ERROR_DB_GET_NEWS_SQL");
                }
                //                    }

                answer.put("news", newsList);

            } else
                errorList.addError("ERROR_DB_CONNECTION");

        } catch (final JSONException e) {
            errorList.addError("ERROR_REQUEST_JSON");
            System.out.println("Error parsing JSON Data " + e.toString());
        }
    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();

    return answerString;
}

From source file:com.microsoft.tfs.jni.NegotiateEngine.java

private NegotiateEngine() {
    Negotiate i = null;// w w w  .  ja  v  a2s  . com
    try {
        if (NativeNegotiate.isAvailable()) {
            i = new NativeNegotiate();
        }
    } catch (final Exception e) {
        log.warn(MessageFormat.format("{0} reported itself available, but failed to load", //$NON-NLS-1$
                NativeNegotiate.class.getName()));
    }

    if (i == null) {
        i = new UnavailableNegotiate();
    }

    impl = i;
}

From source file:com.feilong.core.text.MessageFormatUtil.java

/**
 * ?.//from w ww. j  a  v a  2s  .c  o  m
 * 
 * <h3>:</h3>
 * 
 * <blockquote>
 * 
 * <pre class="code">
 * MessageFormatUtil.format("name={0}a{1}", "jin", "xin")                                             =   "name=jinaxin"
 * MessageFormatUtil.format("name={0,number}a{1}", 5, "xin")                                          =   "name=5axin"
 * MessageFormatUtil.format("name={0,date}a{1}", DateUtil.toDate("2000", DatePattern.yyyy), "xin")    =   "name=2000-1-1axin"
 * </pre>
 * 
 * </blockquote>
 * 
 * @param pattern
 *            ?????:
 *            <ul>
 *            <li>{argumentIndex}: 0-9 ,?????</li>
 *            <li>{argumentIndex,formatType}: ??</li>
 *            <li>{argumentIndex,formatType,FormatStyle}: ??,???????.</li>
 *            </ul>
 * @param arguments
 *            ??
 * @return  <code>pattern</code> null, {@link NullPointerException}<br>
 */
public static String format(String pattern, Object... arguments) {
    Validate.notNull(pattern, "pattern can't be null!");
    return MessageFormat.format(pattern, arguments);
}

From source file:com.sazneo.export.file.FileProcessor.java

/**
 * Initialise a new <code>FileProcessor</code> object
 * @param exportFile <code>File</code> referencing the exported XML file from Sazneo
 * @param outputDir <code>File</code> referencing the output dir to export files to
 *//*ww w .j a v a  2s. com*/
public FileProcessor(File exportFile, File outputDir) {
    logger.debug(MessageFormat.format("Exporting files from: {0}", exportFile.getAbsolutePath()));
    this.exportFile = exportFile;
    logger.debug(MessageFormat.format("Setting output dir to: {0}", outputDir.getAbsolutePath()));
    this.outputDir = outputDir;
}

From source file:org.nabucco.alfresco.enhScriptEnv.common.webscripts.processor.ClasspathScriptContent.java

/**
 * {@inheritDoc}//from  ww w.jav  a2s  .co m
 */
@Override
public InputStream getInputStream() {
    final InputStream stream = getClass().getClassLoader().getResourceAsStream(this.path);
    if (stream == null) {
        throw new WebScriptException(
                MessageFormat.format("Unable to retrieve input stream for script {0}", getPathDescription()));
    }
    return stream;
}

From source file:FileHelper.java

/**
 * Move a file from one location to another.  An attempt is made to rename
 * the file and if that fails, the file is copied and the old file deleted.
 *
 * @param from file which should be moved.
 * @param to desired destination of the file.
 * @param overwrite If false, an exception will be thrown rather than overwrite a file.
 * @throws IOException if an error occurs.
 *
 * @since ostermillerutils 1.00.00/* ww w .  j  a  v  a 2  s .  co m*/
 */
public static void move(File from, File to, boolean overwrite) throws IOException {
    if (to.exists()) {
        if (overwrite) {
            if (!to.delete()) {
                throw new IOException(MessageFormat.format(labels.getString("deleteerror"),
                        (Object[]) new String[] { to.toString() }));
            }
        } else {
            throw new IOException(MessageFormat.format(labels.getString("alreadyexistserror"),
                    (Object[]) new String[] { to.toString() }));
        }
    }

    if (from.renameTo(to))
        return;

    InputStream in = null;
    OutputStream out = null;
    try {
        in = new FileInputStream(from);
        out = new FileOutputStream(to);
        copy(in, out);
        in.close();
        in = null;
        out.flush();
        out.close();
        out = null;
        if (!from.delete()) {
            throw new IOException(MessageFormat.format(labels.getString("deleteoriginalerror"),
                    (Object[]) new String[] { from.toString(), to.toString() }));
        }
    } finally {
        if (in != null) {
            in.close();
            in = null;
        }
        if (out != null) {
            out.flush();
            out.close();
            out = null;
        }
    }
}

From source file:net.sfr.tv.mom.mgt.CommandHandler.java

protected String renderExpression(Object[] args) {

    String result;//from  w w  w . jav a2  s.c o m

    if (expression.indexOf("{") != -1) {
        if (args == null) {
            args = new String[] { "*" };
        }
        result = MessageFormat.format(expression, args);
    } else {
        result = expression;
    }

    return result;
}

From source file:com.microsoft.tfs.core.clients.workitem.internal.rules.FieldPickListSupport.java

@Override
public void reset() {
    allowed = null;/*w  w w .j ava  2s.c  o  m*/
    prohibited = null;
    suggested = null;
    allowedValues = null;
    prohibitedValues = null;

    if (log.isDebugEnabled()) {
        log.debug(MessageFormat.format("{0}: reset picklist", debuggingIdentifier)); //$NON-NLS-1$
    }
}

From source file:com.sonicle.webtop.tasks.TplHelper.java

public static String buildTaskReminderSubject(ProfileI18n profileI18n, VTask task) {
    StringBuilder sb = new StringBuilder();
    sb.append(StringUtils.abbreviate(task.getSubject(), 30));

    return MessageFormat.format(
            WT.lookupResource(SERVICE_ID, profileI18n.getLocale(), TasksLocale.EMAIL_REMINDER_SUBJECT),
            sb.toString());/* w w w  .  j  ava 2 s.  co m*/
}

From source file:com.microsoft.tfs.core.clients.workitem.internal.fields.AllowedValuesHelper.java

public String[] compute() {
    if (log.isDebugEnabled()) {
        log.debug(MessageFormat.format("computing allowed values for field: {0}", //$NON-NLS-1$
                Integer.toString(fieldDefinitionId)));
    }// w  ww. ja  v a  2s.  co  m

    if ((internalFieldType & FieldTypeConstants.MASK_FIELD_TYPE_ONLY) == FieldTypeConstants.TYPE_TREENODE) {
        return computeValuesForTreeNodesWithType(fieldDefinitionId);
    } else if (fieldDefinitionId == WorkItemFieldIDs.NODE_NAME) {
        return computeAllNodeNameValues();
    } else if (fieldDefinitionId == WorkItemFieldIDs.NODE_TYPE) {
        return computeAllNodeTypeValues();
    } else if (fieldDefinitionId == WorkItemFieldIDs.AUTHORIZED_AS) {
        return computeAllPersonNameValues();
    } else {
        return computeFromRules(fieldDefinitionId);
    }
}