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:airbrake.Backtrace.java

private String causedBy(final Throwable throwable) {
    return MessageFormat.format("Caused by {0}", messageIn(throwable));
}

From source file:com.microsoft.tfs.core.clients.workitem.internal.files.AttachmentUpDownHelper.java

public static void download(final URL attachmentUrl, final File localTarget,
        final TFSTeamProjectCollection connection) throws DownloadException {
    final TaskMonitor taskMonitor = TaskMonitorService.getTaskMonitor();
    final HttpClient httpClient = connection.getHTTPClient();
    final GetMethod method = new GetMethod(attachmentUrl.toExternalForm());
    boolean cancelled = false;
    OutputStream outputStream = null;

    try {/*from  w  w  w.  ja  v  a2 s  . c  o  m*/
        final int statusCode = httpClient.executeMethod(method);

        if (statusCode != HttpStatus.SC_OK) {
            throw new DownloadException(MessageFormat.format(
                    Messages.getString("AttachmentUpDownHelper.ServerReturnedHTTPStatusFormat"), //$NON-NLS-1$
                    Integer.toString(statusCode)));
        }

        taskMonitor.begin(Messages.getString("AttachmentUpDownHelper.Downloading"), //$NON-NLS-1$
                computeTaskSize(method.getResponseContentLength()));

        final InputStream input = method.getResponseBodyAsStream();
        outputStream = new FileOutputStream(localTarget);
        outputStream = new BufferedOutputStream(outputStream);

        final byte[] buffer = new byte[DOWNLOAD_BUFFER_SIZE];
        int len;
        long totalBytesDownloaded = 0;

        while ((len = input.read(buffer)) != -1) {
            outputStream.write(buffer, 0, len);
            totalBytesDownloaded += len;
            taskMonitor.worked(1);
            taskMonitor.setCurrentWorkDescription(MessageFormat.format(
                    Messages.getString("AttachmentUpDownHelper.DownloadedCountBytesFormat"), //$NON-NLS-1$
                    totalBytesDownloaded));
            if (taskMonitor.isCanceled()) {
                cancelled = true;
                break;
            }
            Thread.sleep(10);
        }

    } catch (final Exception ex) {
        throw new DownloadException(ex);
    } finally {
        method.releaseConnection();
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (final IOException e) {
            }
        }
    }

    if (cancelled) {
        localTarget.delete();
    }
}

From source file:com.microsoft.tfs.client.eclipse.project.ProjectManagerWorkspaceJob.java

ProjectManagerWorkspaceJob(final ProjectManagerDataProvider dataProvider, final IProject project,
        final URI serverURI, final Credentials credentials) {
    super(MessageFormat.format(Messages.getString("ProjectManagerWorkspaceJob.JobNameFormat"), //$NON-NLS-1$
            serverURI.toString()));// w ww.j  a  va 2  s  .  c om

    setSystem(true);

    this.project = project;
    this.serverURI = serverURI;
    this.credentials = credentials;
}

From source file:com.futureplatforms.kirin.internal.fragmentation.CursorCoercer4.java

public JSONObject coerceToJSONObject(String[] cols, AbstractWindowedCursor c) {
    JSONObject obj = new JSONObject();
    for (int i = 0; i < cols.length; i++) {
        String name = cols[i];//from   w w  w .  ja  va 2 s.  c  o m

        if (c.isNull(i)) {
            continue;
        }
        String str = null;
        try {
            str = c.getString(i);
        } catch (Exception e) {
            // not a string
            Log.i(C.TAG, MessageFormat.format("Column {0} could not be represented as a string", name), e);
        }
        Object res = null;
        try {
            if (res == null) {
                res = Long.parseLong(str);
            }
        } catch (Exception e) {
            // wasn't a long!
        }
        try {
            if (res == null) {
                res = Double.parseDouble(str);
            }
        } catch (Exception e) {
            // wasn't a double!
        }
        if (res == null) {
            res = str;
        }

        if (res != null) {
            try {
                obj.putOpt(name, res);
            } catch (JSONException e) {
                Log.e(C.TAG, e.getLocalizedMessage(), e);
            }
        }
    }
    return obj;
}

From source file:com.jidesoft.spring.richclient.docking.LayoutManager.java

/**
 * Loads a the previously saved layout for the current page. If no 
 * previously persisted layout exists for the given page the built 
 * in default layout is used.//from  w w  w.j av  a 2s . c  om
 * 
 * @param manager The docking manager to use
 * @param pageId The page to get the layout for
 * @return a boolean saying if the layout requested was previously saved
 */
public static boolean loadPageLayoutData(DockingManager manager, String pageId, Perspective perspective) {
    manager.beginLoadLayoutData();
    try {
        //if(isValidLayout(manager, pageId, perspective)){
        try {
            String pageLayout = MessageFormat.format(PAGE_LAYOUT, new Object[] { pageId, perspective.getId() });
            //manager.setLayoutDirectory(".");
            manager.setUsePref(false);
            manager.loadLayoutDataFromFile(pageLayout);
            logger.info("Used existing layout");
            return true;
        } catch (Exception exc)
        //}
        //                        else{
        {
            logger.info("Using default layout");
            Resource r = Application.instance().getApplicationContext()
                    .getResource("classpath:layout/default.layout");
            manager.loadLayoutFrom(r.getInputStream());
            return false;
        }
    } catch (Exception e) {
        logger.info("Using default layout");
        manager.setUsePref(true);
        manager.loadLayoutData();
        return false;
    }
}

From source file:net.sourceforge.fenixedu.util.BundleUtil.java

@Deprecated // remove on move to major version 4.0.0
public static String getMessageFromModuleOrApplication(final String moduleName, final String key,
        final String... arguments) {
    try {/*from w  ww .  j a  v  a2s .  c om*/
        return MessageFormat.format(getResourceBundleByModuleName(moduleName).getString(key),
                (Object[]) arguments);
    } catch (MissingResourceException e) {
        try {
            return MessageFormat.format(getResourceBundleByModuleName(APPLICATION_MODULE).getString(key),
                    (Object[]) arguments);
        } catch (MissingResourceException ex) {
            return key;
        }
    }
}

From source file:com.nearinfinity.blur.log.LogImpl.java

public void debug(Object message, Object... args) {
    if (isDebugEnabled()) {
        log.debug(MessageFormat.format(message.toString(), args));
    }
}

From source file:com.microsoft.tfs.client.common.ui.framework.action.ExtendedAction.java

public String getErrorMessage() {
    if (errorMessage != null) {
        return errorMessage;
    }//from w  w w.j a  v a  2  s .  c o  m

    final String messageFormat = Messages.getString("ExtendedAction.CouldNotExecuteFormat"); //$NON-NLS-1$
    return MessageFormat.format(messageFormat, getName());
}

From source file:eu.esdihumboldt.hale.io.haleconnect.HaleConnectUrnBuilder.java

private static String[] splitProjectUrn(URI urn) {
    if (urn == null) {
        throw new NullPointerException("URN must not be null");
    } else if (!SCHEME_HALECONNECT.equals(urn.getScheme().toLowerCase())) {
        throw new IllegalArgumentException(
                MessageFormat.format("URN must have scheme \"{0}\"", SCHEME_HALECONNECT));
    }//from  ww w. j a va2 s. c  om

    if (StringUtils.isEmpty(urn.getSchemeSpecificPart())) {
        throw new IllegalArgumentException(MessageFormat.format("Malformed URN: {0}", urn.toString()));
    }

    String[] parts = urn.getSchemeSpecificPart().split(":");
    if (parts.length != 4) {
        throw new IllegalArgumentException(MessageFormat.format("Malformed URN: {0}", urn.toString()));
    } else if (!"project".equals(parts[0])) {
        throw new IllegalArgumentException(MessageFormat.format("No a project URN: {0}", urn.toString()));
    }
    return parts;
}

From source file:com.manydesigns.elements.util.RandomUtil.java

public static String getCodeFileName(String fileNameFormat, String randomCode) {
    return MessageFormat.format(fileNameFormat, randomCode);
}