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.sonicle.webtop.core.versioning.SqlScript.java
private void readFile(InputStreamReader readable) throws IOException { this.statements = new ArrayList<>(); String lines[] = null;// w w w . j a v a 2 s .co m StringBuilder sbsql = null; Scanner s = new Scanner(readable); s.useDelimiter("(;( )?(\r)?\n)"); while (s.hasNext()) { String block = s.next(); block = StringUtils.replace(block, "\r", ""); if (!StringUtils.isEmpty(block)) { // Remove remaining ; at the end of the block (only if this block is the last one) if (!s.hasNext() && StringUtils.endsWith(block, ";")) block = StringUtils.left(block, block.length() - 1); sbsql = new StringBuilder(); lines = StringUtils.split(block, "\n"); for (String line : lines) { if (CommentLine.matches(line)) continue; sbsql.append(StringUtils.trim(line)); sbsql.append(" "); } if (sbsql.length() > 0) statements.add(sbsql.toString()); } } }
From source file:com.gargoylesoftware.htmlunit.javascript.host.css.CSSFontFaceRule.java
/** * {@inheritDoc}// w w w . j a v a2 s . c o m */ @Override public String getCssText() { String cssText = super.getCssText(); final BrowserVersion browserVersion = getBrowserVersion(); if (browserVersion.hasFeature(CSS_FONTFACERULE_CSSTEXT_CRLF)) { cssText = StringUtils.replace(cssText, "{", "{\r\n\t"); cssText = StringUtils.replace(cssText, "}", ";\r\n}\r\n"); cssText = StringUtils.replace(cssText, "; ", ";\r\n\t"); } else if (browserVersion.hasFeature(CSS_FONTFACERULE_CSSTEXT_NO_CRLF)) { cssText = StringUtils.replace(cssText, "{", "{ "); cssText = StringUtils.replace(cssText, "}", "; }"); cssText = StringUtils.replace(cssText, "; ", "; "); final Matcher matcher = REPLACEMENT_2.matcher(cssText); matcher.find(); final String url = matcher.group(1); final HtmlPage page = (HtmlPage) ((CSSStyleSheet) getParentScope()).getWindow().getWebWindow() .getEnclosedPage(); try { cssText = matcher.replaceFirst("src: url(" + page.getFullyQualifiedUrl(url) + ");"); } catch (final Exception e) { switch (url) { case "//:": cssText = matcher.replaceFirst("src: url(" + "http:///" + ");"); break; case "//": cssText = matcher.replaceFirst("src: url(" + "http:" + ");"); break; default: } } } else { cssText = StringUtils.replace(cssText, "{", "{\n "); cssText = StringUtils.replace(cssText, "}", ";\n}"); cssText = StringUtils.replace(cssText, "; ", ";\n "); cssText = REPLACEMENT_1.matcher(cssText).replaceFirst("font-family: \"$1\";"); cssText = REPLACEMENT_2.matcher(cssText).replaceFirst("src: url(\"$1\");"); } return cssText; }
From source file:com.opentangerine.clean.Replace.java
/** * Find specific pattern and replace with provided value. * * @param pattern Pattern that should be replaced. * @param value Value that should be used for replacement. * @return Replace object./* w w w. j a va2 s . c om*/ */ public Replace replace(final String pattern, final String value) { return this.replace(it -> it.contains(pattern), it -> StringUtils.replace(it, pattern, value)); }
From source file:mfi.staticresources.ProcessResources.java
private String replace(String content, String search, String replacement) { String compare;//from w w w.j a v a2 s . c o m do { compare = content; content = StringUtils.replace(content, search, replacement); } while (!compare.equals(content)); return content; }
From source file:com.gargoylesoftware.htmlunit.html.HtmlSerializer.java
protected String cleanUp(String text) { // ignore <br/> at the end of a block text = reduceWhitespace(text);// www. j ava 2 s .c om text = StringUtils.replace(text, AS_TEXT_BLANK, " "); final String ls = System.getProperty("line.separator"); text = StringUtils.replace(text, AS_TEXT_NEW_LINE, ls); // text = CLEAN_UP_PATTERN.matcher(text).replaceAll(ls); // many block sep => 1 new line text = StringUtils.replace(text, AS_TEXT_BLOCK_SEPARATOR, ls); text = StringUtils.replace(text, AS_TEXT_TAB, "\t"); return text; }
From source file:io.wcm.tooling.commons.contentpackagebuilder.ValueConverter.java
private String escapeSpecialCharsInArray(String value) { return StringUtils.replace(StringUtils.replace(value, "\\", "\\\\"), ",", "\\,"); }
From source file:io.wcm.maven.plugins.contentpackage.httpaction.PackageManagerHtmlMessageCall.java
@Override public String execute() throws MojoExecutionException { if (log.isDebugEnabled()) { log.debug("Call URL: " + method.getURI()); }/* w w w . j a va 2 s .c o m*/ try (CloseableHttpResponse response = httpClient.execute(method)) { String responseString = EntityUtils.toString(response.getEntity()); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // debug output whole xml if (log.isDebugEnabled()) { log.debug("CRX Package Manager Response:\n" + responseString); } // remove all HTML tags and special conctent final Pattern HTML_STYLE = Pattern.compile("<style[^<>]*>[^<>]*</style>", Pattern.MULTILINE | Pattern.DOTALL); final Pattern HTML_JAVASCRIPT = Pattern.compile("<script[^<>]*>[^<>]*</script>", Pattern.MULTILINE | Pattern.DOTALL); final Pattern HTML_ANYTAG = Pattern.compile("<[^<>]*>"); responseString = HTML_STYLE.matcher(responseString).replaceAll(""); responseString = HTML_JAVASCRIPT.matcher(responseString).replaceAll(""); responseString = HTML_ANYTAG.matcher(responseString).replaceAll(""); responseString = StringUtils.replace(responseString, " ", " "); return responseString; } else { throw new MojoExecutionException("Failure:\n" + responseString); } } catch (IOException ex) { throw new MojoExecutionException("Http method failed.", ex); } }
From source file:net.ontopia.topicmaps.nav2.impl.framework.ModelLinkGenerator.java
@Override public String generate(ContextTag contextTag, TopicMapReferenceIF tmRefObj, String template) throws NavigatorRuntimeException { String link = template;//ww w . j a v a2s . co m // replace topicmap id placeholder with real value if (tmRefObj != null) { String topicmapId = tmRefObj.getId(); link = StringUtils.replace(link, LINK_TOPICMAP_KEY, topicmapId); } // replace model placeholder with real value UserIF user = FrameworkUtils.getUser(contextTag.getPageContext()); String model = user.getModel(); link = StringUtils.replace(link, LINK_MODEL_KEY, model); return link; }
From source file:com.xpn.xwiki.plugin.ldap.LDAPPlugin.java
protected String getParam(String name, XWikiContext context) { String param = ""; try {// w w w . j ava 2 s. c om param = context.getWiki().getXWikiPreference(name, context); } catch (Exception e) { } if (param == null || "".equals(param)) { try { param = context.getWiki() .Param("xwiki.authentication." + StringUtils.replace(name, "ldap_", "ldap.")); } catch (Exception e) { } } if (param == null) param = ""; return param; }
From source file:com.enhype.photo.FlickrService.java
public List<String> getCCBySAPhotoFlickr(String query) { List<String> imgSrcs = new ArrayList<String>(); WebResource resource = Client.create().resource(RunConfig.FLICKR_SERVICE_ENDPOINT).path("services/rest/") .queryParam("method", photoSearchMethod).queryParam("api_key", key).queryParam("text", query) .queryParam("format", "json").queryParam("nojsoncallback", "1").queryParam("license", ccBySANonCom) .queryParam("sort", sortBYRelevance); ClientResponse response = null;//from w w w. j a v a 2 s . c o m logger.info(resource.toString()); try { response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); } catch (Exception e) { logger.error("Unable to connection to entity linking service", e); return null; } if (response.getStatus() >= 300) { logger.error(String.format("GET [%s], status code [%d]", resource.toString(), response.getStatus())); throw new UniformInterfaceException("Status code indicates request not expected", response); } String responseStr = response.getEntity(String.class); logger.info(responseStr); if (response != null) response.close(); JSONArray photos = (JSONArray) ((JSONObject) JSONObject.fromObject(responseStr).get("photos")).get("photo"); for (Object photoObj : photos) { JSONObject photo = (JSONObject) photoObj; Photo pho = new Photo(photo.getString("id"), photo.getString("owner"), photo.getString("secret"), photo.getString("server"), photo.getString("farm"), photo.getString("title")); imgSrcs.add(pho.getUrl()); String updateDBStr = "insert into pictures ( query , img_src , img_owner , img_title ) " + "values (" + "'" + StringUtils.replace(query, " ", "_") + "', " + "'" + pho.getUrl() + "', " + "'" + pho.getOwner() + "', " + "'" + StringUtils.replace(pho.getTitle(), "'", "''") + "' " + ");"; // DBBulkInserter dbInserter = new DBBulkInserter(); // dbInserter.addToQueryListOrExecute(updateDBStr); db.execUpdate(updateDBStr); } return imgSrcs; }