List of usage examples for java.text MessageFormat MessageFormat
public MessageFormat(String pattern)
From source file:com.taobao.tddl.common.ConfigServerHelper.java
/** * /*w w w . ja va2 s.c o m*/ */ public static Object subscribeShardRuleConfig(String appName, DataListener listener) { if (appName == null || appName.length() == 0) { throw new IllegalStateException("appName"); } String dataId = new MessageFormat(DATA_ID_TDDL_SHARD_RULE).format(new Object[] { appName }); return ConfigServerHelper.subscribePersistentData(getCallerClassName(), dataId, listener); }
From source file:org.extremecomponents.table.resource.TableResourceBundle.java
/** * Get the resource property./*from ww w .j a v a 2 s . com*/ */ public String getMessage(String code, Object[] args) { String result = findResource(customResourceBundle, code); if (result == null) { result = findResource(defaultResourceBundle, code); } if (result != null && args != null) { MessageFormat formatter = new MessageFormat(""); formatter.setLocale(locale); formatter.applyPattern(result); result = formatter.format(args); } return result; }
From source file:libepg.ts.aligner.Alligner2.java
/** * ?PID?????/*from w w w .j a va 2 s. c o m*/ * * @param pid ?PID * @param packets ? * @throws IllegalArgumentException ?pid?????? */ public Alligner2(int pid, List<TsPacket> packets) throws IllegalArgumentException { this.pid = pid; if (!TsPacket.PID_RANGE.contains(this.pid)) { MessageFormat msg = new MessageFormat( "PID(ID)?????={0} ?={1} ?={2}"); Object[] parameters = { this.pid, TsPacket.PID_RANGE.getMinimum(), TsPacket.PID_RANGE.getMaximum() }; throw new IllegalArgumentException(msg.format(parameters)); } this.packets = new ArrayList<>(); this.packets.addAll(packets); }
From source file:org.exist.security.realm.ldap.LdapContextFactory.java
public LdapContextFactory(final Configuration config) { configuration = Configurator.configure(this, config); if (principalPattern != null) { principalPatternFormat = new MessageFormat(principalPattern); }/*ww w .j av a 2 s . c o m*/ }
From source file:net.dataforte.cohesive.CSVExporter.java
public void addProperty(String name, String title, String format, Integer start, Integer end) { if (format != null) { columns.add(new CSVColumn(name, title, new MessageFormat(format), start, end)); } else {/*from w w w.j a v a 2 s . co m*/ columns.add(new CSVColumn(name, title, null, start, end)); } }
From source file:org.codehaus.groovy.grails.plugins.searchable.util.StringQueryUtils.java
/** * Highlights the different terms in the second query and returns a new query string. * This method is intended to be used with suggested queries to display the suggestion * to the user in highlighted format, as per Google, so the queries are expected to roughly match * @param first the original query/*from w ww.j av a 2 s . co m*/ * @param second the second query, in which to highlight differences * @param highlightPattern the pattern used to highlight; should be a {@link MessageFormat} pattern where argument * zero is the highlighted term text * @return a new copy of second with term differences highlighted * @throws ParseException if either first or second query is invalid * @see #highlightTermDiffs(String, String) */ public static String highlightTermDiffs(String first, String second, String highlightPattern) throws ParseException { final String defaultField = "$StringQueryUtils_highlightTermDiffs$"; Term[] firstTerms = LuceneUtils.realTermsForQueryString(defaultField, first, WhitespaceAnalyzer.class); Term[] secondTerms = LuceneUtils.realTermsForQueryString(defaultField, second, WhitespaceAnalyzer.class); if (firstTerms.length != secondTerms.length) { LOG.warn("Expected the same number of terms for first query [" + first + "] and second query [" + second + "], " + "but first query has [" + firstTerms.length + "] terms and second query has [" + secondTerms.length + "] terms " + "so unable to provide user friendly version. Returning second query as-is."); return second; } MessageFormat format = new MessageFormat(highlightPattern); StringBuffer diff = new StringBuffer(second); int offset = 0; for (int i = 0; i < secondTerms.length; i++) { Term firstTerm = firstTerms[i]; Term secondTerm = secondTerms[i]; boolean noField = defaultField.equals(secondTerm.field()); String snippet = noField ? secondTerm.text() : secondTerm.field() + ":" + secondTerm.text(); int pos = diff.indexOf(snippet, offset); if (!firstTerm.text().equals(secondTerm.text())) { if (!noField) { pos += secondTerm.field().length() + 1; } diff.replace(pos, pos + secondTerm.text().length(), format.format(new Object[] { secondTerm.text() })); } offset = pos; } return diff.toString(); }
From source file:ca.uhn.fhir.i18n.HapiLocalizer.java
public String getMessage(String theQualifiedKey, Object... theParameters) { if (theParameters != null && theParameters.length > 0) { MessageFormat format = myKeyToMessageFormat.get(theQualifiedKey); if (format != null) { return format.format(theParameters).toString(); }// ww w . ja va2 s. c o m String formatString = findFormatString(theQualifiedKey); format = new MessageFormat(formatString.trim()); myKeyToMessageFormat.put(theQualifiedKey, format); return format.format(theParameters).toString(); } else { String retVal = findFormatString(theQualifiedKey); return retVal; } }
From source file:com.clustercontrol.util.Messages.java
/** * Returns the formatted message for the given key in the resource bundle. * //from w w w .jav a 2 s .com * @param key * the resource name * @param args * the message arguments * @param locale * @return the string */ public static String getString(String key, Object[] args, Locale locale) { MessageFormat messageFormat = new MessageFormat(getString(key, key, locale)); return messageFormat.format(args); }
From source file:it.jnrpe.plugin.CCheckOracle.java
/** * Checks if the database is reacheble//from ww w.jav a 2 s.c o m * @param c * @param cl * @return */ private CReturnValue checkAlive(Connection c, CCommandLine cl) { Statement stmt = null; ResultSet rs = null; String sMsg = "{0} : {1} - {2} {3}"; Object[] vObjs = new Object[4]; vObjs[0] = "CHECK_ORACLE"; vObjs[1] = cl.getOptionValue("db"); vObjs[2] = "OK"; vObjs[3] = ""; MessageFormat mf = new MessageFormat(sMsg); try { stmt = c.createStatement(); rs = stmt.executeQuery("SELECT SYSDATE FROM DUAL"); return new CReturnValue(IJNRPEConstants.STATE_OK, mf.format(vObjs)); } catch (SQLException sqle) { vObjs[2] = "UNKNOWN"; vObjs[3] = sqle.getMessage(); return new CReturnValue(IJNRPEConstants.STATE_UNKNOWN, mf.format(vObjs)); } catch (Exception e) { vObjs[2] = "CRITICAL"; vObjs[3] = e.getMessage(); return new CReturnValue(IJNRPEConstants.STATE_CRITICAL, mf.format(vObjs)); } finally { try { stmt.close(); rs.close(); } catch (Exception e) { } } }
From source file:com.haulmont.cuba.desktop.sys.vcl.DatePicker.DatePicker.java
@Override public void setLinkDay(Date linkDay) { MessageFormat todayFormat = new MessageFormat( AppBeans.get(Messages.class).getMessage("com.haulmont.cuba.desktop", "DatePicker.linkFormat")); todayFormat.setFormat(0, new SimpleDateFormat( Datatypes.getFormatStrings(AppBeans.get(UserSessionSource.class).getLocale()).getDateFormat())); setLinkFormat(todayFormat);/* ww w. j a v a 2s . c o m*/ super.setLinkDay(linkDay); }