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

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

Introduction

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

Prototype

public static String replaceEach(final String text, final String[] searchList, final String[] replacementList) 

Source Link

Document

Replaces all occurrences of Strings within another String.

Usage

From source file:com.green.generate.Generate.java

public static void main(String[] args) throws Exception {

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

    // ??????//from  ww  w.  j ava  2 s  . c  o  m
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "com.thinkgem.jeesite.modules";

    String moduleName = "factory"; // ???sys
    String subModuleName = ""; // ????? 
    String className = "product"; // ??user
    String classAuthor = "ThinkGem"; // ThinkGem
    String functionName = "?"; // ??

    // ???
    Boolean isEnable = false;

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

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

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        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);

    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/thinkgem/jeesite/generate/template",
            "/", separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    logger.info("View Path: {}", 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", StringUtils.lowerCase(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",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "_" + StringUtils.lowerCase(subModuleName) : "")
                    + "_" + model.get("className"));
    model.put("urlPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "")
                    + "/" + model.get("className"));
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "")
                    + ":" + model.get("className"));

    // ? Entity
    Template template = cfg.getTemplate("entity.ftl");
    String content = FreeMarkers.renderTemplate(template, model);
    String filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + ".java";
    writeFile(content, filePath);
    logger.info("Entity: {}", filePath);

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

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

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

    // ? 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) + separator
            + model.get("className") + "Form.jsp";
    writeFile(content, filePath);
    logger.info("ViewForm: {}", filePath);

    // ? 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) + separator
            + model.get("className") + "List.jsp";
    writeFile(content, filePath);
    logger.info("ViewList: {}", filePath);

    logger.info("Generate Success.");
}

From source file:com.ourlife.dev.generate.Generate.java

public static void main(String[] args) throws Exception {

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

    // ??????/*from ww  w .  j av a  2 s. c o m*/
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName
    // ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "com.ourlife.dev.modules";

    String moduleName = "biz"; // ???sys
    String subModuleName = ""; // ?????
    String className = "orderLog"; // ??user
    String classAuthor = "ourlife"; // ourlife
    String functionName = "?"; // ??

    // ???
    Boolean isEnable = true;

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

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

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        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);

    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/ourlife/dev/generate/template", "/",
            separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    logger.info("View Path: {}", 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", StringUtils.lowerCase(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",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "_" + StringUtils.lowerCase(subModuleName) : "")
                    + "_" + model.get("className"));
    model.put("urlPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "")
                    + "/" + model.get("className"));
    model.put("viewPrefix", // StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "")
                    + ":" + model.get("className"));

    // ? Entity
    Template template = cfg.getTemplate("entity.ftl");
    String content = FreeMarkers.renderTemplate(template, model);
    String filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + ".java";
    writeFile(content, filePath);
    logger.info("Entity: {}", filePath);

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

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

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

    // ? 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) + separator
            + model.get("className") + "Form.jsp";
    writeFile(content, filePath);
    logger.info("ViewForm: {}", filePath);

    // ? 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) + separator
            + model.get("className") + "List.jsp";
    writeFile(content, filePath);
    logger.info("ViewList: {}", filePath);

    logger.info("Generate Success.");
}

From source file:com.joey.Fujikom.generate.Generate.java

public static void main(String[] args) throws Exception {

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

    // ??????/*from   ww w .j ava2  s  . c  o m*/
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "com.joey.Fujikom.modules";

    String moduleName = "factory"; // ???sys
    String subModuleName = ""; // ????? 
    String className = "product"; // ??user
    String classAuthor = "ThinkGem"; // ThinkGem
    String functionName = "?"; // ??

    // ???
    //Boolean isEnable = false;
    Boolean isEnable = true;

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

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

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        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);

    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/thinkgem/Fujikom/generate/template",
            "/", separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    logger.info("View Path: {}", viewPath);

    // ???
    Configuration cfg = new Configuration();
    cfg.setDefaultEncoding("UTF-8");
    cfg.setDirectoryForTemplateLoading(new File(tplPath));

    // ???
    Map<String, String> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName));
    model.put("moduleName", StringUtils.lowerCase(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",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "_" + StringUtils.lowerCase(subModuleName) : "")
                    + "_" + model.get("className"));
    model.put("urlPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "")
                    + "/" + model.get("className"));
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "")
                    + ":" + model.get("className"));

    // ? Entity
    Template template = cfg.getTemplate("entity.ftl");
    String content = FreeMarkers.renderTemplate(template, model);
    String filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + ".java";
    writeFile(content, filePath);
    logger.info("Entity: {}", filePath);

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

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

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

    // ? 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) + separator
            + model.get("className") + "Form.jsp";
    writeFile(content, filePath);
    logger.info("ViewForm: {}", filePath);

    // ? 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) + separator
            + model.get("className") + "List.jsp";
    writeFile(content, filePath);
    logger.info("ViewList: {}", filePath);

    logger.info("Generate Success.");
}

From source file:com.pansky.integration.generate.Generate.java

public static void main(String[] args) throws Exception {

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

    // ??????//  w  w w  .j  av  a  2s.  c  om
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "com.pansky.integration.modules";

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

    // ???
    //      Boolean isEnable = false;
    Boolean isEnable = true;

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

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

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        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);

    // ?
    String tplPath = StringUtils
            .replace(projectPath + "/src/main/java/com/pansky/integration/generate/template", "/", separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    String javaTestPath = StringUtils.replaceEach(
            projectPath + "/src/test/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    logger.info("View Path: {}", viewPath);

    // ???
    Configuration cfg = new Configuration();
    cfg.setDefaultEncoding("UTF-8");
    cfg.setDirectoryForTemplateLoading(new File(tplPath));

    // ???
    Map<String, String> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName));
    model.put("moduleName", StringUtils.lowerCase(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",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "_" + StringUtils.lowerCase(subModuleName) : "")
                    + "_" + model.get("className"));
    model.put("urlPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "")
                    + "/" + model.get("className"));
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "")
                    + ":" + model.get("className"));

    // ? Entity
    Template template = cfg.getTemplate("entity.ftl");
    String content = FreeMarkers.renderTemplate(template, model);
    String filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + ".java";
    writeFile(content, filePath);
    logger.info("Entity: {}", filePath);

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

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

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

    // ? 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) + separator
            + model.get("className") + "Form.jsp";
    writeFile(content, filePath);
    logger.info("ViewForm: {}", filePath);

    // ? 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) + separator
            + model.get("className") + "List.jsp";
    writeFile(content, filePath);
    logger.info("ViewList: {}", filePath);
    //?TestCase
    template = cfg.getTemplate("serviceTest.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaTestPath + separator + model.get("moduleName") + separator + "service" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + "ServiceTest.java";
    writeFile(content, filePath);
    logger.info("Service: {}", filePath);
    logger.info("Generate Success.");
}

From source file:com.sishuok.es.generate.Generate.java

public static void main(String[] args) throws Exception {

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

    // ??????//  www .  j  a va 2 s . c o m
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "com.sishuok.es";

    String sysName = "sys"; // ??sys?showcase?maintain?personal?shop
    String moduleName = "xxs"; // ???? 
    String tableName = "sys_xxs_attribute"; // user
    String className = "XxsAttribute"; // ??User
    String permissionName = "sys:xxsAttribute";//??????????
    String folderName = "xxs";//??
    String classAuthor = "xxs"; // ThinkGem
    String functionName = "??????"; // ??

    // ???
    //Boolean isEnable = false;
    Boolean isEnable = true;

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

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

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        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);

    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/sishuok/es/generate/template", "/",
            separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/jsp/admin", "/", separator);
    logger.info("View Path: {}", viewPath);

    // ???
    Configuration cfg = new Configuration();
    cfg.setDefaultEncoding("UTF-8");
    cfg.setDirectoryForTemplateLoading(new File(tplPath));

    // ???
    Map<String, String> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName)); //
    model.put("sysName", StringUtils.lowerCase(sysName)); //???
    model.put("moduleName", StringUtils.lowerCase(moduleName)); //???
    model.put("tableName", StringUtils.lowerCase(tableName)); //
    model.put("className", StringUtils.uncapitalize(className)); //???
    model.put("permissionName", permissionName); //????
    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("folderName", folderName); //??
    model.put("urlPrefix", model.get("moduleName") + "_" + model.get("className")); //jsp??
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix", model.get("sysName") + ":" + model.get("moduleName")); //??

    // ? Entity
    Template template = cfg.getTemplate("entity.ftl");
    String content = FreeMarkers.renderTemplate(template, model);
    String filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName")
            + separator + "entity" + separator + model.get("ClassName") + ".java";
    System.out.println("Entity   filePath" + filePath);
    writeFile(content, filePath);
    logger.info("Entity: {}", filePath);

    // ? Repository
    template = cfg.getTemplate("repository.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator
            + "repository" + separator + separator + model.get("ClassName") + "Repository.java";
    System.out.println("repository   filePath" + filePath);
    writeFile(content, filePath);
    logger.info("Dao: {}", filePath);

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

    // ? ??Controller
    template = cfg.getTemplate("frontController.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator
            + "web" + separator + "controller" + separator + "front" + separator + model.get("ClassName")
            + "Controller.java";
    System.out.println("Controller   filePath" + filePath);
    writeFile(content, filePath);
    logger.info("Controller: {}", filePath);

    // ? ??Controller
    template = cfg.getTemplate("adminController.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = javaPath + separator + model.get("sysName") + separator + model.get("moduleName") + separator
            + "web" + separator + "controller" + separator + "admin" + separator + model.get("ClassName")
            + "Controller.java";
    System.out.println("Controller   filePath" + filePath);
    writeFile(content, filePath);
    logger.info("Controller: {}", filePath);

    // ? editForm
    template = cfg.getTemplate("editForm.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator
            + "editForm.jsp";
    System.out.println("---------------------------------------------------");
    System.out.println("ViewForm   filePath" + filePath);
    writeFile(content, filePath);
    logger.info("ViewForm: {}", filePath);

    // ? list
    template = cfg.getTemplate("list.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator
            + "list.jsp";
    writeFile(content, filePath);
    System.out.println("ViewListfilePath" + filePath);
    logger.info("ViewList: {}", filePath);

    // ? searcheForm
    template = cfg.getTemplate("searchForm.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator
            + "searchForm.jsp";
    writeFile(content, filePath);
    System.out.println("searcheForm filePath" + filePath);
    logger.info("ViewList: {}", filePath);

    // ? listTable
    template = cfg.getTemplate("listTable.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath + separator + model.get("sysName") + separator + model.get("folderName") + separator
            + "listTable.jsp";
    writeFile(content, filePath);
    System.out.println("listTable filePath" + filePath);
    logger.info("ViewList: {}", filePath);

    logger.info("Generate Success.");
}

From source file:com.sccl.attech.generate.Generate.java

/**
 * The main method./*from   w  ww .  j  av  a  2 s .c  o  m*/
 * 
 * @param args the arguments
 * @throws Exception the exception
 */
public static void main(String[] args) throws Exception {

    // ==========  ?? ====================1412914

    // ??????
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "com.sccl.attech.modules";

    String moduleName = "mobil"; // ???sys
    String subModuleName = ""; // ????? 
    String className = "updateApp"; // ??user
    List<GenerateField> fields = Lists.newArrayList();
    fields.add(new GenerateField("name", "??"));
    fields.add(new GenerateField("type", ""));
    fields.add(new GenerateField("version", ""));
    fields.add(new GenerateField("path", ""));

    String classAuthor = "zzz"; // zhaozz
    String functionName = "App?"; // ??

    // ???
    //Boolean isEnable = false;
    Boolean isEnable = true;

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

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

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        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);

    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/com/sccl/attech/generate/template", "/",
            separator);
    logger.info("Template Path: {}", tplPath);

    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    logger.info("Java Path: {}", javaPath);

    // 
    String viewPath = StringUtils.replace(projectPath + "/WebRoot/pages", "/", separator);
    logger.info("View Path: {}", viewPath);
    String resPath = StringUtils.replace(projectPath + "/WebRoot/assets/js", "/", separator);
    logger.info("Res Path: {}", resPath);

    // ???
    Configuration cfg = new Configuration();
    cfg.setDefaultEncoding("UTF-8");
    cfg.setDirectoryForTemplateLoading(new File(tplPath));

    // ???
    Map<String, Object> model = Maps.newHashMap();
    model.put("packageName", StringUtils.lowerCase(packageName));
    model.put("moduleName", StringUtils.lowerCase(moduleName));
    model.put("fields", fields);
    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",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "_" + StringUtils.lowerCase(subModuleName) : "")
                    + "_" + model.get("className"));
    model.put("urlPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? "/" + StringUtils.lowerCase(subModuleName) : "")
                    + "/" + model.get("className"));
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));
    model.put("permissionPrefix",
            model.get("moduleName")
                    + (StringUtils.isNotBlank(subModuleName) ? ":" + StringUtils.lowerCase(subModuleName) : "")
                    + ":" + model.get("className"));

    // ? Entity
    Template template = cfg.getTemplate("entity.ftl");
    String content = FreeMarkers.renderTemplate(template, model);
    String filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator
            + StringUtils.lowerCase(subModuleName) + separator + model.get("ClassName") + ".java";
    writeFile(content, filePath);
    logger.info("Entity: {}", filePath);

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

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

    // ? Controller
    createJavaFile(subModuleName, separator, javaPath, cfg, model);

    // ? 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) + separator
            + model.get("className") + "Form.html";
    writeFile(content, filePath);
    logger.info("ViewForm: {}", filePath);

    // ? ViewFormJs
    template = cfg.getTemplate("viewFormJs.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = resPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".")
            + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator
            + model.get("className") + "FormCtrl.js";
    writeFile(content, filePath);
    logger.info("ViewFormJs: {}", filePath);

    // ? 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) + separator
            + model.get("className") + "List.html";
    writeFile(content, filePath);
    logger.info("ViewList: {}", filePath);

    // ? ViewListJs
    template = cfg.getTemplate("viewListJs.ftl");
    content = FreeMarkers.renderTemplate(template, model);
    filePath = resPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".")
            + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator
            + model.get("className") + "ListCtrl.js";
    writeFile(content, filePath);
    logger.info("ViewList: {}", filePath);

    // ? ??sql
    template = cfg.getTemplate("sql.ftl");
    model.put("uid", IdGen.uuid());
    model.put("uid1", IdGen.uuid());
    content = FreeMarkers.renderTemplate(template, model);
    filePath = viewPath//+separator+StringUtils.substringAfterLast(model.get("packageName"),".")
            + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName) + separator
            + model.get("className") + ".sql";
    writeFile(content, filePath);
    logger.info("ViewList: {}", filePath);

    logger.info("Generate Success.");
}

From source file:es.alrocar.utils.Utils.java

public static double formatNumber(String number, String decimalSeparator, String numberSeparator) {
    if (number == null || number.trim().isEmpty()) {
        return 0;
    }/*from w w w  .  jav a2s .c om*/

    number = StringUtils.replaceEach(number, removeChars, replaceChars);

    String temp = number.trim();
    if (numberSeparator != null) {
        temp = number.replaceAll(numberSeparator, "");
    }

    if (decimalSeparator != null) {
        temp = temp.replaceAll(decimalSeparator, ".");
    }

    return Double.valueOf(temp);
}

From source file:com.google.testing.pogen.generator.test.java.NameConverter.java

/**
 * Converts the specified text with signs to a string without signs by translating signs into
 * texts.//from  w w w  .  jav a 2s . c  o m
 * 
 * @param textWithSigns
 * @return the specified text with signs to a string without signs by translating signs into texts
 */
public static String replaceSignsToTexts(String textWithSigns) {
    String[] signs = new String[] { "+", "-", "*", "/", "." };
    String[] texts = new String[] { "_plus_", "_minus_", "_multiply_", "_divide_", "_dot_" };
    return StringUtils.replaceEach(textWithSigns, signs, texts);
}

From source file:com.hubspot.jinjava.lib.filter.EscapeFilter.java

public static String escapeHtmlEntities(String input) {
    return StringUtils.replaceEach(input, TO_REPLACE, REPLACE_WITH);
}

From source file:de.tor.tribes.util.bb.OverallReportStatsFormatter.java

@Override
public String formatElements(List<OverallStatResult> pElements, boolean pExtended) {
    OverallStatResult res = pElements.get(0);
    String[] replacements = res.getReplacements(pExtended);
    String template = STANDARD_TEMPLATE;
    template = StringUtils.replaceEach(template, res.getBBVariables(), replacements);
    return template;
}