Java Code Examples for org.apache.commons.lang3.StringUtils#replaceEach()

The following examples show how to use org.apache.commons.lang3.StringUtils#replaceEach() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static String normalizeNumber(String decimalSeparator, String groupingSeparator, String numberString) {
	if (StringUtils.isBlank(numberString)) {
		return "";
	} else {
		decimalSeparator = StringUtils.defaultIfEmpty(decimalSeparator, DEFAULT_DECIMAL_SEPARATOR);
		groupingSeparator = StringUtils.defaultIfEmpty(groupingSeparator, DEFAULT_GROUPING_SEPARATOR);

		String result;
		if (StringUtils.equals(decimalSeparator, ".")) {
			result = StringUtils.replaceEach(numberString, new String[] { groupingSeparator, " " }, new String[] { "", "" });
		} else {
			result = StringUtils.replaceEach(numberString, new String[] { decimalSeparator, groupingSeparator, " " }, new String[] { ".", "", "" });
		}
		return StringUtils.trimToEmpty(result);
	}
}
 
Example 2
Source Project: htmlunit   File: ErrorOutputChecker.java    License: Apache License 2.0 6 votes vote down vote up
private void verifyNoOutput() {
    if (baos_.size() != 0) {
        String output = baos_.toString();

        // remove webdriver messages
        for (Pattern pattern : PATTERNS) {
            output = pattern.matcher(output).replaceAll("");
        }

        if (!output.isEmpty()) {
            if (output.contains("ChromeDriver")) {
                throw new RuntimeException("Outdated Chrome driver version: " + output);
            }
            if (output.contains("geckodriver")) {
                throw new RuntimeException("Outdated Gecko driver version: " + output);
            }
            output = StringUtils.replaceEach(output, new String[] {"\n", "\r"}, new String[]{"\\n", "\\r"});
            throw new RuntimeException("Test has produced output to System.err: " + output);
        }
    }
}
 
Example 3
Source Project: hugegraph-loader   File: ElementBuilder.java    License: Apache License 2.0 6 votes vote down vote up
private String spliceVertexId(VertexLabel vertexLabel,
                              Object... primaryValues) {
    StringBuilder vertexId = new StringBuilder();
    StringBuilder vertexKeysId = new StringBuilder();
    for (int i = 0; i < primaryValues.length; i++) {
        Object value = primaryValues[i];
        String pkValue;
        if (value instanceof Number || value instanceof Date) {
            pkValue = LongEncoding.encodeNumber(value);
        } else {
            pkValue = String.valueOf(value);
        }
        if (StringUtils.containsAny(pkValue, Constants.SEARCH_LIST)) {
            pkValue = StringUtils.replaceEach(pkValue,
                                              Constants.SEARCH_LIST,
                                              Constants.TARGET_LIST);
        }
        vertexKeysId.append(pkValue);
        vertexKeysId.append("!");
    }

    vertexId.append(vertexLabel.id()).append(":").append(vertexKeysId);
    vertexId.deleteCharAt(vertexId.length() - 1);
    return vertexId.toString();
}
 
Example 4
Source Project: attic-apex-malhar   File: PojoUtils.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("StringEquality")
private static Object createSetter(Class<?> pojoClass, String setterExpr, String exprObjectPlaceholder, String exprValPlaceholder, Class<?> exprClass, Class<?> setterClass)
{
  if (setterExpr.startsWith(".")) {
    setterExpr = setterExpr.substring(1);
  }

  if (setterExpr.isEmpty()) {
    throw new IllegalArgumentException("The setter expression: \"" + setterExpr + "\" is invalid.");
  }

  logger.debug("{} {} {} {}", pojoClass, setterExpr, exprClass, setterClass);



  String code = StringUtils.replaceEach(setterExpr, new String[]{exprObjectPlaceholder, exprValPlaceholder},
      new String[]{new JavaStatement().appendCastToTypeExpr(pojoClass, OBJECT).toString(), new JavaStatement().appendCastToTypeExpr(exprClass, VAL).toString()});
  if (code != setterExpr) {
    code = new JavaStatement(code.length() + 1).append(code).getStatement();
    logger.debug("Original expression {} is a complex expression. Replacing it with {}.", setterExpr, code);
  } else {
    code = getSingleFieldSetterExpression(pojoClass, setterExpr, exprClass);
  }

  return compileExpression(code, setterClass, new String[] {PojoUtils.OBJECT, PojoUtils.VAL});
}
 
Example 5
Source Project: dsworkbench   File: SosListFormatter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String formatElements(List<SOSRequest> pElements, boolean pExtended) {
    StringBuilder b = new StringBuilder();
    int cnt = 1;
    NumberFormat f = getNumberFormatter(pElements.size());
    String beforeList = getHeader();
    String listItemTemplate = getLineTemplate();
    String afterList = getFooter();
    String replacedStart = StringUtils.replaceEach(beforeList, new String[] {ELEMENT_COUNT}, new String[] {f.format(pElements.size())});
    b.append(replacedStart);
    for (SOSRequest s : pElements) {
        for(Village target: s.getTargets()) {
            String[] replacements = s.getReplacementsForTarget(target, pExtended);
            String itemLine = StringUtils.replaceEach(listItemTemplate, s.getBBVariables(), replacements);
            itemLine = StringUtils.replaceEach(itemLine, new String[] {ELEMENT_ID, ELEMENT_COUNT}, new String[] {f.format(cnt), f.format(pElements.size())});
            b.append(itemLine).append("\n").append("\n");
        }
        cnt++;
    }
    String replacedEnd = StringUtils.replaceEach(afterList, new String[] {ELEMENT_COUNT}, new String[] {f.format(pElements.size())});
    b.append(replacedEnd);
    return b.toString();
}
 
Example 6
Source Project: netty-cookbook   File: NettyHttpUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getRefererUrl(HttpHeaders headers){
	String refererUrl = headers.get(REFERER);
	if(StringUtil.isNotEmpty(refererUrl)){
		refererUrl = StringUtils.replaceEach(refererUrl, REFERER_SEARCH_LIST,  REFERER_REPLACE_LIST);
	}
	return refererUrl;
}
 
Example 7
Source Project: dsworkbench   File: BasicFormatter.java    License: Apache License 2.0 5 votes vote down vote up
protected void formatElementsCore(final StringBuilder builder, final Collection<C> elems, final boolean pExtended, final String listItemTemplate, final NumberFormat format) {
    int cnt = 1;
    for (C n : elems) {
        String[] replacements = n.getReplacements(pExtended);
        String itemLine = StringUtils.replaceEach(listItemTemplate, n.getBBVariables(), replacements);
        itemLine = StringUtils.replaceEach(itemLine, new String[] {ELEMENT_ID, ELEMENT_COUNT}, new String[] {format.format(cnt), format.format(elems.size())});
        builder.append(itemLine).append("\n");
        cnt++;
    }
}
 
Example 8
Source Project: netty-cookbook   File: NettyHttpUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getRefererUrl(HttpHeaders headers){
	String refererUrl = headers.get(REFERER);
	if(StringUtil.isNotEmpty(refererUrl)){
		refererUrl = StringUtils.replaceEach(refererUrl, REFERER_SEARCH_LIST,  REFERER_REPLACE_LIST);
	}
	return refererUrl;
}
 
Example 9
public static String encode(final String p) {
    try {
        final StringBuilder b = new StringBuilder();
        if(StringUtils.startsWith(p, String.valueOf(Path.DELIMITER))) {
            b.append(Path.DELIMITER);
        }
        b.append(URLEncoder.encode(p, StandardCharsets.UTF_8.name()));
        return StringUtils.replaceEach(b.toString(),
            new String[]{"+", "*", "%7E", "%40"},
            new String[]{"%20", "%2A", "~", "@"});
    }
    catch(UnsupportedEncodingException e) {
        return p;
    }
}
 
Example 10
@Override
public String formatElements(List<Stats> pElements, boolean pExtended) {
    StringBuilder b = new StringBuilder();
    String template = getTemplate();
    String[] replacements = getStatSpecificReplacements(pElements, pExtended);
    template = StringUtils.replaceEach(template, getTemplateVariables(), replacements);
    b.append(template);
    return b.toString();
}
 
Example 11
/**
 * @param wildcard Pattern
 * @param hostname Server
 * @return True if hostname matches wildcard
 */
protected boolean matches(final String wildcard, final String hostname) {
    final String host = StringUtils.replaceEach(wildcard, new String[]{"*", "?"}, new String[]{".*", "."});
    final String regex = String.format("^%s$", host);
    try {
        return hostname.matches(regex);
    }
    catch(PatternSyntaxException e) {
        log.warn("Failed converting wildcard to regular expression:" + e.getMessage());
    }
    return false;
}
 
Example 12
Source Project: DDMQ   File: MetricReporter.java    License: Apache License 2.0 4 votes vote down vote up
public static String trimTag(String tag) {
    if (StringUtils.isEmpty(tag)) {
        return "null";
    }
    return StringUtils.replaceEach(tag, TRIM_KEYS, TRIM_VALUES);
}
 
Example 13
Source Project: jinjava   File: EscapeFilter.java    License: Apache License 2.0 4 votes vote down vote up
public static String escapeHtmlEntities(String input) {
  return StringUtils.replaceEach(input, TO_REPLACE, REPLACE_WITH);
}
 
Example 14
Source Project: jinjava   File: EscapeJinjavaFilter.java    License: Apache License 2.0 4 votes vote down vote up
public static String escapeJinjavaEntities(String input) {
  return StringUtils.replaceEach(input, TO_REPLACE, REPLACE_WITH);
}
 
Example 15
public static String getFilename(String name) {
  return StringUtils.replaceEach(name, FILENAME_SEARCH_LIST, FILENAME_REPLACEMENT_LIST);
}
 
Example 16
private List<ReadCompleted> list(EffectivePerson effectivePerson, Business business, Integer adjustPage,
		Integer adjustPageSize, Wi wi) throws Exception {
	EntityManager em = business.entityManagerContainer().get(ReadCompleted.class);
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<ReadCompleted> cq = cb.createQuery(ReadCompleted.class);
	Root<ReadCompleted> root = cq.from(ReadCompleted.class);
	Predicate p = cb.equal(root.get(ReadCompleted_.person), effectivePerson.getDistinguishedName());
	if (ListTools.isNotEmpty(wi.getApplicationList())) {
		p = cb.and(p, root.get(ReadCompleted_.application).in(wi.getApplicationList()));
	}
	if (ListTools.isNotEmpty(wi.getProcessList())) {
		p = cb.and(p, root.get(ReadCompleted_.process).in(wi.getProcessList()));
	}
	if(DateTools.isDateTimeOrDate(wi.getStartTime())){
		p = cb.and(p, cb.greaterThan(root.get(ReadCompleted_.startTime), DateTools.parse(wi.getStartTime())));
	}
	if(DateTools.isDateTimeOrDate(wi.getEndTime())){
		p = cb.and(p, cb.lessThan(root.get(ReadCompleted_.startTime), DateTools.parse(wi.getEndTime())));
	}
	if (ListTools.isNotEmpty(wi.getCreatorUnitList())) {
		p = cb.and(p, root.get(ReadCompleted_.creatorUnit).in(wi.getCreatorUnitList()));
	}
	if (ListTools.isNotEmpty(wi.getStartTimeMonthList())) {
		p = cb.and(p, root.get(ReadCompleted_.startTimeMonth).in(wi.getStartTimeMonthList()));
	}
	if (ListTools.isNotEmpty(wi.getCompletedTimeMonthList())) {
		p = cb.and(p, root.get(ReadCompleted_.completedTimeMonth).in(wi.getCompletedTimeMonthList()));
	}
	if (ListTools.isNotEmpty(wi.getActivityNameList())) {
		p = cb.and(p, root.get(ReadCompleted_.activityName).in(wi.getActivityNameList()));
	}
	if (StringUtils.isNotEmpty(wi.getKey())) {
		String key = StringUtils.trim(StringUtils.replace(wi.getKey(), "\u3000", " "));
		if (StringUtils.isNotEmpty(key)) {
			key = StringUtils.replaceEach(key, new String[] { "?", "%" }, new String[] { "", "" });
			p = cb.and(p,
					cb.or(cb.like(root.get(ReadCompleted_.title), "%" + key + "%"),
							cb.like(root.get(ReadCompleted_.opinion), "%" + key + "%"),
							cb.like(root.get(ReadCompleted_.serial), "%" + key + "%"),
							cb.like(root.get(ReadCompleted_.creatorPerson), "%" + key + "%"),
							cb.like(root.get(ReadCompleted_.creatorUnit), "%" + key + "%")));
		}
	}
	cq.select(root).where(p).orderBy(cb.desc(root.get(ReadCompleted_.completedTime)));
	return em.createQuery(cq).setFirstResult((adjustPage - 1) * adjustPageSize).setMaxResults(adjustPageSize)
			.getResultList();
}
 
Example 17
private List<Read> list(EffectivePerson effectivePerson, Business business, Integer adjustPage,
		Integer adjustPageSize, Wi wi) throws Exception {
	EntityManager em = business.entityManagerContainer().get(Read.class);
	List<String> person_ids = business.organization().person().list(wi.getCredentialList());
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaQuery<Read> cq = cb.createQuery(Read.class);
	Root<Read> root = cq.from(Read.class);
	Predicate p = cb.conjunction();
	if (ListTools.isNotEmpty(wi.getApplicationList())) {
		p = cb.and(p, root.get(Read_.application).in(wi.getApplicationList()));
	}
	if (ListTools.isNotEmpty(wi.getProcessList())) {
		p = cb.and(p, root.get(Read_.process).in(wi.getProcessList()));
	}
	if(DateTools.isDateTimeOrDate(wi.getStartTime())){
		p = cb.and(p, cb.greaterThan(root.get(Read_.startTime), DateTools.parse(wi.getStartTime())));
	}
	if(DateTools.isDateTimeOrDate(wi.getEndTime())){
		p = cb.and(p, cb.lessThan(root.get(Read_.startTime), DateTools.parse(wi.getEndTime())));
	}
	if (ListTools.isNotEmpty(person_ids)) {
		p = cb.and(p, root.get(Read_.person).in(person_ids));
	}
	if (ListTools.isNotEmpty(wi.getCreatorUnitList())) {
		p = cb.and(p, root.get(Read_.creatorUnit).in(wi.getCreatorUnitList()));
	}
	if (ListTools.isNotEmpty(wi.getWorkList())) {
		p = cb.and(p, root.get(Read_.work).in(wi.getWorkList()));
	}
	if (ListTools.isNotEmpty(wi.getJobList())) {
		p = cb.and(p, root.get(Read_.job).in(wi.getJobList()));
	}
	if (ListTools.isNotEmpty(wi.getStartTimeMonthList())) {
		p = cb.and(p, root.get(Read_.startTimeMonth).in(wi.getStartTimeMonthList()));
	}
	if (ListTools.isNotEmpty(wi.getActivityNameList())) {
		p = cb.and(p, root.get(Read_.activityName).in(wi.getActivityNameList()));
	}
	if (StringUtils.isNotEmpty(wi.getKey())) {
		String key = StringUtils.trim(StringUtils.replace(wi.getKey(), "\u3000", " "));
		if (StringUtils.isNotEmpty(key)) {
			key = StringUtils.replaceEach(key, new String[] { "?", "%" }, new String[] { "", "" });
			p = cb.and(p,
					cb.or(cb.like(root.get(Read_.title), "%" + key + "%"),
							cb.like(root.get(Read_.opinion), "%" + key + "%"),
							cb.like(root.get(Read_.serial), "%" + key + "%"),
							cb.like(root.get(Read_.creatorPerson), "%" + key + "%"),
							cb.like(root.get(Read_.creatorUnit), "%" + key + "%")));
		}
	}
	cq.select(root).where(p).orderBy(cb.desc(root.get(Read_.startTime)));
	return em.createQuery(cq).setFirstResult((adjustPage - 1) * adjustPageSize).setMaxResults(adjustPageSize)
			.getResultList();
}
 
Example 18
Source Project: dubbox   File: QueryParserBase.java    License: Apache License 2.0 4 votes vote down vote up
private String escapeCriteriaValue(String criteriaValue) {
	return StringUtils.replaceEach(criteriaValue, RESERVED_CHARS, RESERVED_CHARS_REPLACEMENT);
}
 
Example 19
/**
 * 「ローマ字」から「かな文字」に変換する
 *
 * @param romaji 変換元の「ローマ字」
 * @return 変換後の「かな文字」
 * @since 2.8.10
 */
public static String conv(String romaji) {
    return StringUtils.replaceEach(romaji, ROMAJI_LIST, HIRAGANA_LIST);
}
 
Example 20
/**
 * Make sure that an individual funcotation field (i.e. single value of a funcotation) is sanitized for MAF consumption.
 * Particularly, make sure that it does not allow special characters that would interfere with MAF parsing.
 * @param individualFuncotationField  value from a funcotation. Never {@code null}
 * @return input string with special characters replaced by _%HEX%_ where HEX is the 2 digit ascii hex code.  Never {@code null}
 */
public static String sanitizeFuncotationFieldForMaf(final String individualFuncotationField) {
    Utils.nonNull(individualFuncotationField);
    return StringUtils.replaceEach(individualFuncotationField, new String[]{"\t", "\n"}, new String[]{"_%09_", "_%0A_"});
}