List of usage examples for org.apache.commons.lang3 StringUtils replace
public static String replace(final String text, final String searchString, final String replacement)
Replaces all occurrences of a String within another String.
A null reference passed to this method is a no-op.
StringUtils.replace(null, *, *) = null StringUtils.replace("", *, *) = "" StringUtils.replace("any", null, *) = "any" StringUtils.replace("any", *, null) = "any" StringUtils.replace("any", "", *) = "any" StringUtils.replace("aba", "a", null) = "aba" StringUtils.replace("aba", "a", "") = "b" StringUtils.replace("aba", "a", "z") = "zbz"
From source file:com.linkedin.pinot.integration.tests.StarTreeClusterIntegrationTest.java
/** * Replace the star tree table name with reference table name, and add TOP 10000. The TOP 10000 is * added to make the reference result a super-set of star tree result. This will ensure any groups * with equal values that are truncated still appear in the reference result. * @param starQuery//from ww w. ja v a 2 s.co m */ private String convertToRefQuery(String starQuery) { String refQuery = StringUtils.replace(starQuery, STAR_TREE_TABLE_NAME, DEFAULT_TABLE_NAME); return (refQuery + " TOP 10000"); }
From source file:com.feilong.core.lang.StringUtil.java
/** * <code>text</code> <code>searchString</code> ?? <code>replacement</code>. * //from w ww . ja va2s. c om * <h3>:</h3> * * <blockquote> * * <p> * A {@code null} reference passed to this method is a no-op. * </p> * * <pre> * StringUtil.replace(null, *, *) = null * StringUtil.replace("", *, *) = "" * StringUtil.replace("any", null, *) = "any" * StringUtil.replace("any", *, null) = "any" * StringUtil.replace("any", "", *) = "any" * StringUtil.replace("aba", "a", null) = "aba" * StringUtil.replace("aba", "a", "") = "b" * StringUtil.replace("aba", "a", "z") = "zbz" * * StringUtil.replace("//?", "/", "_") = "__?" * StringUtil.replace(null, "/", "_") = null * StringUtil.replace("//?", "/", null) = "//?" * </pre> * * ?: * * <pre class="code"> * StringUtil.replace("SH1265,SH5951", "([a-zA-Z]+[0-9]+)", "'$1'") = SH1265,SH5951 * </pre> * * (? {@link #replaceAll(CharSequence, String, String)} ) * * </blockquote> * * <h3>?:</h3> * <blockquote> * <ol> * <li>??,, "b" ? "aaa" "aa" ? "ba" ? "ab".</li> * <li>{@link java.util.regex.Matcher#replaceAll(String) Matcher.replaceAll()}, * {@link java.util.regex.Matcher#quoteReplacement(String) Matcher.quoteReplacement()} ?</li> * </ol> * </blockquote> * * @param text * text to search and replace in, may be null * @param searchString * the String to search for, may be null * @param replacement * the String to replace it with, may be null * @return <code>text</code> null, null<br> * <code>searchString</code> null, <code>text</code><br> * <code>replacement</code> null, <code>text</code><br> * @see java.lang.String#replace(CharSequence, CharSequence) * @see org.apache.commons.lang3.StringUtils#replace(String, String, String) * @since jdk 1.5 */ public static String replace(final String text, final String searchString, final String replacement) { return StringUtils.replace(text, searchString, replacement); }
From source file:gobblin.hive.policy.HiveRegistrationPolicyBase.java
/*** * Obtain Hive table names filtered by <code>dbPrefix</code> (if present). * * The returned {@link List} contains:/*ww w . j a v a2 s .c o m*/ * A. If <code>dbPrefix</code> is absent: * 1. Table name returned by {@link #getTableName(Path)} * 2. Table names specified by <code>additional.hive.table.names</code> * B. If dbPrefix is present: * 1. Table names specified by <code>dbPrefix.hive.table.names</code> * * In table names above, the {@value PRIMARY_TABLE_TOKEN} if present is also replaced by the * table name obtained via {@link #getTableName(Path)}. * * @param dbPrefix Prefix to the property <code>additional.table.names</code>, to obtain table names only * for the specified db. Eg. If <code>dbPrefix</code> is db, then * <code>db.hive.table.names</code> is the resolved property name. * @param path Path for the table on filesystem. * @return Table names to register. */ protected List<String> getTableNames(Optional<String> dbPrefix, Path path) { List<String> tableNames = Lists.newArrayList(); Optional<String> primaryTableName; if ((primaryTableName = getTableName(path)).isPresent() && !dbPrefix.isPresent()) { tableNames.add(primaryTableName.get()); } String additionalNamesProp; if (dbPrefix.isPresent()) { additionalNamesProp = String.format("%s.%s", dbPrefix.get(), HIVE_TABLE_NAME); } else { additionalNamesProp = ADDITIONAL_HIVE_TABLE_NAMES; } if (!Strings.isNullOrEmpty(this.props.getProp(additionalNamesProp))) { for (String additionalTableName : this.props.getPropAsList(additionalNamesProp)) { String resolvedTableName = primaryTableName.isPresent() ? StringUtils.replace(additionalTableName, PRIMARY_TABLE_TOKEN, primaryTableName.get()) : additionalTableName; tableNames.add(this.tableNamePrefix + resolvedTableName + this.tableNameSuffix); } } return tableNames; }
From source file:com.tlabs.android.jeeves.views.EveFormat.java
private static String cleanHTML(final String html) { String r = StringUtils.isBlank(html) ? "" : html.trim(); if (r.isEmpty()) { return r; }/*from w w w .j a va 2 s. c o m*/ r = StringUtils.remove(html, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); //remove ALL the font tags //@see http://blogs.msdn.com/b/ericgu/archive/2006/01/30/519462.aspx r = r.replaceAll("<font(\\s|\\r|\\n).*?>", ""); r = r.replaceAll("</?font[^>]*>", ""); //r = StringUtils.replace(r, "\n", "<br/>\n"); r = StringUtils.replace(r, "<br>", "<br/>"); r = StringUtils.remove(r, "shellexec:"); //is it the shellexec or me or some people can't type? r = StringUtils.replace(r, "http://http://", "http://"); r = StringUtils.replace(r, "https://https://", "https://"); return r; }
From source file:com.alibaba.dubbo.qos.textui.TTable.java
/** * replace tab to four spaces/*from w ww.ja v a 2s .c o m*/ * * @param string the original string * @return the replaced string */ private static String replaceTab(String string) { return StringUtils.replace(string, "\t", " "); }
From source file:ch.cyberduck.core.dropbox.DropboxExceptionMappingService.java
private void parse(final StringBuilder buffer, final String message) { final JsonParser parser = new JsonParser(); try {//from www . j av a2 s.co m final JsonElement element = parser.parse(new StringReader(message)); if (element.isJsonObject()) { final JsonObject json = element.getAsJsonObject(); final JsonObject error = json.getAsJsonObject("error"); if (null == error) { this.append(buffer, message); } else { final JsonPrimitive tag = error.getAsJsonPrimitive(".tag"); if (null == tag) { this.append(buffer, message); } else { this.append(buffer, StringUtils.replace(tag.getAsString(), "_", " ")); } } } if (element.isJsonPrimitive()) { this.append(buffer, element.getAsString()); } } catch (JsonParseException e) { // Ignore } }
From source file:annis.administration.AdministrationDao.java
protected void createSchema() { log.info("creating ANNIS database schema (" + getSchemaVersion() + ")"); executeSqlFromScript("schema.sql"); // update schema version getJdbcTemplate().execute("DELETE FROM repository_metadata WHERE \"name\"='schema-version'"); getJdbcTemplate().execute("INSERT INTO repository_metadata " + "VALUES ('schema-version', '" + StringUtils.replace(getSchemaVersion(), "'", "''") + "');"); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlSerializer.java
private void appendHtmlTextArea(final HtmlTextArea htmlTextArea) { if (isVisible(htmlTextArea)) { String text = htmlTextArea.getText(); final BrowserVersion browser = htmlTextArea.getPage().getWebClient().getBrowserVersion(); if (browser.hasFeature(HTMLTEXTAREA_REMOVE_NEWLINE_FROM_TEXT)) { text = TEXT_AREA_PATTERN.matcher(text).replaceAll(""); text = StringUtils.replace(text, "\r", ""); text = StringUtils.normalizeSpace(text); } else {//from w w w . jav a2s . co m text = StringUtils.stripEnd(text, null); text = TEXT_AREA_PATTERN.matcher(text).replaceAll(AS_TEXT_NEW_LINE); text = StringUtils.replace(text, "\r", AS_TEXT_NEW_LINE); } text = StringUtils.replace(text, " ", AS_TEXT_BLANK); doAppend(text); } }
From source file:de.micromata.genome.gwiki.page.search.expr.SearchUtils.java
public static String sampleToHtmlOld(String text, List<String> words) { StringBuilder sb = new StringBuilder(); State state = State.LookForStart; int lastemp = 1; int lastStartWordIdx = 0; int i;//from ww w .jav a2 s. co m for (i = 0; i < text.length(); ++i) { char c = text.charAt(i); if (c != '<') { continue; } char c1 = nextChar(text, i + 1); char c2 = nextChar(text, i + 2); if (c1 == '/' && c2 == '^') { if (state == State.LookForEnd) { if (i > lastStartWordIdx) { String lb = text.substring(lastStartWordIdx, i); sb.append(enrich(lb, words)); } if (lastemp > 1) { sb.append("</em>"); } } i += 3; lastStartWordIdx = i + 1; state = State.LookForStart; } else if (c1 == '^') { if (i > lastStartWordIdx - 1) { String lb = text.substring(lastStartWordIdx, i); sb.append(enrich(lb, words)); } Pair<Integer, Integer> p = readEmp(text, i + 2); lastemp = p.getFirst(); i = p.getSecond() + 1; lastStartWordIdx = i; state = State.LookForEnd; if (lastemp > 1) { sb.append("<em>"); } } } if (i - 1 > lastStartWordIdx) { sb.append(enrich(text.substring(lastStartWordIdx, i - 1), words)); } String ret = sb.toString(); ret = StringUtils.replace(ret, "<br/>\n<br/>\n", "<br/>\n"); return ret; }
From source file:ca.simplegames.micro.utils.ResourceUtils.java
/** * Create a URI instance for the given URL, replacing spaces with * "%20" quotes first.// w ww. jav a2s . c om * <p>Furthermore, this method works on JDK 1.4 as well, * in contrast to the <code>URL.toURI()</code> method. * * @param url the URL to convert into a URI instance * @return the URI instance * @throws URISyntaxException if the URL wasn't a valid URI * @see java.net.URL#toURI() */ public static URI toURI(URL url) throws URISyntaxException { return new URI(StringUtils.replace(url.toString(), " ", "%20")); }