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:edu.usf.cutr.obascs.io.ConfigFileGenerator.java
public static String generateSampleRealTimeConfigFile(String configXml, Map<String, String> agencyMap) { StringBuilder bundleNamesBuilder = new StringBuilder(); for (Map.Entry<String, String> agency : agencyMap.entrySet()) { bundleNamesBuilder.append(// w w w . j a v a2 s . c o m "<bean class=\"org.onebusaway.transit_data_federation.impl.realtime.gtfs_realtime.GtfsRealtimeSource\">"); bundleNamesBuilder.append(SystemUtils.LINE_SEPARATOR); bundleNamesBuilder.append("<property name=\"tripUpdatesUrl\" value=\"") .append(GeneralConstants.SAMPLE_REALTIME_CONFIG_TRIP_UPDATES_URL); bundleNamesBuilder.append("\" />").append(SystemUtils.LINE_SEPARATOR); bundleNamesBuilder.append("<property name=\"vehiclePositionsUrl\" value=\"") .append(GeneralConstants.SAMPLE_REALTIME_CONFIG_VEHICLE_POS_URL); bundleNamesBuilder.append("\" />").append(SystemUtils.LINE_SEPARATOR); bundleNamesBuilder.append("<property name=\"alertsUrl\" value=\"") .append(GeneralConstants.SAMPLE_REALTIME_CONFIG_ALERTS_URL); bundleNamesBuilder.append("\" />").append(SystemUtils.LINE_SEPARATOR); bundleNamesBuilder.append("<property name=\"refreshInterval\" value=\"15\" />") .append(SystemUtils.LINE_SEPARATOR); bundleNamesBuilder.append("<property name=\"agencyIds\">").append(SystemUtils.LINE_SEPARATOR); bundleNamesBuilder.append("<list>").append(SystemUtils.LINE_SEPARATOR); bundleNamesBuilder.append("<value>").append(agency.getKey()).append("</value>") .append(SystemUtils.LINE_SEPARATOR); bundleNamesBuilder.append("</list>").append(SystemUtils.LINE_SEPARATOR); bundleNamesBuilder.append("</property>").append(SystemUtils.LINE_SEPARATOR); bundleNamesBuilder.append("</bean>").append(SystemUtils.LINE_SEPARATOR); } configXml = StringUtils.replace(configXml, "${beanNames}", bundleNamesBuilder.toString()); return configXml; }
From source file:de.micromata.genome.util.matcher.GroovyMatcherFactory.java
/** * Consume groovy exression./*from w ww. jav a2 s . c o m*/ * * @param tokens the tokens * @return the string */ protected String consumeGroovyExression(TokenResultList tokens) { String ret = consumeGroovyExressionInternal(tokens); ret = StringUtils.replace(ret, " or ", " || "); ret = StringUtils.replace(ret, " and ", " && "); return ret; }
From source file:com.sk89q.craftbook.sponge.util.ParsingUtil.java
public static void verifySignLocationSyntax(Sign sign, int i) throws CraftBookException { try {// ww w. ja va 2 s . com String line = SignUtil.getTextRaw(sign, i); String[] strings; line = StringUtils.replace(StringUtils.replace(StringUtils.replace(line, "!", ""), "^", ""), "&", ""); if (line.contains("=")) { String[] split = RegexUtil.EQUALS_PATTERN.split(line, 2); if (RegexUtil.COMMA_PATTERN.split(split[0]).length > 1) { String[] rads = RegexUtil.COMMA_PATTERN.split(split[0]); Double.parseDouble(rads[0]); Double.parseDouble(rads[1]); Double.parseDouble(rads[2]); } else Double.parseDouble(split[0]); strings = RegexUtil.COLON_PATTERN.split(split[1], 3); } else strings = RegexUtil.COLON_PATTERN.split(line); if (strings.length > 1) { Double.parseDouble(strings[1]); Double.parseDouble(strings[2]); } Double.parseDouble(strings[0]); } catch (Exception e) { throw new CraftBookException("Wrong syntax! Needs to be: radius=x:y:z or radius=y or y"); } }
From source file:goja.initialize.ctxbox.ClassSearcher.java
/** * @param baseDirName /*from w w w .j a v a 2 s . c o m*/ * @param targetFileName ??? */ private static List<String> findFiles(String baseDirName, String targetFileName, final String classpath) { /** * ????? * ???? ?????? */ List<String> classFiles = Lists.newArrayList(); File baseDir = new File(baseDirName); if (!baseDir.exists() || !baseDir.isDirectory()) { LOG.error("search error" + baseDirName + "is not a dir?"); } else { String[] files = baseDir.list(); File file; String fileName, open = classpath + File.separator, close = ".class"; int start, end; for (String file_path : files) { file = new File(baseDirName + File.separator + file_path); if (file.isDirectory()) { classFiles .addAll(findFiles(baseDirName + File.separator + file_path, targetFileName, classpath)); } else { if (wildcardMatch(targetFileName, file.getName())) { fileName = file.getAbsolutePath(); start = fileName.indexOf(open); end = fileName.indexOf(close, start + open.length()); // window ,? String className = StringUtils.replace(fileName.substring(start + open.length(), end), File.separator, "."); classFiles.add(className); } } } } return classFiles; }
From source file:com.gargoylesoftware.htmlunit.libraries.DojoTestBase.java
void test(final String module) throws Exception { try {/*ww w.ja v a2 s .c om*/ final WebDriver webdriver = getWebDriver(); final String url = "http://localhost:" + PORT + "/util/doh/runner.html?testModule=" + module; webdriver.get(url); final long runTime = 60 * DEFAULT_WAIT_TIME; final long endTime = System.currentTimeMillis() + runTime; // wait a bit to let the tests start Thread.sleep(DEFAULT_WAIT_TIME); String status = getResultElementText(webdriver); while (!"Stopped".equals(status)) { Thread.sleep(DEFAULT_WAIT_TIME); if (System.currentTimeMillis() > endTime) { fail("Test runs too long (longer than " + runTime / 1000 + "s)"); } status = getResultElementText(webdriver); } Thread.sleep(100); // to make tests a bit more stable final WebElement output = webdriver.findElement(By.id("logBody")); final List<WebElement> lines = output.findElements(By.xpath(".//div")); final StringBuilder result = new StringBuilder(); for (WebElement webElement : lines) { final String text = webElement.getText(); if (StringUtils.isNotBlank(text)) { result.append(text); result.append("\n"); } } String expFileName = StringUtils.replace(module, ".", ""); expFileName = StringUtils.replace(expFileName, "_", ""); String expected = loadExpectation(expFileName); expected = StringUtils.replace(expected, "\r\n", "\n"); assertEquals(normalize(expected), normalize(result.toString())); // assertEquals(expected, result.toString()); } catch (final Exception e) { e.printStackTrace(); Throwable t = e; while ((t = t.getCause()) != null) { t.printStackTrace(); } throw e; } }
From source file:com.xpn.xwiki.render.XWikiRadeoxRenderEngine.java
public String noaccents(String name) { return StringUtils.replace(Util.noaccents(name), " ", ""); }
From source file:com.tealcube.minecraft.bukkit.TextUtils.java
/** * Returns a colored copy of the passed-in String. * * @param pString/*from w ww. ja v a 2s. co m*/ * String to color * @return colored copy of passed-in String */ public static String color(String pString) { Validate.notNull(pString, "pString cannot be null"); String ret = pString; for (Map.Entry<String, ChatColor> entry : COLOR_MAP.entrySet()) { ret = StringUtils.replace(ret, entry.getKey(), entry.getValue() + ""); } return ret; }
From source file:annis.sqlgen.SqlConstraints.java
public static String sqlString(String string) { if (string == null) { return "''"; } else {/*from www. j a v a 2 s .com*/ return "'" + StringUtils.replace(string, "'", "''") + "'"; } }
From source file:com.monarchapis.driver.jaxrs.common.Swagger12DocumentationResource.java
/** * Returns the API declaration for a specific route/resources. * //from www. ja v a 2s . c o m * @param version * The version from the path * @param route * The route/resource * @param uriInfo * The URI info for determining the base URI * @return the API declaration JSON. */ @GET @Path("/{route: .+}") @Produces(MediaType.APPLICATION_JSON) public String getApiDeclaration(@PathParam("version") String version, @PathParam("route") String route, @Context UriInfo uriInfo) { try { InputStream is = getClass().getResourceAsStream(SWAGGER_DOC_ROOT + version + "/" + route + ".json"); if (is == null) { throw new NotFoundException(); } String json = IOUtils.toString(is); json = StringUtils.replace(json, "${apiBasePath}", getBaseUri(uriInfo)); json = insertEndpoints(json); return json; } catch (Exception e) { log.error("Could not get swagger documentation.", e); throw new NotFoundException(); } }
From source file:com.monarchapis.driver.jaxrs.common.Swagger12DocumentationResource.java
/** * Inserts the OAuth endpoints into the JSON place holders. * /* w w w. j av a 2 s . co m*/ * @param json * The JSON to alter * @return the new JSON with the OAuth endpoint place holders replaced. */ private static String insertEndpoints(String json) { OAuthEndpoints endpoints = ServiceResolver.getInstance().required(OAuthEndpoints.class); json = StringUtils.replace(json, "${oauthPasswordUrl}", endpoints.getPasswordUrl()); json = StringUtils.replace(json, "${oauthImplicitUrl}", endpoints.getImplicitUrl()); json = StringUtils.replace(json, "${oauthAuthorizationCodeRequestUrl}", endpoints.getAuthorizationCodeRequestUrl()); json = StringUtils.replace(json, "${oauthAuthorizationCodeTokenUrl}", endpoints.getAuthorizationCodeTokenUrl()); return json; }