Example usage for org.apache.commons.lang StringUtils replace

List of usage examples for org.apache.commons.lang StringUtils replace

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils replace.

Prototype

public static String replace(String text, String searchString, String replacement, int max) 

Source Link

Document

Replaces a String with another String inside a larger String, for the first max values of the search String.

Usage

From source file:com.livinglogic.ul4.BoundStringMethodReplace.java

public static String call(String object, String search, String replace, int count) {
    return StringUtils.replace(object, search, replace, count);
}

From source file:com.haulmont.cuba.security.global.UserUtils.java

public static String formatName(String pattern, String firstName, String lastName, String middleName)
        throws ParseException {
    if (pattern == null || pattern.length() == 0)
        throw new ParseException("Pattern error", 0);
    if (firstName == null || firstName.equals("null"))
        firstName = "";
    if (lastName == null || lastName.equals("null"))
        lastName = "";
    if (middleName == null || middleName.equals("null"))
        middleName = "";
    String[] params = StringUtils.substringsBetween(pattern, "{", "}");
    int i;//from   w  w  w  .ja v  a2s  .com
    for (i = 0; i < params.length; i++) {
        pattern = StringUtils.replace(pattern, "{" + params[i] + "}", "{" + i + "}", 1);
        params[i] = parseParam(params[i], firstName, lastName, middleName);
    }
    for (i = 0; i < params.length; i++) {
        pattern = StringUtils.replace(pattern, "{" + i + "}", params[i], 1);
    }
    return pattern;
}

From source file:com.sangupta.pep.macros.FixImagePathsMacro.java

@Override
public ContentAndClasses process(String content, File parentDir) {
    Matcher matcher = EmbedImagesMacro.PATTERN.matcher(content);
    while (matcher.find()) {
        // String imageTag = matcher.group();
        String imageUrl = matcher.group(1);

        // encode image
        String absoluteUrl = PepUtils.getAbsoluteUrl(imageUrl, parentDir);
        if (absoluteUrl == null) {
            System.out.println("Failed to resolve image from url: " + imageUrl);
            continue;
        }/*from   www.  j ava  2  s.  c  o m*/

        // replace original image with encoded image
        content = StringUtils.replace(content, imageUrl, absoluteUrl, 1);
    }

    return new ContentAndClasses(content);
}

From source file:com.sangupta.pep.macros.EmbedImagesMacro.java

@Override
public ContentAndClasses process(String content, File parentDir) {
    Matcher matcher = PATTERN.matcher(content);
    while (matcher.find()) {
        // String imageTag = matcher.group();
        String imageUrl = matcher.group(1);

        // encode image
        String encodedUrl = PepUtils.encodeImageFromUrl(imageUrl);
        if (encodedUrl == null) {
            System.out.println("Failed to embed image from url: " + imageUrl);
            continue;
        }/* w w w  .j  a  v  a  2s. c  o  m*/

        // replace original image with encoded image
        content = StringUtils.replace(content, imageUrl, encodedUrl, 1);
    }

    return new ContentAndClasses(content);
}

From source file:com.gst.infrastructure.core.api.ApiParameterHelper.java

public static String sqlEncodeString(final String str) {
    final String singleQuote = "'";
    final String twoSingleQuotes = "''";
    return singleQuote + StringUtils.replace(str, singleQuote, twoSingleQuotes, -1) + singleQuote;
}

From source file:com.networknt.mask.Mask.java

private static String replaceWithMask(String stringToBeMasked, char maskingChar, String regex) {
    if (stringToBeMasked.length() == 0) {
        return stringToBeMasked;
    }//  w  w w.j  ava 2 s.c o  m
    String replacementString = "";
    String padGroup = "";
    if (!StringUtils.isEmpty(regex)) {
        try {
            Pattern pattern = patternCache.get(regex);
            if (pattern == null) {
                pattern = Pattern.compile(regex);
                patternCache.put(regex, pattern);
            }
            Matcher matcher = pattern.matcher(stringToBeMasked);
            if (matcher.matches()) {
                String currentGroup = "";
                for (int i = 0; i < matcher.groupCount(); i++) {
                    currentGroup = matcher.group(i + 1);
                    padGroup = StringUtils.rightPad("", currentGroup.length(), maskingChar);
                    stringToBeMasked = StringUtils.replace(stringToBeMasked, currentGroup, padGroup, 1);
                }
                replacementString = stringToBeMasked;
            }
        } catch (Exception e) {
            replacementString = StringUtils.rightPad("", stringToBeMasked.length(), maskingChar);
        }
    } else {
        replacementString = StringUtils.rightPad("", stringToBeMasked.length(), maskingChar);
    }
    return replacementString;
}

From source file:com.sun.socialsite.util.UtilitiesModel.java

public static String replace(String src, String target, String rWith, int maxCount) {
    return StringUtils.replace(src, target, rWith, maxCount);
}

From source file:net.di2e.ecdr.broker.endpoint.rest.CDRRestBrokerServiceImpl.java

@Override
protected String replaceTemplateValues(String osdTemplate) {
    // @formatter:off
    String additionalParams = "cdrb:routeTo - a comma separated lists of siteNames (sources) that the query should be federated to "
            + System.lineSeparator() + "            default: [sent to all sites]" + System.lineSeparator()
            + "            allowedValues: " + getAllSites() + System.lineSeparator()
            + "            localSourceId: " + getCatalogFramework().getId() + System.lineSeparator()
            + "            example: site1,site2";
    // @formatter:on 
    osdTemplate = StringUtils.replace(osdTemplate, "${additionalBasicParameters}", additionalParams, 1);
    return super.replaceTemplateValues(osdTemplate);
}