List of usage examples for java.text MessageFormat format
public static String format(String pattern, Object... arguments)
From source file:com.microsoft.tfs.client.common.ui.teamexplorer.internal.pendingchanges.PendingChangesTree.java
public void addPendingChange(final PendingChange pendingChange) { final String localPath; final String serverPath; final String[] segments; if ((localPath = pendingChange.getLocalItem()) != null) { segments = localPath.split(QUOTED_LOCAL_PATH_SEPARATOR); } else if ((serverPath = pendingChange.getServerItem()) != null) { segments = serverPath.split(QUOTED_SERVER_PATH_SEPARATOR); } else {/*from ww w .ja va 2s .co m*/ log.warn(MessageFormat.format("Pending change ''{0}'' has neither server nor local path, skipping", //$NON-NLS-1$ pendingChange)); return; } PendingChangesTreeNode currentNode = root; for (final String segment : segments) { final PendingChangesTreeNode existingNode = currentNode.findChild(segment); if (existingNode == null) { final PendingChangesTreeNode newNode = createTreeNode(segment); currentNode.addChild(newNode); currentNode = newNode; } else { currentNode = existingNode; } } currentNode.setPendingChange(pendingChange); }
From source file:com.ibm.watson.apis.conversation_enhanced.rest.SetupResource.java
/** * Method to fetch config JSON object and also the workspace_id. * /* w w w .jav a 2s . c om*/ * @return response */ @GET @Produces(MediaType.APPLICATION_JSON) public Response getConfig() { String workspace_id = System.getenv(Constants.WORKSPACE_ID); //$NON-NLS-1$ logger.debug(MessageFormat.format(Messages.getString("SetupResource.WORKSPACE_ID_IS"), workspace_id)); JsonObject config = new JsonObject(); config.addProperty(Constants.SETUP_STATUS_MESSAGE, Messages.getString("SetupResource.SETUP_STATUS_MSG")); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_STEP, "0"); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_STATE, Constants.NOT_READY); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_PHASE, Messages.getString("SetupResource.PHASE_ERROR")); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_MESSAGE, Messages.getString("SetupResource.ERROR_CHECK_LOGS")); //$NON-NLS-1$ //$NON-NLS-2$ // Fetch the updated config JSON object from the servlet listener config = new ServletContextListener().getJsonConfig(); config.addProperty(Constants.SETUP_STATUS_MESSAGE, Messages.getString("SetupResource.SETUP_STATUS_MSG")); //$NON-NLS-1$ //$NON-NLS-2$ logger.debug(Messages.getString("SetupResource.CONFIG_STATUS") + config); // The following checks for the workspace_id after the Retrieve and // Rank service is ready for the user. This is done so that when the initial setup is being // done, the user can setup the Conversation service Workspace and provide it's id. if (config.get(Constants.SETUP_STEP).getAsInt() == 3 && config.get(Constants.SETUP_STATE).getAsString().equalsIgnoreCase(Constants.READY)) { if (StringUtils.isNotBlank(workspace_id)) { config.addProperty(Constants.WORKSPACE_ID, workspace_id); //$NON-NLS-1$ } else { config.addProperty(Constants.SETUP_STEP, "0"); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_STATE, Constants.NOT_READY); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_PHASE, Messages.getString("SetupResource.PHASE_ERROR")); //$NON-NLS-1$ //$NON-NLS-2$ config.addProperty(Constants.SETUP_MESSAGE, Messages.getString("SetupResource.WORKSPACE_ID_ERROR")); //$NON-NLS-1$ //$NON-NLS-2$ } } return Response.ok(config.getAsJsonObject().toString().trim()).type(MediaType.APPLICATION_JSON) .header("Cache-Control", "no-cache").build(); }
From source file:core.tooling.logging.Logger.java
public void debug(String message, Throwable throwable, Object... params) { if (isDebugEnabled()) { logger.debug(MessageFormat.format(message, params), throwable); }// w w w . j a v a 2s . c o m }
From source file:com.microsoft.tfs.client.common.ui.framework.diagnostics.cache.DataProviderWrapper.java
public void populate() { available = true;/*from ww w . j a v a2 s .c om*/ final DataProvider provider = dataProviderInfo.getDataProvider(); if (provider instanceof PopulateCallback) { final PopulateCallback callback = (PopulateCallback) provider; try { callback.populate(); } catch (final Throwable t) { final String messageFormat = "data provider [{0}] failed populate"; //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, dataProviderInfo.getID()); log.warn(message, t); available = false; return; } } if (provider instanceof AvailableCallback) { final AvailableCallback callback = (AvailableCallback) provider; try { available = callback.isAvailable(); } catch (final Throwable t) { final String messageFormat = "data provider [{0}] failed isAvailable"; //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, dataProviderInfo.getID()); log.warn(message, t); available = false; return; } } if (available) { try { data = provider.getData(); dataNOLOC = provider.getDataNOLOC(); } catch (final Throwable t) { final String messageFormat = "data provider [{0}] failed getData"; //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, dataProviderInfo.getID()); log.warn(message, t); available = false; return; } } }
From source file:com.microsoft.tfs.client.eclipse.resource.PluginResourceHelpers.java
public static ResourceRepositoryMap mapResources(final IResource[] resources) { final Map<IProject, List<IResource>> projectsToResources = new HashMap<IProject, List<IResource>>(); for (int i = 0; i < resources.length; i++) { final IProject project = resources[i].getProject(); List<IResource> list = projectsToResources.get(project); if (list == null) { list = new ArrayList<IResource>(); projectsToResources.put(project, list); }// www . jav a 2 s .co m list.add(resources[i]); } final IProject[] projects = projectsToResources.keySet() .toArray(new IProject[projectsToResources.keySet().size()]); final Map<TFSRepository, List<IProject>> repositoriesToProjects = new HashMap<TFSRepository, List<IProject>>(); for (int i = 0; i < projects.length; i++) { final TFSRepository repository = TFSEclipseClientPlugin.getDefault().getProjectManager() .getRepository(projects[i]); if (repository == null) { PluginResourceHelpers.log .warn(MessageFormat.format("No TFS Repository for project {0}", projects[i].getName())); //$NON-NLS-1$ continue; } List<IProject> list = repositoriesToProjects.get(repository); if (list == null) { list = new ArrayList<IProject>(); repositoriesToProjects.put(repository, list); } list.add(projects[i]); } final TFSRepository[] repositories = repositoriesToProjects.keySet() .toArray(new TFSRepository[repositoriesToProjects.keySet().size()]); final ResourceRepositoryMap resultMap = new ResourceRepositoryMap(); for (int i = 0; i < repositories.length; i++) { final IProject[] projectsForRepository = repositoriesToProjects.get(repositories[i]) .toArray(new IProject[] {}); final List<IResource> resourcesForRepositoryList = new ArrayList<IResource>(); for (int j = 0; j < projectsForRepository.length; j++) { resourcesForRepositoryList.addAll(projectsToResources.get(projectsForRepository[j])); } final IResource[] resourcesForRepository = resourcesForRepositoryList .toArray(new IResource[resourcesForRepositoryList.size()]); resultMap.addMappings(repositories[i], resourcesForRepository); } return resultMap; }
From source file:org.web4thejob.web.util.MediaUtil.java
public static String getMediaDescription(byte[] media) { String mediaFormat = getMediaFormat(media); if (isImage(mediaFormat)) { Image image = getImage(media); mediaFormat = new StringBuilder().append(mediaFormat).append(" ").append(image.getWidth()).append("x") .append(image.getHeight()).toString(); }//from ww w . ja v a 2 s. c o m return new StringBuilder().append("media | ").append(mediaFormat).append(" (") .append(MessageFormat.format("{0," + "number,#,##0}", media.length - MEDIA_TYPE_SIGNATURE)) .append(" bytes)").toString(); }
From source file:com.macrossx.wechat.impl.WechatMessageHelper.java
@Override public Optional<WecahtMessageTemplateRespObj> sendTemplate(WechatMessageTemplate template) { try {/*from w w w . ja va 2 s.c o m*/ Optional<WechatAccessToken> token = wechatHelper.getAccessToken(); if (token.isPresent()) { WechatAccessToken accessToken = token.get(); HttpPost httpPost = new HttpPost(); System.out.println(new Gson().toJson(template)); httpPost.setEntity(new StringEntity(new Gson().toJson(template), "utf-8")); httpPost.setURI(new URI(MessageFormat.format(WechatConstants.MESSAGE_TEMPLATE_SEND_URL, accessToken.getAccess_token()))); return new WechatHttpClient().send(httpPost, WecahtMessageTemplateRespObj.class); } } catch (URISyntaxException e) { log.info(e.getMessage()); } return Optional.empty(); }
From source file:com.asakusafw.runtime.directio.DirectDataSourceRepository.java
/** * Creates a new instance./* w w w .j av a2 s.c o m*/ * @param providers provider objects * @throws IllegalArgumentException if some parameters were {@code null} */ public DirectDataSourceRepository(Collection<? extends DirectDataSourceProvider> providers) { if (providers == null) { throw new IllegalArgumentException("providers must not be null"); //$NON-NLS-1$ } if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("Preparing directio datasources (count={0})", //$NON-NLS-1$ providers.size())); } for (DirectDataSourceProvider provider : providers) { NodePath path = NodePath.of(provider.getPath()); if (LOG.isDebugEnabled()) { LOG.debug(MessageFormat.format("Preparing datasource (id={0}, path={1})", //$NON-NLS-1$ provider.getId(), path)); } Node current = root; for (String segment : path) { current = current.addChild(segment); } if (current.hasContent()) { throw new IllegalArgumentException( MessageFormat.format("The path \"{0}\" is mapped multiple DirectDataSources ({1}, {2})", path, provider, current.provider)); } current.provider = provider; } }
From source file:com.asakusafw.runtime.windows.WindowsSupport.java
@Override protected void before() throws IOException { if (WinUtilsInstaller.isTarget()) { Assume.assumeFalse("skip this test", skip); } else {/*from w w w . j av a 2 s . c o m*/ return; } try { LOG.debug("checking winutils.exe"); //$NON-NLS-1$ if (WinUtilsInstaller.isAlreadyInstalled()) { return; } File install = prepare(); assert install != null; WinUtilsInstaller.register(install); LOG.info(MessageFormat.format("winutils.exe was successfully installed", //$NON-NLS-1$ install)); cleanup = true; } catch (Exception e) { LOG.warn("failed to install winutils.exe", e); //$NON-NLS-1$ } }
From source file:com.microsoft.tfs.client.common.ui.framework.action.ExtendedAction.java
@Override public final void run(final IAction action) { try {// ww w . j a v a2s .c om ClientTelemetryHelper.sendRunActionEvent(this); doRun(action); } catch (final Throwable t) { final String messageFormat = Messages.getString("ExtendedAction.ErrorDialogTitleFormat"); //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, getName()); LogFactory.getLog(this.getClass()).error(message, t); /* TODO: use StatusHelper here */ ErrorDialog.openError(getShell(), message, null, new Status(IStatus.ERROR, TFSCommonUIClientPlugin.PLUGIN_ID, 0, getErrorMessage(), t)); } }