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

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

Introduction

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

Prototype

public static String replace(final String text, final String searchString, final String replacement) 

Source Link

Document

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" 

Usage

From source file:io.manasobi.license.LicenseController.java

private String convertISODateToDate(Date isoDate) {

    DateTime dateTime = new DateTime(isoDate);

    String simpleDate = DateUtils.convertDateToString(dateTime.minusHours(9).toDate(),
            "yyyy-MM-dd'T'HH:mm:ss.SSS'Z");

    simpleDate = StringUtils.replace(simpleDate, "T", " ");
    simpleDate = StringUtils.remove(simpleDate, "Z");

    return StringUtils.substring(simpleDate, 0, 19);
}

From source file:com.adobe.acs.commons.httpcache.keys.AbstractCacheKey.java

private String unmangle(String str) {
    str = StringUtils.replace(str, "jcr%3acontent", JcrConstants.JCR_CONTENT);
    return StringUtils.replace(str, "_jcr_content", JcrConstants.JCR_CONTENT);
}

From source file:net.ontopia.topicmaps.nav.taglibs.template.InsertTag.java

/**
 * Sets (according to attribute 'template') a path to the template
 * page.  <br><p>//  ww w . j a v a  2 s.  co  m
 *
 * Note: You can use a special placeholder <code>%view%</code> if
 * you want to insert the name of the current view of the user
 * session.  This is a work-around, because JSP does not allow you
 * to use a custom tag inside another custom tag
 */
public void setTemplate(String templateString) {
    template = templateString;

    // special extension for the needs of the MVS support
    // replace view placeholder with current view value
    if (template.indexOf(VIEW_PLACEHOLDER) >= 0) {
        UserIF user = FrameworkUtils.getUser(pageContext);
        String view = user.getView();
        template = StringUtils.replace(template, VIEW_PLACEHOLDER, view);
    }
}

From source file:io.wcm.handler.url.suffix.impl.UrlSuffixUtil.java

/**
 * Encode key value part//from w  ww . j a v a  2  s .  c om
 * @param string String
 * @return Encoded string
 */
public static String encodeKeyValuePart(String string) {
    try {
        String encoded = string;

        // escape special chars
        for (Map.Entry<String, String> entry : SPECIAL_CHARS_ESCAPEMAP.entrySet()) {
            encoded = StringUtils.replace(encoded, entry.getKey(), entry.getValue());
        }

        // fully URL encode the Key/value to allow arbitrary Strings
        encoded = URLEncoder.encode(encoded, CharEncoding.UTF_8);

        return encoded;
    } catch (UnsupportedEncodingException ex) {
        throw new RuntimeException("utf-8 not supported on this system", ex);
    }
}

From source file:com.norconex.commons.wicket.markup.html.chart.jqplot.options.PlotToStringBuilder.java

public static String esc(String str) {
    return StringUtils.replace(str, "'", "\\'");
}

From source file:net.ontopia.topicmaps.nav2.portlets.pojos.Wiki.java

private static String escape(String str) {
    str = StringUtils.replace(str, "<", "&lt;");
    str = StringUtils.replace(str, ">", "&gt;");
    return str;/*from w  ww.jav a 2s . co m*/
}

From source file:mfi.staticresources.ProcessResources.java

private String base64svg(String content) {

    content = replace(content, "image/svg+xml;charset=utf8,", "image/svg+xml;charset=utf8;base64,");
    try {/*  w w  w.  j  a  va2s .  c o  m*/
        boolean again = true;
        while (again) {
            String svg = StringUtils.substringBetween(content, "<svg", "</svg>");
            if (StringUtils.isBlank(svg)) {
                again = false;
            } else {
                svg = "<svg" + svg + "</svg>";
                byte[] svgBytes = svg.getBytes("UTF-8");
                String substringase64 = new String(Base64.encodeBase64(svgBytes), "UTF-8");
                content = StringUtils.replace(content, svg, substringase64);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    return content;
}

From source file:de.vandermeer.skb.datatool.commons.DataEntry.java

/**
 * Replaces several characters in a string to return a valid key element.
 * @param input the input string/*  w  w  w. j  a v a 2  s .c o  m*/
 * @return a string with replaced characters (" " to "-", "." to "")
 * @throws IllegalArgumentException if any illegal characters are in the final key
 */
default String toKey(String input) {
    if (input == null) {
        return input;
    }
    String ret = input;

    ret = StringUtils.replace(ret, " ", "-");
    ret = StringUtils.replace(ret, ".", "");

    if (ret.contains("%")) {
        throw new IllegalArgumentException("key contains '%'");
    }

    return ret.toLowerCase();
}

From source file:it.vige.greenarea.sgaplconsole.controllers.utils.RelativeViewHandler.java

/**
 * Get the url-path from the given request.
 * // w  w  w.  j a v  a2 s  .  c  o  m
 * @param request
 * @return clean path
 */
private String getPath(final HttpServletRequest request) {
    try {
        // TODO handle more than two '/'
        return StringUtils.replace(new URI(request.getRequestURI()).getPath(), "//", "/");
    } catch (final URISyntaxException e) {
        // XXX URISyntaxException ignored
        return StringUtils.EMPTY;
    }
}

From source file:de.micromata.genome.gwiki.page.impl.wiki.fragment.GWikiFragmentLink.java

protected String normalizeToTarget(String title) {
    String id = StringUtils.replace(StringUtils.replace(StringUtils.replace(title, "\t", "_"), " ", "_"), "\\",
            "/");
    id = NormalizeUtils.normalizeToTarget(id);
    return id;// ww w. j  av  a 2 s. c o m
}