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:io.gs2.AbstractGs2Client.java
/** * POST?//from ww w . j a v a2 s .c om * * @param url URL * @param credential ? * @param service * @param module * @param function * @param body * @return */ protected HttpPost createHttpPost(String url, IGs2Credential credential, String service, String module, String function, String body) { Long timestamp = System.currentTimeMillis() / 1000; url = StringUtils.replace(url, "{service}", service); url = StringUtils.replace(url, "{region}", region.getName()); HttpPost post = new HttpPost(url); post.setHeader("Content-Type", "application/json"); credential.authorized(post, service, module, function, timestamp); post.setEntity(new StringEntity(body, "UTF-8")); return post; }
From source file:com.github.benmanes.caffeine.cache.simulator.parser.wikipedia.WikipediaTraceReader.java
/** Returns the path segment of the URL. */ private String getPath(String url) { int index = url.indexOf('/', 7); if (index == -1) { return url; }//from w w w .j a v a 2 s . c om String path = url.substring(index + 1); // Replace the html entities that we want to search for inside paths String cleansed = path; for (int i = 0; i < SEARCH_LIST.length; i++) { cleansed = StringUtils.replace(cleansed, SEARCH_LIST[i], REPLACEMENT_LIST[i]); } return cleansed; }
From source file:io.wcm.handler.url.impl.Externalizer.java
/** * Externalizes an URL without applying Sling Mapping. Instead the servlet context path is added and sling namespace * mangling is applied manually./*w w w . j a va 2 s. c o m*/ * Hostname and scheme are not added because they are added by the link handler depending on site URL configuration * and secure/non-secure mode. URLs that are already externalized remain untouched. * @param url Unexternalized URL (without scheme or hostname) * @param request Request * @return Exernalized URL without scheme or hostname, the path is URL-encoded if it contains special chars. */ public static String externalizeUrlWithoutMapping(String url, SlingHttpServletRequest request) { // apply externalization only path part String path = url; // split off query string or fragment that may be appended to the URL String urlRemainder = null; int urlRemainderPos = StringUtils.indexOfAny(path, '?', '#'); if (urlRemainderPos >= 0) { urlRemainder = path.substring(urlRemainderPos); path = path.substring(0, urlRemainderPos); } // apply namespace mangling (e.g. replace jcr: with _jcr_) path = mangleNamespaces(path); // add webapp context path if (request != null) { path = StringUtils.defaultString(request.getContextPath()) + path; //NOPMD } // url-encode path path = Escape.urlEncode(path); path = StringUtils.replace(path, "+", "%20"); // replace %2F back to / for better readability path = StringUtils.replace(path, "%2F", "/"); // build full URL again return path + (urlRemainder != null ? urlRemainder : ""); }
From source file:com.xpn.xwiki.objects.classes.ListClass.java
public static List<String> getListFromString(String value, String separators, boolean withMap) { List<String> list = new ArrayList<String>(); if (value == null) { return list; }//www.j ava 2s .co m if (separators == null) { separators = "|"; } String val = value; if (separators.length() == 1) { val = StringUtils.replace(val, "\\" + separators, "%PIPE%"); } String[] result = StringUtils.split(val, separators); String item = ""; for (int i = 0; i < result.length; i++) { String element = StringUtils.replace(result[i], "%PIPE%", separators); if (withMap && (element.indexOf('=') != -1)) { item = StringUtils.split(element, "=")[0]; } else { item = element; } if (!item.trim().equals("")) { list.add(item); } } return list; }
From source file:com.thruzero.common.web.filter.InitFilter.java
@Override @ConfigBookmark(comment = "initialize config") public void init(FilterConfig config) throws ServletException { String configFilePath = config .getInitParameter(InitFilterInitParameterWebXmlKeys.CONFIG_FILE_PATH_INIT_PARAM); // get config file path from web.xml init-param String configFileEnvironmentVar = config .getInitParameter(InitFilterInitParameterWebXmlKeys.CONFIG_FILE_PATH_ENV_VAR_NAME_INIT_PARAM); // get config file environment var name from web.xml init-param if (StringUtils.isNotEmpty(configFileEnvironmentVar)) { String configDirPath = System.getenv(configFileEnvironmentVar); // if env var set for config home, then attempt to substitute if (StringUtils.isEmpty(configDirPath)) { logger.error("*** ERROR *** ENVIRONMENT VAR NAME '" + configFileEnvironmentVar + "' WAS PROVIDED, but no value was found."); } else {//from ww w .j av a 2 s .com configFilePath = StringUtils.replace(configFilePath, "${" + configFileEnvironmentVar + "}", configDirPath); } } // init config ConfigLocator.setup(configFilePath, null); // TODO-p1(george) add config implementation name as an option to web.xml }
From source file:net.ontopia.xml.CanonicalPrinter.java
public String escape(String attrval) { return StringUtils.replace(StringUtils.replace(StringUtils.replace(attrval, "&", "&"), "<", "<"), "\"", """); }
From source file:de.micromata.genome.gwiki.page.impl.GWikiWikiPageEditorArtefakt.java
@Override public boolean renderWithParts(GWikiContext ctx) { String thisPageId = null;/*ww w . j a v a 2 s . c o m*/ if (editBean.isNewPage() == false) { thisPageId = editBean.getPageId(); } String pn = partName; String html; if (useDivEditor == true) { String text = textPage.getStorageData(); text = StringEscapeUtils.escapeXml(text); text = StringUtils.replace(text, "\n", "<br/>\n"); html = Html.div( Xml.attrs("id", "textarea" + partName, "class", "wikiEditorTextArea", "contenteditable", "true", "style", "width:100%;height:100%"), // Xml.code(text)).toString(); } else { html = Html.textarea( Xml.attrs("id", "textarea" + partName, "class", "wikiEditorTextArea", "rows", "30", "cols", "100", "name", partName + ".wikiText", "style", "width:100%;height:100%"), // Xml.text(textPage.getStorageData())).toString(); } String tabs = "<div id=\"gwikiWikiEditorFrame" + pn + "\" style=\"width: 100%; height: 100%\">" + "<div id='gwikiwktabs" + pn + "'>" + "<ul><li><a href='#WikiEdit" + pn + "'><span>Wiki</span></a></li><li>" + "<a href='#WikiRte" + pn + "'><span>Rich Text</span></a></li><li><a href='#WikiPreview" + pn + "'><span>Preview</span></a></li></ul>" + "<div id='WikiEdit" + pn + "'>" + html + "</div>" + "<div id='WikiRte" + pn + "'></div>" + "<div id='WikiPreview" + pn + "' style=\"width: 100%; height: 100%; overflow: scroll;\">" // overflow: scroll; + "</div>" + "</div>" + "</div>"; ctx.append(tabs); ctx.append("<script type=\"text/javascript\">\n", "jQuery(document).ready(function(){\n" + " jQuery(\"#textarea" + pn + "\").gwikiedit({\n", "linkAutoCompleteUrl: '", ctx.localUrl("edit/PageSuggestions"), "', partName: '", partName, "' "); if (thisPageId != null) { ctx.append(", parentPageId: '", thisPageId, "'"); } ctx.append("});\n" + " gwikicreateEditTab('" + partName + "'); } );\n"); ctx.append("saveHandlers.push(function(){\n")// .append(" gwikiRestoreFromRte(gwikiCurrentPart);\n ")// .append(" gwikiUnsetContentChanged();\n")// .append("});\n"); ctx.append("</script>"); return true; }
From source file:com.gargoylesoftware.htmlunit.libraries.MochiKitTest.java
private void doTest(final String testName) throws Exception { final String url = "http://localhost:" + PORT + "/tests/test_MochiKit-" + testName + ".html"; assertNotNull(url);/* w w w.j a va2 s. c om*/ final WebDriver driver = getWebDriver(); driver.get(url); // make single test results visible driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.findElement(By.linkText("Toggle passed tests")).click(); driver.findElement(By.linkText("Toggle failed tests")).click(); driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); String expected = loadExpectation(testName); expected = expected.trim(); expected = StringUtils.replace(expected, "\r\n", "\n"); final WebElement div = driver.findElement(By.xpath("//div[@class = 'tests_report']")); assertNotNull(div); String actual = div.getText().trim(); actual = StringUtils.replace(actual, "\n\n", "\n"); assertEquals(expected.trim(), actual); }
From source file:com.mirth.connect.plugins.datatypes.ncpdp.NCPDPSerializer.java
@Override public String transformWithoutSerializing(String message, MessageSerializer outboundSerializer) throws MessageSerializerException { try {// ww w . j a v a 2s. c o m boolean transformed = false; NCPDPSerializer serializer = (NCPDPSerializer) outboundSerializer; String outputSegmentDelimiter = serializer.getDeserializationSegmentDelimiter(); String outputGroupDelimiter = serializer.getDeserializationGroupDelimiter(); String outputFieldDelimiter = serializer.getDeserializationFieldDelimiter(); if (!serializationSegmentDelimiter.equals(outputSegmentDelimiter)) { message = StringUtils.replace(message, serializationSegmentDelimiter, outputSegmentDelimiter); transformed = true; } if (!serializationGroupDelimiter.equals(outputGroupDelimiter)) { message = StringUtils.replace(message, serializationGroupDelimiter, outputGroupDelimiter); transformed = true; } if (!serializationFieldDelimiter.equals(outputFieldDelimiter)) { message = StringUtils.replace(message, serializationFieldDelimiter, outputFieldDelimiter); transformed = true; } if (transformed) { return message; } } catch (Exception e) { throw new MessageSerializerException("Error transforming NCPDP", e, ErrorMessageBuilder .buildErrorMessage(this.getClass().getSimpleName(), "Error transforming NCPDP", e)); } return null; }
From source file:com.xpn.xwiki.render.macro.XWikiCodeMacro.java
public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException { // We need to escape any HTML tag before we execute the macro. This is because the macro // generates HTML itself and we must only escape the HTML that was there before the // generation. String content = params.getContent(); content = StringUtils.replace(content, "<", "<"); content = StringUtils.replace(content, ">", ">"); params.setContent(content);//from www . j ava 2 s. c om super.execute(writer, params); return; }