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:com.thinkbiganalytics.servicemonitor.support.ServiceMonitorCheckUtil.java

/**
 * get a map of the Service and any components that should be checked within that service.
 *///from w  w w. j  av a  2  s  .  co m
public static Map<String, List<String>> getMapOfServiceAndComponents(String services) {
    Map<String, List<String>> map = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    if (StringUtils.isNotBlank(services)) {
        String finalServiceString = services;
        if (services.contains("/")) {
            int i = 1;
            String serviceName = null;
            for (String servicePart : StringUtils.split(services, "/")) {
                //service name is the first string before the /

                if (serviceName == null) {
                    if (servicePart.contains(",")) {
                        serviceName = StringUtils.substringAfterLast(servicePart, ",");
                    } else {
                        serviceName = servicePart;
                    }
                } else {
                    String components = "";
                    String origComponents = "";
                    if (servicePart.contains("]")) {
                        components = StringUtils.substringBeforeLast(servicePart, "]");
                        components = StringUtils.substringAfter(components, "[");
                        origComponents = "[" + components + "]";
                    } else {
                        components = StringUtils.substringBefore(servicePart, ",");
                        origComponents = components;
                    }
                    String[] componentsArr = StringUtils.split(components, ",");
                    map.put(serviceName, Arrays.asList(componentsArr));

                    //now remove these from the finalServiceString
                    finalServiceString = StringUtils.replace(finalServiceString,
                            serviceName + "/" + origComponents, "");

                    //reset serviceName
                    serviceName = StringUtils.substringAfterLast(servicePart, ",");

                }
                i++;
            }
        }

        for (String service : StringUtils.split(finalServiceString, ",")) {
            String serviceName = service;
            map.put(serviceName, Arrays.asList(new String[] { ALL_COMPONENTS }));
        }
    }
    return map;
}

From source file:it.cnr.ilc.latmorphwebapp.ProxyHandler.java

private String getPath(final HttpServletRequest request) {
    try {/* www . ja v a2s . c  om*/
        return StringUtils.replace(new URI(request.getRequestURI()).getPath(), "//", "/");
    } catch (final URISyntaxException e) {
        return StringUtils.EMPTY;
    }
}

From source file:AIR.Common.Utilities.JavaPrimitiveUtils.java

private static String removeFormattingFromNumberString(String value) {
    return StringUtils.replace(value, ",", "");
}

From source file:de.micromata.tpsb.srcgen.SourceGenerator.java

public String writeToDisk(String baseDir) {
    if (sb.getBuffer().length() == 0) {
        generate();//from   ww  w.  j a  v  a  2s  .  c  om
    }
    File dir = new File(baseDir);
    if (dir.exists() == false) {
        throw new RuntimeException("Source generation; target dir doesn't exists: " + dir.getAbsolutePath());
    }
    String packageN = StringUtils.replace(TypeUtils.getPackageFromFqClassName(fileInfo.getClassName()), ".",
            "/");
    File packageDir = new File(dir, packageN);
    if (packageDir.exists() == false) {
        if (packageDir.mkdirs() == false) {
            throw new RuntimeException("Source generation; cannot create class package directory: "
                    + packageDir.getAbsolutePath());
        }
    }
    String pureClassName = TypeUtils.getShortClassName(fileInfo.getClassName());
    File f = new File(packageDir, pureClassName + ".java");
    try {
        FileUtils.write(f, sb.getBuffer().toString(), CharEncoding.UTF_8);
        return f.getAbsolutePath();
    } catch (Exception ex) {
        throw new RuntimeException(
                "Source generation; Error writing file " + f.getAbsolutePath() + "; " + ex.getMessage(), ex);
    }
}

From source file:glluch.com.ontotaxoseeker.Term.java

/**
 * Create the possible uri from a piece of text 
 * @param term A String with the possible name.
 * @return a String with the candidate uri.
 *///from  w  w  w  .  j a va2 s.  c o  m
public static String buildUri(String term) {
    //TODO check if term is, perhaps, an uri.
    String res;
    res = term.trim().toLowerCase();
    res = StringUtils.replace(res, " ", "_");
    return Config.NS + res;
}

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

public static String escape(String k) {
    k = StringUtils.replace(k, "\\", "\\\\");
    k = StringUtils.replace(k, "|", "\\|");
    k = StringUtils.replace(k, "=", "\\=");
    return k;/*from w ww  .  ja  v  a 2s  . c o  m*/

}

From source file:net.ontopia.xml.ContentWriter.java

protected String escape(String attrval) {
    return StringUtils.replace(
            StringUtils.replace(StringUtils.replaceChars(attrval, "&", "&amp;"), "<", "&lt;"), "\"", "&quot;");
}

From source file:apm.generate.Generate.java

public static void parameters(String packageName, String moduleName, String className, String classAuthor,
        String functionName, String tableName, String entityContent, String flag) throws Exception {
    // ==========  ?? ====================
    // ??????/*from   ww  w  .j a va 2s  . c o  m*/
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}
    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?

    //String packageName = "lms.modules";//???

    //String moduleName = "test";         //???sys
    String subModuleName = ""; // ?????? 
    //String className = "test";         // ??user
    //String classAuthor = "htd";         // ThinkGem
    //String functionName = "";         //??

    // ???
    Boolean isEnable = true;

    // ==========  ?? ====================

    if (!isEnable) {
        //logger.error("????isEnable = true");
        System.out.println("????isEnable = true");
        return;
    }

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        //logger.error("??????????????");
        System.out.println("??????????????");
        return;
    }

    // ?
    String separator = File.separator;

    // ?
    File projectPath = new DefaultResourceLoader().getResource("").getFile();
    while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) {
        projectPath = projectPath.getParentFile();
    }
    //logger.info("Project Path: {}", projectPath);
    System.out.println("-------------------------------------------------");
    System.out.println(":" + projectPath);
    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/apm/generate/template", "/", separator);
    //logger.info("Template Path: {}", tplPath);
    System.out.println("?:" + tplPath);
    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    //logger.info("Java Path: {}", javaPath);
    System.out.println("Java:" + javaPath);
    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    //logger.info("View Path: {}", viewPath);
    System.out.println(":" + viewPath);
    // ???
    Configuration cfg = new Configuration();
    cfg.setDirectoryForTemplateLoading(new File(tplPath));

    // ???
    Map<String, String> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName));
    model.put("moduleName", moduleName);
    model.put("subModuleName",
            StringUtils.isNotBlank(subModuleName) ? "." + StringUtils.lowerCase(subModuleName) : "");
    model.put("className", StringUtils.uncapitalize(className));
    model.put("ClassName", StringUtils.capitalize(className));
    model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools");
    model.put("classVersion", DateUtils.getDate());
    model.put("functionName", functionName);
    model.put("tableName", tableName);

    model.put("urlPrefix", "/" + model.get("className"));
    model.put("viewUrlPrefix", "/" + model.get("moduleName"));
    model.put("returnPrefix", "modules" + //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("viewUrlPrefix") + "/" + model.get("className"));
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));

    model.put("permissionPrefix", model.get("className"));
    String[] strs = entityContent.split("##");
    model.put("columnContent", strs[0]);
    model.put("entityContent", strs[1]);

    System.out.println("-------------------------?------------------------");
    Template template = null;
    String content = null;
    String filePath = null;
    if (flag.indexOf("entity") != -1 || flag.length() == 0) {
        // ? Entity
        template = cfg.getTemplate("entity.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator
                + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + ".java";
        writeFile(content, filePath);
        System.out.println("? Entity:" + filePath);
    }

    if (flag.indexOf("dao") != -1 || flag.length() == 0) {

        // ? Dao
        template = cfg.getTemplate("dao.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator
                + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + "Dao.java";
        writeFile(content, filePath);
        System.out.println("? Dao:" + filePath);

    }

    if (flag.indexOf("service") != -1 || flag.length() == 0) {

        // ? Service
        template = cfg.getTemplate("service.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator
                + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + "Service.java";
        writeFile(content, filePath);
        System.out.println("? Service:" + filePath);

    }

    if (flag.indexOf("controler") != -1 || flag.length() == 0) {

        // ? Controller
        template = cfg.getTemplate("controller.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "web" + separator
                + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + "Controller.java";
        writeFile(content, filePath);
        System.out.println("? Controller:" + filePath);

    }

    if (flag.indexOf("form") != -1 || flag.length() == 0) {

        // ? ViewForm
        template = cfg.getTemplate("viewForm.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".")
                + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName)
                + model.get("className") + "Form.jsp";
        writeFile(content, filePath);
        System.out.println("? ViewForm:" + filePath);

    }

    if (flag.indexOf("list") != -1 || flag.length() == 0) {

        // ? ViewList
        template = cfg.getTemplate("viewList.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".")
                + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName)
                + model.get("className") + "List.jsp";
        writeFile(content, filePath);
        System.out.println("? ViewList:" + filePath);

    }

}

From source file:com.xpn.xwiki.render.PreTagSubstitution.java

public String insertNonWikiText(String content) {
    for (int i = 0; i < this.list.size(); i++) {
        content = StringUtils.replace(content, "%_" + i + "_%", this.list.get(i));
    }//  w  w  w  .  j  av a 2s.  co  m
    return content;
}

From source file:de.micromata.genome.gwiki.page.search.expr.SearchUtils.java

public static String unescapeSearchLiteral(String text) {
    String ret = StringUtils.replace(text, "\\\"", "\"");
    ret = StringUtils.replace(ret, "\\\\", "\\");
    return ret;//from ww  w .j ava2s  . c o  m
}