List of usage examples for org.apache.commons.lang StringUtils replaceEachRepeatedly
public static String replaceEachRepeatedly(String text, String[] searchList, String[] replacementList)
Replaces all occurrences of Strings within another String.
From source file:org.jahia.modules.gateway.admin.forms.MailStartPointFormHandlerImpl.java
public static String buildUri(Map<String, String> parameters) { String protocol = StringUtils.defaultIfEmpty(parameters.get("protocol"), "imap"); String host = StringUtils.defaultIfEmpty(parameters.get("host"), "imap.gmail.com"); if ("imap.gmail.com".equals(host)) { protocol = "imaps"; }/*from w ww .j ava2s. c om*/ String port = StringUtils.defaultIfEmpty(parameters.get("port"), ""); if (port.length() > 0) { port = ":" + port; } String username = StringUtils.defaultString(parameters.get("username")); String delay = StringUtils.defaultIfEmpty(parameters.get("delay"), "60000"); String delete = StringUtils.defaultString(parameters.get("delete"), "false"); return StringUtils.replaceEachRepeatedly(URI_TEMPLATE, new String[] { "${protocol}", "${host}", "${port}", "${username}", "${delay}", "${delete}" }, new String[] { protocol, host, port, username, delay, delete }); }
From source file:org.jspringbot.keyword.string.ReplaceVariable.java
public Object execute(Object[] params) { String str = String.valueOf(params[0]); String var = String.valueOf(params[1]); String replacement = String.valueOf(params[2]); return StringUtils.replaceEachRepeatedly(str, new String[] { "${" + var + "}" }, new String[] { replacement }); }
From source file:org.openhab.binding.mqtt.internal.AbstractMqttMessagePubSub.java
/** * Split the given string into a string array using ':' as the separator. If * the separator is escaped like '\:', the separator is ignored. * // www .j a v a 2s . c o m * @param configString * @return configString split into array. */ protected String[] splitConfigurationString(String configString) { if (StringUtils.isEmpty(configString)) { return new String[0]; } String[] result = StringUtils.replaceEachRepeatedly(configString, new String[] { "\\:" }, new String[] { TEMP_COLON_REPLACEMENT }).split(":"); for (int i = 0; i < result.length; i++) { result[i] = StringUtils.replaceEachRepeatedly(result[i], new String[] { TEMP_COLON_REPLACEMENT }, new String[] { ":" }); } return result; }
From source file:org.tec.webapp.jdbc.entity.support.PreparedStatementBuilder.java
/** * Set a prepared statement field based on type * * @param stmt PrepapredStatement//from www . j a v a2s.com * @param index index of the parameter in the stmt * @param param the param value and metadata */ protected void setParameter(PreparedStatement stmt, int index, Parameter param) { try { if (param.getData() == null) { stmt.setNull(index, param.getType().getVendorTypeNumber()); } else { switch (param.getType()) { case BOOLEAN: stmt.setBoolean(index, (Boolean) param.getData()); break; case DATE: /* * java.sql.Date date = TextHelper.parseDate(param.getData()); if * (null == date) { throw new * SQLException("failed to set parameter: stmt=" + stmt + " index=" * + index + " param=" + param); } stmt.setDate(index, date); */ break; case TIME: /* * Time time = TextHelper.parseTime(param.getData()); if (null == * time) { throw new SQLException("failed to set parameter: stmt=" + * stmt + " index=" + index + " param=" + param); } * stmt.setTime(index, time); */ break; case TIMESTAMP: /* * Timestamp ts = TextHelper.parseTimestamp(param.getData()); if * (null == ts) { throw new * SQLException("failed to set parameter: stmt=" + stmt + " index=" * + index + " param=" + param); } stmt.setTimestamp(index, ts); */ break; case INTEGER: if (param.getData() instanceof Long) { Long l = (Long) param.getData(); stmt.setLong(index, l); } else { Integer i = (Integer) param.getData(); stmt.setInt(index, i); } break; case FLOAT: Float f = (Float) param.getData(); stmt.setFloat(index, f); break; default: // set string for non explicit types String tmp = StringUtils.replaceEachRepeatedly((String) param.getData(), INVALID_TEXT_CHARS, CORRECT_TEXT_CHARS); stmt.setString(index, tmp); break; } } } catch (Throwable e) { throw new RuntimeException("failed to process parameter " + param, e); } }