List of usage examples for java.text MessageFormat format
public final StringBuffer format(Object arguments, StringBuffer result, FieldPosition pos)
MessageFormat
's pattern, with format elements replaced by the formatted objects, to the provided StringBuffer
. From source file:it.govpay.web.utils.Utils.java
public String getMessageFromResourceBundle(String bundleName, String key, Object params[], Locale locale) { String text = null;/*from ww w.j a v a2 s . co m*/ try { ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale, this.getCurrentClassLoader(params)); text = bundle.getString(key); } catch (MissingResourceException e) { text = MISSING_RESOURCE_START_PLACEHOLDER + key + MISSING_RESOURCE_END_PLACEHOLDER; } if (params != null) { MessageFormat mf = new MessageFormat(text, locale); text = mf.format(params, new StringBuffer(), null).toString(); } return text; }
From source file:it.govpay.web.utils.Utils.java
public Map<String, String> getMessagesFromResourceBundle(String bundleName, String keyPrefix, Object params[], Locale locale) {// ww w . j a v a2s . c o m Map<String, String> toRet = new HashMap<String, String>(); String text = null; ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale, this.getCurrentClassLoader(params)); Enumeration<String> keys = bundle.getKeys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); if (key.startsWith(keyPrefix)) { try { text = bundle.getString(key); } catch (MissingResourceException e) { text = MISSING_RESOURCE_START_PLACEHOLDER + key + MISSING_RESOURCE_END_PLACEHOLDER; } if (params != null) { MessageFormat mf = new MessageFormat(text, locale); text = mf.format(params, new StringBuffer(), null).toString(); } toRet.put(key.substring(keyPrefix.length()), text); } } return toRet; }
From source file:com.apress.prospringintegration.messageflow.splitter.MarketDataServiceActivator.java
@ServiceActivator public void handleField(Field dataField, @Headers Map<String, Object> headerMap) { System.out.println(/*from w w w . j a v a 2 s. c o m*/ MessageFormat.format("{0}:{1}", dataField.getFieldDescriptor().toString(), dataField.getValue())); for (String key : headerMap.keySet()) { Object value = headerMap.get(key); System.out.println(MessageFormat.format("header {0}:{1}", key, value)); } }
From source file:com.apress.prospringintegration.messageflow.aggregator.MarketFieldServiceActivator.java
@ServiceActivator public Field handleField(Field dataField, @Headers Map<String, Object> headerMap) { System.out.println(/*ww w. j av a 2 s . com*/ MessageFormat.format("{0}:{1}", dataField.getFieldDescriptor().toString(), dataField.getValue())); for (String key : headerMap.keySet()) { Object value = headerMap.get(key); System.out.println(MessageFormat.format("header {0}:{1}", key, value)); } return dataField; }
From source file:ips1ap101.ejb.core.BeanLocator.java
private static Object lookup(Class<?> local) { Bitacora.trace(BeanLocator.class, "lookup", local); String key = EAC.JNDI_EJB_LOOKUP_PATTERN; String pattern = EA.getString(key); String name = local.getSimpleName(); String root = StringUtils.removeEnd(name, LOCAL_SUFFIX); String arg0 = root + BEANS_SUFFIX; String arg1 = local.getName(); String jndi = MessageFormat.format(pattern, arg0, arg1); Bitacora.trace(key + "=" + pattern); Bitacora.trace(key + "=" + jndi); try {//from w w w. j a va2s . c o m Object object = InitialContext.doLookup(jndi); boolean assignable = object != null && local.isAssignableFrom(object.getClass()); Bitacora.trace(arg0 + "=" + object + ", assignable=" + assignable); return object; } catch (NamingException ex) { return null; } }
From source file:com.microsoft.tfs.client.common.ui.framework.console.ConsoleStream.java
private void printConsoleMessage(final String message, final boolean newline) { final Log log = console.getLog(); if (log.isDebugEnabled()) { final String messageFormat = "[{0}]: {1}"; //$NON-NLS-1$ final String text = MessageFormat.format(messageFormat, id, message); log.debug(text);/*ww w .java 2s . com*/ } if (!console.isEnabled()) { return; } console.throwIfDisposed(); /* * println() and print() can be called from any thread */ if (newline) { stream.println(message); } else { stream.print(message); } }
From source file:com.alibaba.otter.shared.arbitrate.impl.manage.helper.ManagePathUtils.java
/** * pipeline path (??config?)// w w w. ja va 2s . c o m */ public static String getPipeline(Long channelId, Long pipelineId) { // ?channelId , pipelineId path return MessageFormat.format(ArbitrateConstants.NODE_PIPELINE_FORMAT, String.valueOf(channelId), String.valueOf(pipelineId)); }
From source file:atg.taglib.json.JsonTestRunner.java
public void runTest() throws Exception { try {// w w w .j a va2 s .c o m String msg; msg = MessageFormat.format("Running test {0}/{1}... ", testType, testNum); System.out.println(msg); ResponseData data = Helper.getData(testType, testNum); msg = MessageFormat.format("{0}/{1} - Status {2} is expected.", testType, testNum, data.expectedStatusCode); assertEquals(msg, data.expectedStatusCode, data.statusCode); if (data.statusCode == HttpStatus.SC_OK) { // Compare JSON objects msg = MessageFormat.format("{0}/{1} - JSON Objects should match.", testType, testNum); System.out.print(msg); assertEquals(msg, data.expectedJson, data.json); } else { String expectedMsg = Messages.getString(data.expectedMsgKey); // If the expected Msg has a substitued value, just check the returned string // up to that point - we can't know what value will ctually be substituted if (expectedMsg.contains("{0}")) { expectedMsg = expectedMsg.substring(0, expectedMsg.indexOf("{0}")); } msg = MessageFormat.format("{0}/{1} - Exception should contain key {2} - \"{3}\"", testType, testNum, data.expectedMsgKey, expectedMsg); System.out.print(msg); assertTrue(msg, data.body.contains(expectedMsg)); } System.out.println(" OK"); } catch (Exception e) { String msg = MessageFormat.format("{0}/{1} - Exception occurred during test.", testType, testNum); System.out.println(msg); System.out.println(e); e.printStackTrace(System.out); throw new Exception(msg, e); } }
From source file:com.microsoft.tfs.core.clients.workitem.internal.wiqlparse.NodeCondition.java
@Override public void bind(final IExternal e, final NodeTableName tableContext, final NodeFieldName fieldContext) { getLeft().bind(e, tableContext, fieldContext); getRight().bind(e, tableContext, fieldContext); Tools.ensureSyntax(getRight().isConst() || (getRight() instanceof NodeFieldName), SyntaxError.INVALID_RIGHT_EXPRESSION_IN_CONDITION, getRight()); if (log.isDebugEnabled()) { log.debug(MessageFormat.format("right - {0} left - {1}", getRight().getDataType(), //$NON-NLS-1$ getLeft().getDataType())); }/* w w w. jav a 2 s .c o m*/ if (e != null) { Tools.ensureSyntax(getRight().canCastTo(getLeft().getDataType(), e.getLocale()), SyntaxError.INCOMPATIBLE_CONDITION_PARTS_TYPE, this); } if (e != null && (getCondition() == Condition.CONTAINS || getCondition() == Condition.CONTAINS_WORDS)) { Tools.ensureSyntax(getLeft().getDataType() == DataType.STRING, SyntaxError.CONTAINS_WORKS_FOR_STRINGS_ONLY, this); } super.bind(e, tableContext, fieldContext); }
From source file:com.microsoft.tfs.core.clients.build.internal.utils.BuildTypeUtil.java
/** * Download the TFSBuild.proj file specified in the passed {@link Item}, * then attempt to parse it for the values required for the returned * {@link BuildTypeInfo}.//from w w w .ja v a2 s.co m * * @param server * the build server (must not be <code>null</code>) * @param item * An {@link Item} representing the TFSBuild.proj file for the build * type. * @return parsed values for the passed AItem. * @throws IOException * if Exception occurred reading or parsing item. */ public static BuildTypeInfo parseBuildTypeFile(final IBuildServer server, final Item item) throws IOException { // Download file to temp location Check.notNull(item, "item"); //$NON-NLS-1$ final String buildTypeName = ServerPath.getFileName(ServerPath.getParent(item.getServerItem())); final String fileName = MessageFormat.format("{0}-{1}", buildTypeName, BuildConstants.PROJECT_FILE_NAME); //$NON-NLS-1$ final File localBuildFile = item .downloadFileToTempLocation(server.getConnection().getVersionControlClient(), fileName); BuildTypeInfo info; try { info = parseBuildTypeInfo(buildTypeName, localBuildFile, item.getEncoding()); } finally { try { localBuildFile.delete(); } catch (final Exception e) { // We did our best, log and ignore. log.error(Messages.getString("BuildTypeUtil.ErrorDeletingTemporaryBuildProjectFile"), e); //$NON-NLS-1$ } TempStorageService.getInstance().cleanUpItem(localBuildFile.getParentFile()); } return info; }