List of usage examples for org.apache.commons.lang3 StringUtils replaceEach
public static String replaceEach(final String text, final String[] searchList, final String[] replacementList)
Replaces all occurrences of Strings within another String.
From source file:de.vandermeer.translation.characters.Html2AsciiDoc.java
@Override public String translateCharacters(String input) { return StringUtils.replaceEach(input, this.sourceArray, this.targetArray); }
From source file:nl.vpro.jcr.criteria.query.xpath.utils.XPathTextUtils.java
/** * Convert a string to a JCR search expression literal, suitable for use in jcr:contains() (inside XPath queries). * The characters - and " have special meaning, and may be escaped with a backslash to obtain their literal value. * See JSR-170 spec v1.0, Sec. 6.6.5.2./*from w ww. j a va 2 s. c o m*/ * @param str Any string. * @return A valid XPath 2.0 string literal suitable for use in jcr:contains(), including enclosing quotes. */ public static String stringToJCRSearchExp(String str) { if (StringUtils.isEmpty(str)) { return str; } String parseString = StringUtils.trimToEmpty(str); // workaround for https://issues.apache.org/jira/browse/JCR-2732 parseString = StringUtils.replaceEach(parseString, new String[] { ":)", ":(" }, new String[] { ": )", ": (" }); /* * http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Escaping%20Special%20Characters * http://www.javalobby.org/java/forums/t86124.html */ String escapeChars = "[\\\\+\\-\\!\\(\\)\\:\\^\\]\\{\\}\\~\\*\\?\"\\[\\]|]"; parseString = parseString.replaceAll(escapeChars, "\\\\$0"); parseString = parseString.replaceAll("\'", "\'\'"); // workaround for https://issues.apache.org/jira/browse/JCR-2733 if (StringUtils.startsWith(parseString, "OR ")) { parseString = parseString.replaceFirst("\\bOR\\b", "\"OR\""); } return parseString; }
From source file:org.apache.fineract.infrastructure.dataexport.helper.DataExportUtils.java
/** * Search and replace string using the searchList string array and replacementList string array * /*w w w . java 2 s.c o m*/ * @param string * @param searchList * @param replacementList * @return replacement string for the specified string */ public static String searchAndReplaceString(final String string, final String[] searchList, final String[] replacementList) { // replace all occurrences of the strings the "searchList" array with // their corresponding string in the "replacementList" array final String replacementString = StringUtils.replaceEach(string, searchList, replacementList); // finally, trim the string return StringUtils.trim(replacementString); }
From source file:org.diorite.cfg.messages.DioriteMessages.java
/** * Returns messages for given plugin, may return null if plugin don't use diorite message system. :( * * @param plugin plugin to get messages. * * @return messages for given plugin or null. *//* w w w . j a va 2 s .c o m*/ public static Messages getPluginMessages(final BasePlugin plugin) { return getMessages("plugins" + getNodeSeparator() + StringUtils.replaceEach(plugin.getName(), new String[] { Character.toString(getNodeSeparator()), ChildPlugin.CHILD_SEPARATOR }, new String[] { "_", getNodeSeparator() + "plugins" + getNodeSeparator() })); }
From source file:org.diorite.cfg.messages.PluginMessages.java
/** * Returns messages for given plugin, may return null if plugin don't use diorite message system. :( * * @param plugin plugin to get messages. * * @return messages for given plugin or null. *///from w w w. j a v a 2 s.c o m public Messages getSubPluginMesssages(final ChildPlugin plugin) { return this.getMessages(StringUtils.replaceEach(plugin.getName(), new String[] { Character.toString(this.getNodeSeparator()), ChildPlugin.CHILD_SEPARATOR }, new String[] { "_", this.getNodeSeparator() + "plugins" + this.getNodeSeparator() })); }
From source file:org.diorite.cfg.system.elements.StringTemplateElement.java
@Override public void appendValue(final Appendable writer, final CfgEntryData field, final Object source, final Object elementRaw, final int level, final ElementPlace elementPlace) throws IOException { StringStyle style = field.getOption(FieldOptions.STRING_STYLE, StringStyle.DEFAULT); if ((style == StringStyle.ALWAYS_MULTI_LINE) && (elementPlace == ElementPlace.SIMPLE_LIST_OR_MAP)) // multi line strings don't works in simple lists/maps. {/*ww w. j a va2 s . co m*/ style = StringStyle.DEFAULT; } final String element = Enum.class.isAssignableFrom(elementRaw.getClass()) ? ((Enum<?>) elementRaw).name() : elementRaw.toString(); switch (style) { case ALWAYS_QUOTED: { writeQuoted(writer, element); break; } case ALWAYS_SINGLE_QUOTED: { writeSingleQuoted(writer, StringUtils.replaceEach(element, REP_PREV_1, REP_PREV_2)); break; } case ALWAYS_MULTI_LINE: { writeMultiLine(writer, element, level, elementPlace); break; } default: { final boolean haveNewLines = StringUtils.contains(element, '\n'); if ((elementPlace != ElementPlace.SIMPLE_LIST_OR_MAP) && haveNewLines) { writeMultiLine(writer, element, level, elementPlace); return; } boolean needQuote = false; if (element.isEmpty()) { writeSingleQuoted(writer, element); return; } final char f = element.charAt(0); if (StringUtils.containsAny(element, ':', '#')) { needQuote = true; } else { for (final char c : CANT_BE_FIRST) { if (c == f) { needQuote = true; break; } } } if (needQuote) { writeQuoted(writer, element); return; } if (StringUtils.isNumeric(element)) { writeQuoted(writer, element); } else { writer.append(StringUtils.replace(element, "\n", "\\n")); } break; } } }
From source file:org.diorite.cfg.system.elements.StringTemplateElement.java
private static void writeQuoted(final Appendable writer, final String element) throws IOException { writer.append('\"'); writer.append(StringUtils.replaceEach(element, REP_LAST_1, REP_LAST_2)); writer.append('\"'); }
From source file:org.diorite.impl.plugin.PluginDataImpl.java
public PluginDataImpl(final Plugin plugin) { this.name = plugin.name(); this.version = plugin.version(); this.prefix = StringUtils.replaceEach(plugin.prefix(), new String[] { "%name%", "%version%" }, new String[] { this.name, this.version }); this.author = plugin.author(); this.description = plugin.description(); this.website = plugin.website(); }
From source file:org.diorite.impl.plugin.PluginDataImpl.java
public PluginDataImpl(final PluginDataBuilder builder) { this.name = builder.getName(); this.version = builder.getVersion(); this.prefix = StringUtils.replaceEach(builder.getPrefix(), new String[] { "%name%", "%version%" }, new String[] { this.name, this.version }); this.author = builder.getAuthor(); this.description = builder.getDescription(); this.website = builder.getWebsite(); }
From source file:org.diorite.impl.plugin.PluginDataImpl.java
public PluginDataImpl(final String name, final String version, final String prefix, final String author, final String description, final String website) { Validate.notNull(name, "name can't be null!"); this.name = name; this.version = (version == null) ? "unknown" : version; this.author = (author == null) ? "unknown" : author; this.prefix = (prefix == null) ? (this.name + " v" + this.version) : StringUtils.replaceEach(prefix, new String[] { "%name%", "%version%" }, new String[] { this.name, this.version }); this.description = (description == null) ? "" : description; this.website = (website == null) ? "" : website; }