List of usage examples for java.text MessageFormat MessageFormat
public MessageFormat(String pattern)
From source file:org.talend.dataprep.transformation.actions.line.MakeLineHeader.java
private void setHeadersFromRow(DataSetRow row, ActionContext context) { LOGGER.debug("Make line header for rowId {} with parameters {} ", context.getRowId(), context.getParameters());/*from www . j a v a2 s . co m*/ List<ColumnMetadata> columns = context.getRowMetadata().getColumns(); for (int columnIndex = 0; columnIndex < columns.size(); columnIndex++) { ColumnMetadata column = columns.get(columnIndex); // get new column name keyed on column id from context or use the row value final int columnViewIndex = columnIndex + 1; String newColumnName = context.get(column.getId(), p -> { String name = row.get(column.getId()); if (StringUtils.isBlank(name)) { MessageFormat pattern = context.get(DEFAULT_TITLE_KEY, q -> new MessageFormat(DEFAULT_TITLE_VALUE_MASK)); name = pattern.format(new Object[] { columnViewIndex }); } return name; }); column.setName(newColumnName); } row.setDeleted(true); }
From source file:com.pactera.edg.am.metamanager.extractor.util.GenSqlUtil.java
/** * ?SQL// w w w .j a v a 2 s .c o m * * @throws IOException * XML? */ private static Map<String, String> readSQL(String location) throws IOException { Map<String, String> sqls = new HashMap<String, String>(); MessageFormat mf = new MessageFormat(Constants.SQL_STORE_PATH); String file = mf.format(new Object[] { location }); InputStream in = null; Dom4jReader reader = null; try { in = GenSqlUtil.class.getClassLoader().getResourceAsStream(file); reader = new Dom4jReader(); reader.initDocument(in); List<?> elements = reader.selectNodes(Constants.SQL_FLAG); for (int i = 0; i < elements.size(); i++) { Element element = (Element) elements.get(i); sqls.put(element.attributeValue("id"), element.getTextTrim()); } } finally { if (reader != null) { reader.close(); } if (in != null) { in.close(); } } return sqls; }
From source file:com.taobao.tddl.common.ConfigServerHelper.java
/** * // w w w . j a v a 2 s . co m */ public static Object subscribeSyncLogDbConfig(String syncServerID, DataListener listener) { if (syncServerID == null || syncServerID.length() == 0) { throw new IllegalStateException("IDsyncServerID"); } String dataId = new MessageFormat(DATA_ID_SYNCLOG_DBSET).format(new Object[] { syncServerID }); return ConfigServerHelper.subscribePersistentData(getCallerClassName(), dataId, listener); }
From source file:libepg.epg.util.datetime.DateTimeFieldConverter.java
private static Map<HMS_KEY, Integer> BcdTimeToMap(byte[] hms) throws ParseException { Map<HMS_KEY, Integer> ret = new HashMap<>(); if (hms.length != 3) { throw new IndexOutOfBoundsException( "?????3????????" + " ?=" + Hex.encodeHexString(hms)); }/* w w w. java 2 s . c o m*/ //ARIB???????????????? if (Arrays.equals(hms, UNDEFINED_BCD_TIME_BLOCK.getData())) { throw new ParseException("???????????" + " ?=" + Hex.encodeHexString(hms), 0); } Object[] parameters = null; final int hour = new BCD(hms[0]).getDecimal(); final int minute = new BCD(hms[1]).getDecimal(); final int second = new BCD(hms[2]).getDecimal(); CHECK: { final Range<Integer> HOUR_RANGE = Range.between(0, 23); if (!HOUR_RANGE.contains(hour)) { parameters = new Object[] { Hex.encodeHexString(hms), "", hour }; break CHECK; } final Range<Integer> MINUTE_AND_SECOND_RANGE = Range.between(0, 59); if (!MINUTE_AND_SECOND_RANGE.contains(minute)) { parameters = new Object[] { Hex.encodeHexString(hms), "", minute }; break CHECK; } if (!MINUTE_AND_SECOND_RANGE.contains(second)) { parameters = new Object[] { Hex.encodeHexString(hms), "", second }; break CHECK; } } if (parameters != null) { MessageFormat msg = new MessageFormat( "????????????={0} ={1} ={2}"); throw new ParseException(msg.format(parameters), 0); } if (LOG.isTraceEnabled()) { LOG.trace("hour=" + hour + " minute=" + minute + " second=" + second); } ret.put(HMS_KEY.HOUR, hour); ret.put(HMS_KEY.MINUTE, minute); ret.put(HMS_KEY.SECOND, second); return ret; }
From source file:com.ucuenca.pentaho.plugin.step.ontologymapping.OntoMapData.java
/** * Saves table data on DB Schema/*from www.j a v a 2 s . c o m*/ * @param table Dialog TableView * @param tableName DB table name * @return List of generated SQL INSERT statements * @throws Exception */ public List<String> saveTable(TableView table, String tableName) throws Exception { List<String> sqlInsertList = new ArrayList<String>(); this.createDBTable(table, tableName); Object[] pk = new Object[] { this.getTransName().toUpperCase(), this.getStepName().toUpperCase() }; DatabaseLoader.executeUpdate("DELETE FROM " + tableName + " WHERE TRANSID = ? AND STEPID = ?", pk); for (int i = 0; i < table.getItemCount(); i++) { Object[] tableValues = table.getItem(i); Object[] values = pk; values = ArrayUtils.addAll(values, tableValues); if (((String) values[2]).length() > 0) { try { String sqlInsertion = "INSERT INTO " + tableName + " VALUES("; String sqlInsertStack = sqlInsertion; int count = 1; while (count < values.length) { sqlInsertion += "?,"; sqlInsertStack += "{" + (count - 1) + "},"; count++; } sqlInsertion += "?)"; sqlInsertStack += "{" + (values.length - 1) + "})"; DatabaseLoader.executeUpdate(sqlInsertion, values); sqlInsertList.add(new MessageFormat(sqlInsertStack).format( this.setValuesFormat(ArrayUtils.addAll(new Object[] { "{0}", "{1}" }, tableValues)))); } catch (Exception e) { throw new KettleException("ERROR EXECUTING SQL INSERT: " + e.getMessage()); } } } return sqlInsertList; }
From source file:info.magnolia.jcr.node2bean.impl.Node2BeanTransformerImpl.java
public Node2BeanTransformerImpl(Class<?> defaultListImpl, Class<?> defaultSetImpl, Class<?> defaultQueueImpl) { this.defaultListImpl = defaultListImpl; this.defaultSetImpl = defaultSetImpl; this.defaultQueueImpl = defaultQueueImpl; // We use non-static BeanUtils conversion, so we can // * use our custom ConvertUtilsBean // * control converters (convertUtilsBean.register()) - we can register them here, locally, as opposed to a // global ConvertUtils.register() final EnumAwareConvertUtilsBean convertUtilsBean = new EnumAwareConvertUtilsBean(); // de-register the converter for Class, we do our own conversion in convertPropertyValue() convertUtilsBean.deregister(Class.class); convertUtilsBean.register(new Converter() { @Override//ww w . j a va 2s. c o m public Object convert(Class type, Object value) { return new MessageFormat((String) value); } }, MessageFormat.class); convertUtilsBean.register(new Converter() { @Override public Object convert(Class type, Object value) { return Pattern.compile((String) value); } }, Pattern.class); this.beanUtilsBean = new BeanUtilsBean(convertUtilsBean, new PropertyUtilsBean()); }
From source file:org.phenotips.vocabulary.internal.solr.EthnicityOntology.java
private SolrQuery addDynamicQueryParameters(String originalQuery, Integer rows, String sort, String customFq, boolean isId, SolrQuery query) { String queryString = originalQuery.trim(); String escapedQuery = ClientUtils.escapeQueryChars(queryString); if (isId) {/*from ww w . j av a2 s .c o m*/ query.setFilterQueries(new MessageFormat("id:{0}").format(new String[] { escapedQuery })); } query.setQuery(escapedQuery); query.set(SpellingParams.SPELLCHECK_Q, queryString); query.setRows(rows); if (StringUtils.isNotBlank(sort)) { for (String sortItem : sort.split("\\s*,\\s*")) { query.addSort(StringUtils.substringBefore(sortItem, " "), sortItem.endsWith(" desc") || sortItem.startsWith("-") ? ORDER.desc : ORDER.asc); } } return query; }
From source file:org.jamwiki.servlets.WikiPageInfo.java
/** * Return a description for the current page that can be used in an HTML meta * tag.//from w ww .j ava 2 s .com * * @return A description for the current page that can be used in an HTML meta * tag. */ public String getMetaDescription() { String pattern = Environment.getValue(Environment.PROP_BASE_META_DESCRIPTION); if (StringUtils.isBlank(pattern)) { return ""; } MessageFormat formatter = new MessageFormat(pattern); Object params[] = new Object[1]; params[0] = (this.topicName == null) ? "" : this.topicName; return formatter.format(params); }
From source file:org.apache.myfaces.shared_impl.util.MessageUtils.java
/** * Uses <code>MessageFormat</code> and the supplied parameters to fill in the param placeholders in the String. * * @param locale The <code>Locale</code> to use when performing the substitution. * @param msgtext The original parameterized String. * @param params The params to fill in the String with. * @return The updated String./*from www . j a va2 s .c o m*/ */ public static String substituteParams(Locale locale, String msgtext, Object params[]) { String localizedStr = null; if (params == null || msgtext == null) return msgtext; StringBuffer b = new StringBuffer(100); MessageFormat mf = new MessageFormat(msgtext); if (locale != null) { mf.setLocale(locale); b.append(mf.format(((Object) (params)))); localizedStr = b.toString(); } return localizedStr; }
From source file:translation.util.Tips.java
/** * @param tips/* w ww . j a v a 2s . c om*/ * @param bw * @throws IOException */ private static void writePOT(Set<String> tips, BufferedWriter bw) throws IOException { // header stuff Calendar now = Calendar.getInstance(); bw.write("msgid \"\"\n" + "msgstr \"\"\n" + "\"Project-Id-Version: PCGen-tips 6.x/SVN?\\n\"\n" + "\"Report-Msgid-Bugs-To: \\n\"\n" + "\"POT-Creation-Date: " + DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(now) + "\\n\"\n" + "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n" + "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n" + "\"Language-Team: LANGUAGE <LL@li.org>\\n\"\n" + "\"MIME-Version: 1.0\\n\"\n" + "\"Content-Type: text/plain; charset=UTF-8\\n\"\n" + "\"Content-Transfer-Encoding: 8bit\\n\"\n\n"); // filecontent MessageFormat msgid = new MessageFormat("msgid \"{0}\""); //$NON-NLS-1$ String msgstr = "msgstr \"\""; //$NON-NLS-1$ for (String tip : tips) { bw.write(msgid.format(new Object[] { escape(tip) })); bw.write("\n"); bw.write(msgstr); bw.write("\n\n"); } }