List of usage examples for java.text MessageFormat format
public static String format(String pattern, Object... arguments)
From source file:com.nearinfinity.blur.log.LogImpl.java
public void trace(Object message, Object... args) { if (isTraceEnabled()) { log.trace(MessageFormat.format(message.toString(), args)); } }
From source file:com.microsoft.tfs.client.common.ui.TFSCommonUIImages.java
private static void addDescriptor(final String symbolicName, final String imageFileName) { try {/*from w ww . ja va 2 s. c o m*/ final ImageDescriptor descriptor = newImageDescriptorFromFile(imageFileName); descriptors.put(symbolicName, descriptor); } catch (final Exception e) { final String messageFormat = "unable to load image [{0}]"; //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, imageFileName); log.warn(message, e); } }
From source file:com.microsoft.tfs.client.common.ui.controls.vc.ServerItemControlUtils.java
/** * Sets the initial selection of the given ServerItemControl to the given * server path. If the given path is not found on the server, will set the * selection to the nearest parent path. (ie, if you provide * $/proj/a/example.txt as the selection path and $/proj/a does not exist, * then $/proj will be given selection and expanded.) * * @param path/*www . j a va 2s .co m*/ * The server path to set the control selection to * @param control * The {@link ServerItemControl} to set selection on * @return true if the selection was set to the given path or a parent, * false otherwise */ public static boolean setInitialSelection(String path, final ServerItemControl control) { Check.notNull(control, "control"); //$NON-NLS-1$ if (path == null) { return false; } path = path.trim(); if (path.length() == 0) { return false; } /* * There is ambiguity here. The path (which could come from user input) * may refer to a folder or a file. First we'll try it as a folder. */ try { path = ServerPath.canonicalize(path); } catch (final ServerPathFormatException e) { log.warn(MessageFormat.format("Asked to set path to non server path {0}", path)); //$NON-NLS-1$ return false; } TypedServerItem item = new TypedServerItem(path, ServerItemType.FOLDER); control.setSelectedItem(item); if (control.getSelectedItem() != null) { return true; } /* * It wasn't a folder, so next try it as a file. */ item = new TypedServerItem(path, ServerItemType.FILE); control.setSelectedItem(item); if (control.getSelectedItem() != null) { return true; } /* * There was no item in the tree at the specified path. Try to find a * close item by successively trying the item's ancestors. (Note: open * the children in this case to match the Visual Studio behavior when * the exact path is not found.) */ item = item.getParent(); while (item != null && item.getType() != ServerItemType.ROOT) { control.setSelectedItem(item); final TypedServerItem selectedItem = control.getSelectedItem(); if (selectedItem != null) { if (ServerItemType.isFolder(selectedItem.getType()) && control instanceof ServerItemTreeControl) { ((ServerItemTreeControl) control).expandItem(selectedItem, 1); } return true; } item = item.getParent(); } /* * Nothing left to do. Neither the path nor any of the path's parents * were in the tree. */ return false; }
From source file:com.evolveum.midpoint.schema.util.LocalizationUtil.java
public static String resolve(String key, Object... params) { if (key != null && RESOURCE_BUNDLE.containsKey(key)) { return MessageFormat.format(RESOURCE_BUNDLE.getString(key), params); } else {/* w w w . j ava 2 s.c o m*/ return key; } }
From source file:com.baron.bm.controller.ErrorController.java
/** * ? web.xml? ?? ?/*from ww w. j a v a 2 s .c o m*/ */ @RequestMapping("/error") public String throwException(HttpServletRequest request, HttpServletResponse response, Model model) { int statusCode = (int) request.getAttribute("javax.servlet.error.status_code"); String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri"); if (requestUri == null) { requestUri = " "; //Unknown } String message; if (statusCode == 400) { message = MessageFormat.format(ErrorType.ERROR_400.getMessage(), requestUri); } else if (statusCode == 403) { message = MessageFormat.format(ErrorType.ERROR_403.getMessage(), requestUri); } else if (statusCode == 404) { message = MessageFormat.format(ErrorType.ERROR_404.getMessage(), requestUri); } else if (statusCode == 500) { message = MessageFormat.format(ErrorType.ERROR_500.getMessage(), requestUri); } else { message = MessageFormat.format(ErrorType.ERROR_ELSE.getMessage(), requestUri); } model.addAttribute("errorMessage", message); return "/common/error"; }
From source file:com.alibaba.ims.platform.exception.WebException.java
public WebException(String message, Object... params) { if (StringUtils.isBlank(message)) { return;/*from w w w . j a va 2 s .com*/ } this.message = MessageFormat.format(message, params); }
From source file:com.microsoft.tfs.client.common.util.EULAText.java
public static String getEULAText() { InputStream in = null;//from w ww . j a va 2 s. c o m BufferedReader bufferedReader = null; try { final StringBuffer inputData = new StringBuffer(); in = EULAText.class.getClassLoader().getResourceAsStream(RESOURCE_NAME); if (in == null) { throw new RuntimeException("unable to load license resource [" //$NON-NLS-1$ + RESOURCE_NAME + "] from class loader: " //$NON-NLS-1$ + EULAText.class.getClassLoader()); } final InputStreamReader reader = new InputStreamReader(in, "UTF-8"); //$NON-NLS-1$ bufferedReader = new BufferedReader(reader); String line = bufferedReader.readLine(); while (line != null) { inputData.append(line).append(NEWLINE); line = bufferedReader.readLine(); } return inputData.toString(); } catch (final Throwable t) { t.printStackTrace(); log.warn(t); final String messageFormat = Messages.getString("EulaText.ErrorLoadingEULAFormat"); //$NON-NLS-1$ final String message = MessageFormat.format(messageFormat, LICENSE_URL); return message; } finally { if (bufferedReader != null) { try { bufferedReader.close(); } catch (final IOException e) { } } } }
From source file:com.microsoft.tfs.client.eclipse.resource.RemoteSyncInfoFilter.java
@Override public ResourceFilterResult filter(final IResource resource, final int flags) { SyncInfo syncInfo;//from w ww . j a v a2s. co m try { syncInfo = SynchronizeSubscriber.getInstance().getSyncInfo(resource); } catch (final TeamException e) { log.warn(MessageFormat.format("Could not determine synchronization info for {0}", resource), e); //$NON-NLS-1$ return ResourceFilterResult.REJECT; } /* * Resource does not exist in the synchronization tree. */ if (syncInfo != null && syncInfo instanceof SynchronizeInfo) { /* If there's a remote operation, allow this to proceed. */ if (((SynchronizeInfo) syncInfo).getRemoteOperation() != null) { return ResourceFilterResult.ACCEPT; } } return ResourceFilterResult.REJECT; }
From source file:cl.borrego.foundation.util.Message.java
public String getFormattedMessage(String key, Object... arguments) { String ret = ""; if (this.m_lookup == null) { //TODO handle this } else if (key == null) { //TODO handle this } else {/*from w w w. java 2 s . co m*/ String msg = this.m_lookup.getString(key); ret = MessageFormat.format(msg, arguments); } return ret; }
From source file:com.asakusafw.shafu.core.net.ShafuNetwork.java
/** * Processes a content on the target URL. * @param url the target URL/* w w w .java2 s.c o m*/ * @param processor the content processor * @param <T> the processing result type * @return the process result * @throws IOException if failed to process the content */ public static <T> T processContent(URL url, IContentProcessor<? extends T> processor) throws IOException { String protocol = url.getProtocol(); if (protocol != null && HTTP_SCHEMES.contains(protocol)) { return processHttpContent(url, processor); } InputStream input; try { input = url.openStream(); } catch (IOException e) { throw new IOException(MessageFormat.format(Messages.ShafuNetwork_failedToOpenContent, url), e); } try { return processor.process(input); } finally { input.close(); } }