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

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

Introduction

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

Prototype

public static String replaceEachRepeatedly(String text, String[] searchList, String[] replacementList) 

Source Link

Document

Replaces all occurrences of Strings within another String.

Usage

From source file:com.sp.keyword_generator.Keyword.java

public static String stripAccents(String s) {
    s = StringUtils.replaceEachRepeatedly(s.toLowerCase(), InputReplace, OutputReplace);
    s = StringEscapeUtils.escapeSql(s);/*w ww  .j a  v  a2s .c  om*/
    s = Normalizer.normalize(s.toLowerCase(), Normalizer.Form.NFD);
    return s;
}

From source file:hydrograph.ui.expression.editor.datastructure.ClassDetails.java

private String getJavaDoc(IClassFile classFile) throws JavaModelException {
    BinaryType binaryType = (BinaryType) classFile.getType();
    if (binaryType.getSource() != null && binaryType.getJavadocRange() != null) {
        String javaDoc = Constants.EMPTY_STRING;
        javaDoc = StringUtils.substring(binaryType.getSource().toString(), 0,
                binaryType.getJavadocRange().getLength());
        javaDoc = StringUtils.replaceEachRepeatedly(javaDoc, new String[] { "/*", "*/", "*" },
                new String[] { Constants.EMPTY_STRING, Constants.EMPTY_STRING, Constants.EMPTY_STRING });
    }/*  www. j a  v a 2 s  .c  o m*/
    return javaDoc;
}

From source file:edu.harvard.iq.dataverse.rserve.VariableNameCheckerForR.java

public String[] getFilteredVarNames() {
    // safeVarNames: all variables
    safeVarNames = new String[rawVarNames.length];
    int counter = 0;
    for (int i = 0; i < rawVarNames.length; i++) {

        if (R_RESERVED_WORDS_MAPPING_TABLE.containsKey(rawVarNames[i])) {
            safeVarNames[i] = R_RESERVED_WORDS_MAPPING_TABLE.get(rawVarNames[i]);
            raw2safeTable.put(rawVarNames[i], safeVarNames[i]);
            safe2rawTable.put(safeVarNames[i], rawVarNames[i]);
            renamedVars.add(rawVarNames[i]);
            renamedResults.add(safeVarNames[i]);
        } else {// ww  w  . j  ava 2 s .  c  om
            safeVarNames[i] = StringUtils.replaceEachRepeatedly(rawVarNames[i], unsafeChar, safeChar);
            if (!safeVarNames[i].equals(rawVarNames[i])) {
                raw2safeTable.put(rawVarNames[i], safeVarNames[i]);
                safe2rawTable.put(safeVarNames[i], rawVarNames[i]);
                renamedVars.add(rawVarNames[i]);
                renamedResults.add(safeVarNames[i]);
            }
        }
    }
    return safeVarNames;
}

From source file:com.sp.Parser.Utils.java

public static String Strip(String Input) {
    //        Input = Input.replaceAll("(\\b|_)(a|o)u+x?\\b", "");
    //        Input = Input.replaceAll("(\\b|_)l(e|a|es)\\b", "");
    //        Input = Input.replaceAll("(\\b|_)(m|t|s)(on|a|es)\\b", "");
    //        Input = Input.replaceAll("(\\b|_)une?\\b", "");
    //        Input = Input.replaceAll("(\\b|_)es?t\\b", "");
    //        Input = Input.replaceAll("(\\b|_)ce(lle)?s?\\b", "");
    //        Input = Input.replaceAll("(\\b|_)d(es?|u)\\b", "");
    //        Input = Input.replaceAll("(\\b|_)d(es?|u)\\b", "");
    Input = StringUtils.replaceEachRepeatedly(Input.toLowerCase(), InputReplace, OutputReplace);
    Input = StringEscapeUtils.escapeSql(Input);
    Input = Normalizer.normalize(Input.toLowerCase(), Normalizer.Form.NFD);
    return (Input.replaceAll("  *", " ")).trim();
    //return Input;
}

From source file:hydrograph.ui.expression.editor.datastructure.MethodDetails.java

private String createFormattedJavaDoc(IMethod iMethod) throws JavaModelException {
    String source = iMethod.getSource();
    if (iMethod.getJavadocRange() != null) {
        javaDoc = StringUtils.substring(source, 0, iMethod.getJavadocRange().getLength());
        javaDoc = StringUtils.replaceEachRepeatedly(javaDoc, new String[] { "/*", "*/", "*" },
                new String[] { Constants.EMPTY_STRING, Constants.EMPTY_STRING, Constants.EMPTY_STRING });
    }/*from  w  w  w  . j av  a 2 s  .c  o m*/
    return javaDoc;
}

From source file:hydrograph.ui.expression.editor.datastructure.ClassDetails.java

private String getJavaDoc(SourceType javaClassFile) throws JavaModelException {
    StringBuffer source = new StringBuffer(javaClassFile.getSource());
    try {/*from  www  .j  a v a 2s  .c  o  m*/
        String javaDoc = StringUtils.substring(source.toString(), 0,
                javaClassFile.getJavadocRange().getLength());
        javaDoc = StringUtils.replaceEachRepeatedly(javaDoc, new String[] { "/*", "*/", "*" },
                new String[] { Constants.EMPTY_STRING, Constants.EMPTY_STRING, Constants.EMPTY_STRING });
    } catch (Exception exception) {
        LOGGER.warn("Failed to build java-doc for :{}", javaClassFile);
    }
    return javaDoc;
}

From source file:com.cws.esolutions.security.config.xml.SecurityConfigurationData.java

public static final String expandEnvVars(final String value) {
    final String methodName = SecurityConfigurationData.CNAME + "#expandEnvVars(final String value)";

    if (DEBUG) {/*w  ww.  j  a  v a2s .co  m*/
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", value);
    }

    String returnValue = null;

    if (!(StringUtils.contains(value, "$"))) {
        return null;
    }

    final Properties sysProps = System.getProperties();
    final Map<String, String> envMap = System.getenv();
    final String text = StringUtils.replaceEachRepeatedly(value.split("=")[1].trim(),
            new String[] { "${", "}" }, new String[] { "", "" }).trim();

    if (DEBUG) {
        DEBUGGER.debug("Properties sysProps: {}", sysProps);
        DEBUGGER.debug("Map<String, String> envMap: {}", envMap);
        DEBUGGER.debug("String text: {}", text);
    }

    for (Entry<Object, Object> property : sysProps.entrySet()) {
        if (DEBUG) {
            DEBUGGER.debug("Entry<Object, Object> property: {}", property);
        }

        String key = (String) property.getKey();

        if (DEBUG) {
            DEBUGGER.debug("String key: {}", key);
        }

        if (StringUtils.equals(key.trim(), text)) {
            returnValue = sysProps.getProperty(key.trim());

            break;
        }
    }

    for (Entry<String, String> entry : envMap.entrySet()) {
        if (DEBUG) {
            DEBUGGER.debug("Entry<String, String> entry: {}", entry);
        }

        String key = entry.getKey();

        if (DEBUG) {
            DEBUGGER.debug("String key: {}", key);
        }

        if (StringUtils.equals(key.trim(), text)) {
            returnValue = entry.getValue();

            break;
        }
    }

    if (DEBUG) {
        DEBUGGER.debug("String returnValue: {}", returnValue);
    }

    return returnValue;
}

From source file:DataBase.DatabaseManager.java

public static String stripAccents(String s) {
    s = StringUtils.replaceEachRepeatedly(s.toLowerCase(), InputReplace, OutputReplace);
    s = StringEscapeUtils.escapeSql(s);// www  .ja  va  2s .c  o  m
    s = Normalizer.normalize(s.toLowerCase(), Normalizer.Form.NFD);
    s = s.replaceAll("('+|+)", "'");
    s = s.replaceAll("\"+", "");

    //LOG.info("after stripAccents: " + s);
    return s;
}

From source file:org.exoplatform.datasystems.migration.ContentMigrationService.java

private static void migrateContents() {
    try {//from   w  ww  . java2 s.  c  om

        RepositoryService repoService_ = (RepositoryService) ExoContainerContext.getContainerByName("portal")
                .getComponentInstanceOfType(RepositoryService.class);
        ManageableRepository repo = repoService_.getRepository("repository");
        Session session = repo.getSystemSession("collaboration");
        String statement = "select * from nt:resource ORDER BY exo:name DESC";
        QueryResult result = session.getWorkspace().getQueryManager().createQuery(statement, Query.SQL)
                .execute();
        NodeIterator nodeIter = result.getNodes();
        System.out.println("=====Start migrate data for all contents=====");

        while (nodeIter.hasNext()) {
            Node ntResource = nodeIter.nextNode();
            String mimeType = ntResource.getProperty("jcr:mimeType").getString();
            if (mimeType.startsWith("text")) {
                String jcrData = ntResource.getProperty("jcr:data").getString();
                if (jcrData.contains("/sites content/live/") || jcrData.contains("/ecmdemo/")
                        || jcrData.contains("/rest-ecmdemo/")) {

                    LOG.info("Content found with old data to update :" + ntResource.getParent().getPath());
                    //pattern   background: url("/ecmdemo/rest-ecmdemo/jcr/repository/collaboration/sites content/live/intranet/web contents/site artifacts/Welcome/medias/images/
                    //after   background: url("/portal/rest/jcr/repository/collaboration/sites/intranet/web contents/site artifacts/Welcome/medias/images/
                    String newData = StringUtils.replaceEachRepeatedly(jcrData,
                            new String[] { "/ecmdemo/", "/rest-ecmdemo/", "/sites content/live/" },
                            new String[] { "/portal/", "/rest/", "/sites/" });

                    // String realData = StringUtils.replace(jcrData,
                    // "/rest-ecmdemo/","/rest/");
                    // System.out.println(realData);
                    ntResource.setProperty("jcr:data", newData);
                    session.save();
                    LOG.info("migrate :" + ntResource.getParent().getName() + " with success");

                }
            }

        }
        System.out.println("=====end migrate data for all contents=====");

    } catch (Exception e) {
        LOG.error("An unexpected error occurs when migrating old Content: ", e);
    }
}

From source file:org.fuin.units4j.Units4JUtils.java

/**
 * Replaces the content of one or more XML attributes.
 * //from   w  w  w. j a  va2s. c  o m
 * @param xml
 *            Xml with content to replace.
 * @param keyValues
 *            Attribute name and new value.
 * 
 * @return Replaced content.
 */
public static String replaceXmlAttr(final String xml, final KV... keyValues) {

    final List<String> searchList = new ArrayList<String>();
    final List<String> replacementList = new ArrayList<String>();

    for (final KV kv : keyValues) {
        final String tag = kv.getKey() + "=\"";
        int pa = xml.indexOf(tag);
        while (pa > -1) {
            final int s = pa + tag.length();
            final int pe = xml.indexOf("\"", s);
            if (pe > -1) {
                final String str = xml.substring(pa, pe + 1);
                searchList.add(str);
                final String repl = xml.substring(pa, pa + tag.length()) + kv.getValue() + "\"";
                replacementList.add(repl);
            }
            pa = xml.indexOf(tag, s);
        }
    }

    final String[] searchArray = searchList.toArray(new String[searchList.size()]);
    final String[] replacementArray = replacementList.toArray(new String[replacementList.size()]);
    return StringUtils.replaceEachRepeatedly(xml, searchArray, replacementArray);
}