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) 

Source Link

Document

Replaces all occurrences of a String within another String.

Usage

From source file:com.jaxio.celerio.convention.CommentStyle.java

public String decorate(String line, String prepend) {
    if (null == line) {
        return "";
    }/*from   ww  w. java 2  s .  c  om*/
    if (this == JAVADOC || this == JAVA) {
        line = StringUtils.replace(line, "/**", "\n");
        line = StringUtils.replace(line, "/*", "\n");
        line = StringUtils.replace(line, "**/", "\n");
        line = StringUtils.replace(line, "*/", "\n");
        line = StringUtils.replace(line, " *", "\n");
    }
    line = StringUtils.replace(line, "  ", " ");
    line = StringUtils.replace(line, "  ", " ");
    line = StringUtils.replace(line, "  ", " ");
    line = StringUtils.replace(line, "\\n", "\n");
    line = StringUtils.replace(line, "\n\n", "\n");
    line = StringUtils.replace(line, "\n\n", "\n");
    line = StringUtils.replace(line, "\n\n", "\n");
    return decorate(newArrayList(line.split("\n")), prepend);
}

From source file:fr.cls.atoll.motu.library.misc.utils.PropertiesUtilities.java

/**
 * Replace in a string all variables (declared by <tt>${var}<tt>) with their corresponding values.
 * <p>/*from  w  w  w .  j  ava  2 s.  c  o  m*/
 * 
 * @param value string for which declared variables are replaced
 * @return the substituted string.
 */

static public String replaceSystemVariable(String value) {
    StringBuffer substValue = new StringBuffer();
    int idx = 0;
    int startIdx;
    int endIdx;
    String varName;
    String varValue;
    while ((startIdx = value.indexOf("${", idx)) != -1) {
        endIdx = value.indexOf("}", startIdx + 2);
        if (endIdx != -1) {
            varName = value.substring(startIdx + 2, endIdx);
            varValue = System.getProperty(varName);
            if (varValue == null) {
                throw new NoSuchElementException("no system property found for " + varName + " in " + value);
            }
            if (startIdx > 0) {
                substValue.append(value.substring(idx, startIdx));
            }
            // Treat correctly \
            varValue = StringUtils.replace(varValue, "\\", "\\\\");
            substValue.append(varValue);
            idx = endIdx + 1;
        } else {
            substValue.append(value.substring(idx));
            idx = value.length();
        }
    }
    substValue.append(value.substring(idx));
    return substValue.toString();
}

From source file:net.sf.zekr.common.resource.filter.QuranWriterFilter.java

public String filter(QuranFilterContext qfc) {
    String str = qfc.text;/*www .  ja va  2s  . c  o  m*/

    boolean suppressFilter = ApplicationConfig.getInstance().getProps().getBoolean("text.filter.suppress",
            false);
    if (suppressFilter) {
        return str;
    }

    if (qfc.ayaNum == 1 && qfc.suraNum != 1 && qfc.suraNum != 9) {
        int sp = -1;
        for (int i = 0; i < 4; i++) { // ignore 4 whitespaces.
            sp = str.indexOf(' ', sp + 1);
        }
        str = str.substring(sp + 1);
    }

    // remove SAJDA and HIZB sign
    str = StringUtils.remove(str, " " + SAJDA_PLACE);
    str = StringUtils.remove(str, RUB_EL_HIZB + " ");

    // good for Uthmani text
    if ((qfc.params & UTHMANI_TEXT) == UTHMANI_TEXT) {
        str = RegexUtils.pregReplace(str, "($SHADDA|$FATHA)($SUPERSCRIPT_ALEF)", "$1$TATWEEL$2");
        str = RegexUtils.pregReplace(str, "([$HAMZA$DAL-$ZAIN$WAW][$SHADDA$FATHA]*)$TATWEEL($SUPERSCRIPT_ALEF)",
                "$1$ZWNJ$2");
    }
    str = RegexUtils.pregReplace(str, "($SHADDA)([$KASRA$KASRATAN])", "$2$1");

    str = StringUtils.replace(str, String.valueOf(ALEF) + MADDA, String.valueOf(ALEF_MADDA));

    if ((qfc.params & SHOW_WAQF_SIGN) != SHOW_WAQF_SIGN) {
        // remove all waqf signs
        str = highlightRegex.matcher(str).replaceAll("");
    }

    if ((qfc.params & HIGHLIGHT_WAQF_SIGN) == HIGHLIGHT_WAQF_SIGN) {
        // highlight waqf sign
        if (ApplicationConfig.getInstance().getProps().getBoolean("text.filter.noSpaceBeforeWaqf", false)) {
            str = highlightRegex.matcher(str).replaceAll(REPLACE_HIGHLIGHT_NOSPACE);
        } else {
            str = highlightRegex.matcher(str).replaceAll(REPLACE_HIGHLIGHT);
        }
    }
    return str;
}

From source file:info.magnolia.module.delta.BootstrapSingleResourceAndOrderBefore.java

public BootstrapSingleResourceAndOrderBefore(String name, String description, String resource,
        String orderBeforeName) {
    super(name, description);
    // TODO : these values should be provided by the BootstrapUtil/Helper once MAGNOLIA-1806 is done.
    String filename = StringUtils.substringAfterLast(resource, "/");
    String repository = StringUtils.substringBefore(filename, ".");
    String path = StringUtils.substringAfter(StringUtils.substringBeforeLast(filename, "."), ".");
    path = "/" + StringUtils.replace(path, ".", "/");

    addTask(new BootstrapSingleResource(name, description, resource));
    addTask(new OrderNodeBeforeTask(name, description, repository, path, orderBeforeName));
}

From source file:com.opengamma.web.AbstractWebResource.java

/**
 * Builds the sort order.//from  www  .  ja va 2 s .  com
 * <p>
 * This method is lenient, returning the default in case of error.
 * 
 * @param <T>  the sort order type
 * @param order  the sort order, null or empty returns default
 * @param defaultOrder  the default order, not null
 * @return the sort order, not null
 */
protected <T extends Enum<T>> T buildSortOrder(String order, T defaultOrder) {
    if (StringUtils.isEmpty(order)) {
        return defaultOrder;
    }
    order = order.toUpperCase(Locale.ENGLISH);
    if (order.endsWith(" ASC")) {
        order = StringUtils.replace(order, " ASC", "_ASC");
    } else if (order.endsWith(" DESC")) {
        order = StringUtils.replace(order, " DESC", "_DESC");
    } else if (order.endsWith("_ASC") == false && order.endsWith("_DESC") == false) {
        order = order + "_ASC";
    }
    try {
        Class<T> cls = defaultOrder.getDeclaringClass();
        return Enum.valueOf(cls, order);
    } catch (IllegalArgumentException ex) {
        return defaultOrder;
    }
}

From source file:com.qualogy.qafe.core.placeholder.PlaceHolderResolver.java

private static String implementPlaceholders(ApplicationContext context, ApplicationStoreIdentifier storeId,
        DataIdentifier dataId, String value, List placeHolders, String localStoreId) {
    for (Iterator iter = placeHolders.iterator(); iter.hasNext();) {
        PlaceHolder placeHolder = (PlaceHolder) iter.next();
        if (placeHolder != null) {
            Object placeHolderValue = ParameterValueHandler.get(context, storeId, dataId, placeHolder,
                    localStoreId);/*from w  w  w.  jav a2s  . com*/

            if (placeHolderValue == null)
                placeHolderValue = "";

            value = StringUtils.replace(value, placeHolder.getPlaceHolderKey(), placeHolderValue.toString());
        }
    }
    return value;
}

From source file:com.cyclopsgroup.waterview.jsp.JspEngine.java

/**
 * Overwrite or implement method createView()
 *
 * @see com.cyclopsgroup.waterview.spi.DynaViewFactory#createView(com.cyclopsgroup.waterview.Path)
 *//*from   ww  w .  jav  a 2 s.c o  m*/
public View createView(Path path) throws Exception {
    String p = path.getPath();
    if (StringUtils.isNotEmpty(path.getPackage())) {
        p = '/' + StringUtils.replace(path.getPackage(), ".", "/") + p;
    }
    p = "/templates" + p;
    return new JspView(p, path.getFullPath());
}

From source file:com.wantscart.jade.core.JadeOperationFactoryImpl.java

@Override
public JadeOperation getOperation(DataAccess dataAccess, Modifier modifier) {

    //   Annotation
    SQL sql = modifier.getAnnotation(SQL.class);
    Assert.notNull(sql, "@SQL is required for method " + modifier);

    String sqlString = sql.value();
    SQLType sqlType = sql.type();

    if (sqlType == SQLType.TEMPLATE) {
        TableSchema schema = TableSchema.getSchema(modifier.getDefinition().getDAOGenericsClazz());
        for (String T : TableSchema.ALL_TEMPLATE) {
            sqlString = StringUtils.replace(sqlString, T, schema.getByTemplate(T));
        }//from   www.j a  v a2  s  .  c  o  m
        sqlType = SQLType.AUTO_DETECT;
    }

    if (sqlType == SQLType.AUTO_DETECT) {
        for (int i = 0; i < SELECT_PATTERNS.length; i++) {
            // ??  SELECT ?
            if (SELECT_PATTERNS[i].matcher(sqlString).find()) {
                sqlType = SQLType.READ;
                break;
            }
        }
        if (sqlType == SQLType.AUTO_DETECT) {
            sqlType = SQLType.WRITE;
        }
    }

    //
    if (SQLType.READ == sqlType) {
        //   RowMapper
        RowMapper rowMapper = rowMapperFactory.getRowMapper(modifier);
        // SELECT 
        return new SelectOperation(dataAccess, sqlString, modifier, rowMapper);

    } else if (SQLType.WRITE == sqlType) {
        // INSERT / UPDATE / DELETE 
        return new UpdateOperation(dataAccess, sqlString, modifier);
    }

    // 
    throw new AssertionError("Unknown SQL type: " + sqlType);
}

From source file:com.github.fritaly.graphml4j.samples.GradleDependencies.java

/**
 * Computes and returns a label from the given value.
 *
 * @param value/*from ww  w .  ja v a  2 s .co m*/
 *            a string identifying a dependency (group, artifact, version)
 *            generated by the Gradle dependencies task. Can't be null.
 * @return a string corresponding to a shorter label to uniquely identify a
 *         dependency.
 */
private static String computeLabel(String value) {
    // Examples of input values:
    // "org.springframework:spring-core:3.2.0.RELEASE (*)" => "spring-core:3.2.0.RELEASE"
    // "com.acme:acme-logging:1.16.0 -> 1.16.3 (*)" => "acme-logging:1.16.3"
    // "junit:junit:3.8.1 -> 4.8.1" => "junit:4.8.1"
    // "sun-jaxb:jaxb-impl:2.2" => "jaxb-impl:2.2"

    if (value.endsWith(" (*)")) {
        // Ex: "org.springframework:spring-core:3.2.0.RELEASE (*)" => "org.springframework:spring-core:3.2.0.RELEASE"
        value = value.replace(" (*)", "");
    }
    if (value.contains(" -> ")) {
        // Ex: "junit:junit:3.8.1 -> 4.8.1" => "junit:junit:4.8.1"
        final String version = StringUtils.substringAfter(value, " -> ");

        value = StringUtils.substringBeforeLast(value, ":") + ":" + version;
    }

    // Ex: "sun-jaxb:jaxb-impl:2.2" => "jaxb-impl:2.2"
    value = StringUtils.substringAfter(value, ":");

    return StringUtils.replace(value, ":", "\n");
}

From source file:de.fhg.iais.asc.transformer.jdom.handler.XmlFieldCleanser.java

@Override
protected String transform(Element element, String text) {
    String result = text;//from   w  w w  .  j av  a 2  s .com

    for (String term : this.searchTerms) {
        if (result.contains(term)) {
            result = StringUtils.replace(result, term, this.replacement).trim();
        }
    }

    return result;
}