List of usage examples for org.apache.commons.lang StringUtils replaceEach
public static String replaceEach(String text, String[] searchList, String[] replacementList)
Replaces all occurrences of Strings within another String.
From source file:TranslationList.java
/** Attempts to translate a text using the word list. */ public String translate(Tokenizer tok, String text) { StringBuilder res = new StringBuilder(); for (Token t : tok.tokenize(text)) { if (Transliterator.hasAsianChar(t.getSurface())) { // attempt (partial) translation String s = t.getSurface(); String r = StringUtils.replaceEach(s, srcEverywhere, trlEverywhere); r = replaceAnyOfAtStart(r, srcPrefix, trlPrefix); r = replaceAnyOfAtEnd(r, srcSuffix, trlSuffix); if (r != s && verbose > 1) System.out.println("translation list: translated " + s + " to " + r); res.append(r);//from ww w .j a v a2 s . c om } else // tokens without asian chars can be ignored here and will be copied directly res.append(t.getSurface()); } return res.toString(); }
From source file:com.hangum.tadpole.rdb.core.dialog.export.sqltoapplication.application.SQLToAxisjConvert.java
/** * sql to string/*from w ww.j a v a2 s.co m*/ * * @param userDB * @param name * @param sql * @return */ public static String sqlToString(UserDBDAO userDB, String sql, Map options, List<AxisjHeaderDAO> listAxisjHeader) { String retHtml = ""; try { String STR_TEMPLATE = IOUtils.toString(SQLToAxisjConvert.class.getResource("axis.js.template")); QueryExecuteResultDTO queryResult = QueryUtils.executeQuery(userDB, sql, 0, 4); Map<Integer, String> columnLabel = queryResult.getColumnLabelName(); String strHead = ""; StringBuffer sbGroup = new StringBuffer(); for (AxisjHeaderDAO dao : listAxisjHeader) { sbGroup.append(String.format(GROUP_TEMPLATE, dao.getKey(), dao.getLabel(), dao.getWidth(), AxisjConsts.alignValue[dao.getAlign()], AxisjConsts.sortValue[dao.getSort()], dao.isColHeadTool() ? "true" : "false", dao.getFormatter(), dao.getTooltip(), dao.getDisabled(), dao.getChecked())); } strHead = StringUtils.removeEnd(sbGroup.toString(), ","); // String strBody = ""; StringBuffer sbData = new StringBuffer(); TadpoleResultSet tdbResult = queryResult.getDataList(); for (Map<Integer, Object> resultRow : tdbResult.getData()) { sbData.setLength(0); for (int i = 0; i < columnLabel.size(); i++) { String strColumnLabel = columnLabel.get(i); String strColumnValue = "" + resultRow.get(i); strColumnValue = StringUtils.replaceEach(strColumnValue, new String[] { ">", "<", "\"", "\r", "\n" }, new String[] { ">", "<", "\\\"", "", "\\n" }); sbData.append(String.format(GROUP_DATA_TEMPLATE, strColumnLabel, "\"" + strColumnValue + "\"")); } strBody += PREFIX_TAB + "{" + StringUtils.removeEnd(sbData.toString(), ",") + "},"; } strBody = StringUtils.removeEnd(strBody, ","); retHtml = StringUtils.replaceEach(STR_TEMPLATE, new String[] { "_TDB_TEMPLATE_TITLE_" }, new String[] { (String) options.get("name") }); retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_THEME_" }, new String[] { (String) options.get("theme") }); retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_FIXEDCOL_" }, new String[] { (String) options.get("fixedColSeq") }); retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_FITTOWIDTH_" }, new String[] { (String) options.get("fitToWidth") }); retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_HEADALIGN_" }, new String[] { (String) options.get("colHeadAlign") }); retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_MERGECELL_" }, new String[] { (String) options.get("mergeCells") }); retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_HEIGHT_" }, new String[] { (String) options.get("height") }); retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_SORT_" }, new String[] { (String) options.get("sort") }); retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_HEADTOOL_" }, new String[] { (String) options.get("colHeadTool") }); retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_VIEWMODE_" }, new String[] { (String) options.get("viewMode") }); retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_HEAD_" }, new String[] { strHead }); retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_BODY_" }, new String[] { strBody }); } catch (Exception e) { logger.error("SQL template exception", e); } return retHtml; }
From source file:hello.jaxrs.GreetingsResource.java
private void printGreetings(final PrintWriter writer, final Collection<String> greetings) { writer.println("<h2>Greetings!</h2>"); if (greetings.isEmpty()) { writer.println("No greetings available. Be the first and say hello!"); } else {//from www. j a va 2 s . com writer.println("<ul>"); for (String greeting : greetings) { // escape HTML greeting = StringEscapeUtils.escapeHtml(StringUtils.trimToEmpty(greeting)); // format greeting = StringUtils.replaceEach(greeting, new String[] { "(", ")" }, new String[] { "<br><small>(", ")</small>" }); // print writer.println("<li>"); writer.println(greeting); writer.println("</li>"); } writer.println("</ul>"); } }
From source file:jef.tools.string.RegexpUtils.java
/** * ??/*from w w w . ja v a2 s . c om*/ * *?????0~1?? Windows?? * @param key * @return */ public static String simpleMatchToRegexp(String key) { //* ?? key = escapeRegChars(key, STAR_QUESTION); key = StringUtils.replaceEach(key, new String[] { "*", "?", "+" }, new String[] { ".*", ".?", ".+" }); return key; }
From source file:com.xpn.xwiki.store.jcr.query.JcrQueryExecutor.java
/** * Substitute query parameters to its values. * TODO: Use PreparedQuery from JCRv2./* w ww . ja v a2s . c o m*/ * @param query * @return clear query statement without parameters */ protected String createNativeStatement(Query query) { String statement = query.getStatement(); if (query.isNamed()) { statement = this.queriesBundle.getString(statement); } int n = query.getNamedParameters().size(); String[] vars = new String[n]; String[] vals = new String[n]; int count = 0; for (Entry<String, Object> e : query.getNamedParameters().entrySet()) { vars[count] = ":{" + e.getKey() + "}"; vals[count] = getValueAsString(e.getValue()); ++count; } return StringUtils.replaceEach(statement, vars, vals); }
From source file:jef.tools.string.RegexpUtils.java
public static String[] getSimpleMatchResult(String str, String key, boolean strict) { key = escapeRegChars(key, STAR_QUESTION); key = StringUtils.replaceEach(key, new String[] { "*", "?", "+" }, new String[] { "(.*)", "(.?)", "(.+)" }); return getMatcherResult(str, key, strict); }
From source file:eionet.cr.util.URLUtil.java
/** * Escapes IRI's reserved characters in the given URL string. * * @param url//from ww w . j ava 2s . c om * @return */ public static String escapeIRI(String url) { return url == null ? null : StringUtils.replaceEach(url, BAD_IRI_CHARS, BAD_IRI_CHARS_ESCAPES); }
From source file:com.neusoft.mid.clwapi.tools.JacksonUtils.java
/** * json</br>//from w w w . ja v a 2s.c o m * * JacksonUtils.jsonCoder(null,true) = null; * JacksonUtils.jsonCoder(null,false) = null; * JacksonUtils.jsonCoder("\babc\t\"",true) = "\\babc\\t\\\""; * JacksonUtils.jsonCoder("\\babc\\t\\\"",false) = "\babc\t\""; * * @param str * @param encoder * @return */ private static String jsonCoder(String str, boolean encoder) { logger.debug("transferred meaning value is [" + str + "]"); String newStr = null; if (encoder) { // encoder newStr = StringUtils.replaceEach(str, DECODER_CHAR, ENCODER_CHAR); } else { // decoder newStr = StringUtils.replaceEach(str, ENCODER_CHAR, DECODER_CHAR); } logger.debug("transferred meaned value is [" + newStr + "]"); return newStr; }
From source file:br.com.renatoccosta.regexrenamer.view.FrmAbout.java
private void initLocal() { ((JPanel) this.getContentPane()).setOpaque(false); txtDeveloper.setText(StringUtils.replace(txtDeveloper.getText(), "${devname}", "Renato Couto da Costa")); String version = VersionInfoUtil.getVersionNumber(); SimpleDateFormat sdf = new SimpleDateFormat("E, dd MMMM yyyy HH:mm"); String date = sdf.format(VersionInfoUtil.getVersionDate()); String vmachine = System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version"); String so = System.getProperty("os.name") + " " + System.getProperty("os.arch"); txtInfo.setText(StringUtils.replaceEach(txtInfo.getText(), new String[] { "${version}", "${versionDate}", "${vmachine}", "${so}" }, new String[] { version, date, vmachine, so })); }
From source file:com.photon.phresco.service.rest.api.AdminService.java
private String filterString(String inputString) { return StringUtils.replaceEach(inputString, new String[] { " ", "'", "&", "(", ")", "{", "}" }, new String[] { "-", "", "", "", "", "", "" }).toLowerCase(); }