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:org.efaps.db.databases.AbstractDatabase.java
/** * @param _value value to be prepared for use in a match * @return string prepared for match/*from w w w .j a v a 2 s .c om*/ */ public String prepare4Match(final String _value) { // Remove double escapes String ret = StringUtils.replace(_value, "\\\\", "\\"); // escape '%' percent and '_' underscore ret = StringUtils.replace(ret, "%", "\\%"); ret = StringUtils.replace(ret, "_", "\\_"); // replace any '*' that is not escaped by a '\' ret = ret.replaceAll("(?<!\\\\)\\" + AbstractDatabase.WILDCARDPATTERN, "%"); // remove the escapecharacter from the '\*' and replace with a simple '*' ret = ret.replaceAll("(?>\\\\)\\" + AbstractDatabase.WILDCARDPATTERN, AbstractDatabase.WILDCARDPATTERN); // replace any '?' that is not escaped by a '_' ret = ret.replaceAll("(?<!\\\\)\\" + AbstractDatabase.SINGLECHARACTERPATTERN, "_"); // remove the escapecharacter from the '\?' and replace with a simple '?' ret = ret.replaceAll("(?>\\\\)\\" + AbstractDatabase.SINGLECHARACTERPATTERN, AbstractDatabase.SINGLECHARACTERPATTERN); return ret; }
From source file:org.emau.icmvc.ganimed.deduplication.impl.CommonPreprocessor.java
/** * /*from w ww . jav a2 s. c om*/ * @param processable * @param transformationConfig * @param propertyName * @return * @throws DeduplicationException */ protected <V> String performSimpleTransformation(V processable, SimpleTransformation transformationConfig, String propertyName) throws DeduplicationException { try { String inputPattern = transformationConfig.getInputPattern(); String outputPattern = transformationConfig.getOutputPattern(); String propertyValue = (String) ReflectionUtil.getProperty(processable, propertyName); String newValue = propertyValue; if (propertyValue != null) { if (outputPattern != null) { // standard string replacement newValue = StringUtils.replace(propertyValue, inputPattern, outputPattern); } } return newValue; } catch (Exception e) { throw new DeduplicationException(e.getLocalizedMessage(), e); } }
From source file:org.emau.icmvc.ganimed.deduplication.preprocessing.impl.CharsMutationTransformation.java
@Override public String transform(String fieldName, String value) { String newValue = value;/*from ww w. ja va2 s . co m*/ if (value != null) { newValue = StringUtils.replace(newValue, "", "UE"); newValue = StringUtils.replace(newValue, "", "AE"); newValue = StringUtils.replace(newValue, "", "OE"); } else { logger.warn(String.format("Value for property %s is null.", fieldName)); } return newValue; }
From source file:org.emau.icmvc.ganimed.deduplication.preprocessing.impl.UniversalStringTransformation.java
/** * The method normalizes spaces, turns the string to uppercase representation * and normalizes hyphens/*from www . j av a2 s. c o m*/ * @param input * @return */ public String normalize(String input) { // normalize spaces input = StringUtils.normalizeSpace(input); input = StringUtils.replace(input, "-", " - "); input = StringUtils.replace(input, " - ", "-"); input = StringUtils.capitalize(input); return input; }
From source file:org.geoserver.test.onlineTest.StationsMappingsSetup.java
public void setupMapping(String solrUrl, String solrCoreName, PostgresqlProperties pgProps, File testDir) { // replace mappings.xml placeholders String mappingsContent = loadFileAsString("test-data/" + MAPPING_FILE_NAME); mappingsContent = StringUtils.replace(mappingsContent, "${solr_url}", solrUrl); mappingsContent = StringUtils.replace(mappingsContent, "${solr_core}", solrCoreName); mappingsContent = replacePgPlaceholders(mappingsContent, pgProps); // replace includedTypes.xml placeholders String includedContent = loadFileAsString("test-data/" + INCLUDED_FILE_NAME); includedContent = replacePgPlaceholders(includedContent, pgProps); try {/*from ww w .j a v a 2 s. c o m*/ // save as mappings.xml final file Path path = Paths.get(testDir.getAbsolutePath(), MAPPING_FILE_NAME); Files.write(path, mappingsContent.getBytes()); // save as includedTypes.xml final file Path itpath = Paths.get(testDir.getAbsolutePath(), INCLUDED_FILE_NAME); Files.write(itpath, includedContent.getBytes()); // create app-schema-cache directory Path dirpath = Paths.get(testDir.getAbsolutePath(), "app-schema-cache"); Files.createDirectories(dirpath); copyRelatedFiles(testDir.getAbsolutePath()); } catch (IOException e) { throw new RuntimeException(e); } }