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:de.micromata.genome.util.runtime.LocalSettingsIncludeReplacer.java

/**
 * {@inheritDoc}/*w  w  w. j av  a  2s.c  o  m*/
 * 
 */

@Override
public Pair<String, String> replace(Pair<String, String> keyValue, Map<String, String> target) {
    if (keyValue.getKey().equals("include") == true) {
        File tf = new File(loadDir, keyValue.getSecond());
        this.localSettings.getLocalSettingsLoader().loadSettings(this.localSettings, tf, target, false, true);
        return null;
    }
    if (keyValue.getValue().contains("${LOCALSETTINGSDIR}") == true) {
        String value = StringUtils.replace(keyValue.getValue(), "${LOCALSETTINGSDIR}",
                loadDir.getAbsolutePath());
        keyValue.setValue(value);
    }
    return keyValue;
}

From source file:de.blizzy.documentr.web.filter.TrimWriter.java

void write(String text, OutputStream out, Charset charset) throws IOException {
    BufferedReader in = null;/* w w w .  ja v  a2s  .  com*/
    try {
        in = new BufferedReader(new StringReader(text));
        String line;
        boolean textareaTag = false;
        boolean preTag = false;
        boolean notrimTag = false;
        boolean trim = true;
        while ((line = in.readLine()) != null) {
            String origLine = line;

            line = StringUtils.replace(line, "__NOTRIM__", StringUtils.EMPTY); //$NON-NLS-1$
            line = StringUtils.replace(line, "__/NOTRIM__", StringUtils.EMPTY); //$NON-NLS-1$
            line = REMOVE_COMMENT.replaceAll(line);

            if (trim) {
                line = TRIM_LEFT.replaceAll(line);
            }

            if (origLine.contains("<textarea")) { //$NON-NLS-1$
                textareaTag = true;
            }
            if (origLine.contains("<pre")) { //$NON-NLS-1$
                preTag = true;
            }
            if (origLine.contains("__NOTRIM__")) { //$NON-NLS-1$
                notrimTag = true;
            }
            if (textareaTag || preTag || notrimTag) {
                trim = false;
            }

            if (origLine.contains("</textarea")) { //$NON-NLS-1$
                textareaTag = false;
            }
            if (origLine.contains("</pre")) { //$NON-NLS-1$
                preTag = false;
            }
            if (origLine.contains("__/NOTRIM__")) { //$NON-NLS-1$
                notrimTag = false;
            }
            if (!textareaTag && !preTag && !notrimTag) {
                trim = true;
            }

            if (trim) {
                line = TRIM_RIGHT.replaceAll(line);
            }

            boolean doWrite = !trim || StringUtils.isNotBlank(line);
            if (doWrite) {
                writeln(line, out, charset);
            }
        }
    } finally {
        Closeables.closeQuietly(in);
    }
}

From source file:de.micromata.mgc.jpa.hibernatesearch.bridges.TimeableListFieldBridge.java

@Override
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
    if ((value instanceof List) == false) {
        return;//from ww  w  .j  a v  a 2 s. c om
    }
    List timelist = (List) value;
    for (Object el : timelist) {
        if ((el instanceof TimeableAttrRow) == false) {
            LOG.warn("No TimeableAttrRow, cannot create search index: " + el);
            break;
        }
        TimeableAttrRow<?> row = (TimeableAttrRow<?>) el;
        Date start = row.getStartTime();
        String prefix = Converter.dateToDebugString(start) + ".";
        prefix = StringUtils.replace(StringUtils.replace(prefix, ".", "-"), ":", "_");
        for (String rk : row.getAttributeKeys()) {
            String svalue = row.getStringAttribute(rk);
            if (StringUtils.isEmpty(svalue) == true) {
                continue;
            }
            Field field = new StringField(prefix + rk, svalue, TabAttrFieldBridge.DEFAULT_STORE);
            document.add(field);

            field = new StringField(rk, svalue, TabAttrFieldBridge.DEFAULT_STORE);
            document.add(field);
        }
    }
}

From source file:net.ontopia.topicmaps.nav2.impl.basic.DefaultUniversalLinkGenerator.java

@Override
public String generate(ContextTag contextTag, TopicMapReferenceIF tmRefObj, String template) {
    String link = template;/*  w w w  . java 2 s  . c o  m*/

    // replace topicmap id placeholder with real value
    String topicmapId = tmRefObj.getId();
    link = StringUtils.replace(link, LINK_TOPICMAP_KEY, topicmapId);

    return link;
}

From source file:com.monarchapis.driver.servlet.ApiRequest.java

public ApiRequest(HttpServletRequest request) throws IOException {
    super(request);
    this.body = IOUtils.toByteArray(request.getInputStream());
    requestId = StringUtils.replace(UUID.randomUUID().toString(), "-", "");
}

From source file:com.huifu.mybatis.handler.LikeTypeHandler.java

@Override
public void setNonNullParameter(PreparedStatement arg0, int arg1, String arg2, JdbcType arg3)
        throws SQLException {
    String likeParam = arg2;//  w w  w  .j a va 2  s  . co  m
    // ?
    likeParam = StringUtils.replace(likeParam, getEscape(), getEscape() + getEscape());
    // ?%
    likeParam = StringUtils.replace(likeParam, WILDCARD_PERCENT_SIGN, getEscape() + WILDCARD_PERCENT_SIGN);
    // ?_
    likeParam = StringUtils.replace(likeParam, WILDCARD_UNDERLINE, getEscape() + WILDCARD_UNDERLINE);

    // TODO [] .
    // ?[
    // likeParam = StringUtils.replace(likeParam, WILDCARD_LEFT_BRACKETS,
    // getEscape() + WILDCARD_LEFT_BRACKETS);
    // ?]
    // likeParam = StringUtils.replace(likeParam, WILDCARD_RIGHT_BRACKETS,
    // getEscape() + WILDCARD_RIGHT_BRACKETS);

    // ??%
    likeParam = WILDCARD_PERCENT_SIGN + likeParam + WILDCARD_PERCENT_SIGN;
    LogFactory.LOGGER_FRAMEWORK.debug("like param :" + likeParam);
    arg0.setString(arg1, likeParam);
    // arg0.setString(arg1, likeParam + " escape '\\'");
}

From source file:de.micromata.genome.gwiki.plugin.rogmp3_1_0.GenItunesFile.java

public static String esc(String s) {
    s = StringUtils.replace(s, "&", "&amp;");
    s = StringUtils.replace(s, "<", "&lt;");
    s = StringUtils.replace(s, ">", "&gt;");
    // return StringEscapeUtils.escapeXml(s);
    return s;//from  www . j  a va 2s  .  c o  m
}

From source file:de.ks.flatadocdb.defaults.DefaultIdGenerator.java

protected String getRelativePath(Path repository, Path targetPath) {
    return StringUtils.replace(repository.relativize(targetPath).toString(), "\\", "/");
}

From source file:com.yqboots.initializer.core.ProjectMetadata.java

/**
 * Gets the path by replacing the '.' to '/', for path lookup.
 *
 * @return the group path//w  w w .  j  a  v a2  s  . c  o m
 */
public String getGroupPath() {
    return StringUtils.replace(getGroupId(), ".", "/");
}

From source file:com.neophob.sematrix.core.glue.ShufflerOffset.java

/**
 * //from   www. j a va  2 s  .co  m
 * @return
 */
public String guiText() {
    return WordUtils.capitalizeFully(StringUtils.replace(this.name(), "_", " "));
}