List of usage examples for org.apache.commons.lang3 StringUtils replaceEach
public static String replaceEach(final String text, final String[] searchList, final String[] replacementList)
Replaces all occurrences of Strings within another String.
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 www.j a va 2 s. c om*/ // ?{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:de.tor.tribes.util.bb.BasicFormatter.java
public String formatElements(List<C> pElements, boolean pExtended) { StringBuilder b = new StringBuilder(pElements.size() * 15); NumberFormat f = getNumberFormatter(pElements.size()); String beforeList = getHeader(); String listItemTemplate = getLineTemplate(); String afterList = getFooter(); String replacedStart = StringUtils.replaceEach(beforeList, new String[] { ELEMENT_COUNT }, new String[] { f.format(pElements.size()) }); b.append(replacedStart);/*w ww . j av a2s .c om*/ formatElementsCore(b, pElements, pExtended, listItemTemplate, f); String replacedEnd = StringUtils.replaceEach(afterList, new String[] { ELEMENT_COUNT }, new String[] { f.format(pElements.size()) }); b.append(replacedEnd); return b.toString(); }
From source file:com.hesine.manager.generate.Generate.java
public static void execute(File curProjectPath) { // ========== ?? ==================== // ??????/* w w w . j a v a 2 s .com*/ // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className} // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4? String packageName = "com.hesine.manager"; // String moduleName = "function"; // ???sys String moduleName = ""; // ???sys String tableName = "tb_product"; // ???sys String subModuleName = ""; // ????? String className = "product"; // ??product String classAuthor = "Jason"; // ThinkGem String functionName = "?"; // ?? List<Map<String, String>> fileds = new ArrayList<Map<String, String>>(); // map Map<String, String> dataName = new HashMap<String, String>(); dataName.put("dataType", "String"); dataName.put("name", "name"); dataName.put("methodName", "Name"); dataName.put("comment", "??"); dataName.put("dbName", "name"); Map<String, String> dataDesc = new HashMap<String, String>(); dataDesc.put("dataType", "String"); dataDesc.put("name", "description"); dataDesc.put("methodName", "Description"); dataDesc.put("comment", "??"); dataDesc.put("dbName", "description"); fileds.add(dataName); fileds.add(dataDesc); // ??? Boolean isEnable = true; // ========== ?? ==================== if (!isEnable) { logger.error("????isEnable = true"); return; } // StringUtils.isBlank(moduleName) || if (StringUtils.isBlank(packageName) || StringUtils.isBlank(className) || StringUtils.isBlank(functionName)) { logger.error("??????????????"); return; } // ? String separator = File.separator; // ? File projectPath = curProjectPath; 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/hesine/manager/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); // Xml String xmlPath = StringUtils.replace(projectPath + "/src/main/resources/mybatis", "/", separator); logger.info("Xml Path: {}", xmlPath); // String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator); logger.info("View Path: {}", viewPath); // ??? Map<String, Object> 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("tableName", tableName); 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")); model.put("fileds", fileds); // // ? Entity // FileGenUtils.generateEntity(tplPath, javaPath, model); // // // ? sqlMap // FileGenUtils.generateSqlMap(tplPath, xmlPath, model); // // // ? Model // FileGenUtils.generateModel(tplPath, javaPath, model); // // // ? Dao // FileGenUtils.generateDao(tplPath, javaPath, model); // // // ? Service // FileGenUtils.generateService(tplPath, javaPath, model); // // // ? ServiceImpl // FileGenUtils.generateServiceImpl(tplPath, javaPath, model); // // // ? Controller // FileGenUtils.generateController(tplPath, javaPath, model); // ? add.ftl FileGenUtils.generateAddFtl(tplPath, viewPath, model); // ? edit.ftl FileGenUtils.generateEditFtl(tplPath, viewPath, model); // ? list.ftl FileGenUtils.generateListFtl(tplPath, viewPath, model); logger.info("Generate Success."); }
From source file:de.tor.tribes.util.bb.WinnerLoserStatsFormatter.java
@Override public String formatElements(List<Stats> pElements, boolean pExtended) { StringBuilder b = new StringBuilder(); String template = getTemplate(); String[] replacements = getStatSpecificReplacements(pElements, pExtended); template = StringUtils.replaceEach(template, getTemplateVariables(), replacements); b.append(template);//from w w w . j a va2 s . c o m return b.toString(); }
From source file:de.vandermeer.skb.datatool.entries.encodings.Htmlentry.java
@Override public void loadEntry(String keyStart, Map<String, Object> data, CoreSettings cs) throws URISyntaxException { this.entryMap = DataUtilities.loadEntry(this.getSchema(), keyStart, data, cs); this.entryMap.put(CommonKeys.KEY, this.getHtmlEntity()); this.entryMap.put(HtmlentryKeys.LOCAL_HTML_REPLACEMENT, StringUtils.replace(StringUtils.replace(this.getHtmlEntity(), "<", REPLACEMENT_PATTERN_START), ">", REPLACEMENT_PATTERN_END)); // this.htmlEntityRepl = StringUtils.replace(StringUtils.replace(this.getHtmlEntity(), "<", REPLACEMENT_PATTERN_START), ">", REPLACEMENT_PATTERN_END); if (this.getLatex() != null) { this.entryMap.put(EntryKeys.LATEX, StringUtils.replaceEach(this.getLatex(), new String[] { "\"", "\\" }, new String[] { "\\\"", "\\\\" })); }/*ww w . j a v a 2s .c om*/ // if(this.latex!=null){ // this.latex = StringUtils.replaceEach( // (String)this.latex, // new String[]{"\"", "\\"}, // new String[]{"\\\"", "\\\\"} // ); // } }
From source file:de.vandermeer.skb.datatool.entries.encodings.EncodingEntry.java
@Override public void loadEntry(String keyStart, Map<String, Object> data, CoreSettings cs) throws URISyntaxException { this.entryMap = DataUtilities.loadEntry(this.getSchema(), keyStart, data, cs); this.entryMap.put(CommonKeys.KEY, Integer.toString(this.getDec())); if (this.getText() != null) { this.entryMap.put(EncodingKeys.ENC_CHAR, StringUtils.replaceEach(this.getText(), new String[] { "\"", "\\" }, new String[] { "\\\"", "\\\\" })); }/*from ww w . ja v a2 s . c om*/ // this.text = StringUtils.replaceEach( // (String)this.text, // new String[]{"\"", "\\"}, // new String[]{"\\\"", "\\\\"} // ); this.entryMap.put(EncodingKeys.LOCAL_HTML_CODE, String.format("&#%d;", this.getDec())); this.entryMap.put(EncodingKeys.LOCAL_ENCODING_UC_NUMBER, String.format("U+%4H", this.getDec())); // this.htmlCode = String.format("&#%d;", this.getDec()); // this.ucNumber = String.format("U+%4H", this.getDec()); if (this.getLatex() != null) { this.entryMap.put(EntryKeys.LATEX, StringUtils.replaceEach(this.getLatex(), new String[] { "\"", "\\" }, new String[] { "\\\"", "\\\\" })); } // if(this.latex!=null){ // this.latex = StringUtils.replaceEach( // (String)this.latex, // new String[]{"\"", "\\"}, // new String[]{"\\\"", "\\\\"} // ); // } }
From source file:de.tor.tribes.util.bb.BasicFormatter.java
protected void formatElementsCore(final StringBuilder builder, final Collection<C> elems, final boolean pExtended, final String listItemTemplate, final NumberFormat format) { int cnt = 1;//from www . j a v a 2 s .c o m for (C n : elems) { String[] replacements = n.getReplacements(pExtended); String itemLine = StringUtils.replaceEach(listItemTemplate, n.getBBVariables(), replacements); itemLine = StringUtils.replaceEach(itemLine, new String[] { ELEMENT_ID, ELEMENT_COUNT }, new String[] { format.format(cnt), format.format(elems.size()) }); builder.append(itemLine).append("\n"); cnt++; } }
From source file:eu.codesketch.scriba.rest.analyser.domain.service.introspector.jackson.JsonPropertyAnnotationIntrospector.java
private String getPropertyNamefromSetterOrGetter(String input) { return StringUtils.replaceEach(input, new String[] { "get", "set" }, new String[] { "", "" }).toLowerCase(); }
From source file:com.rutarget.UpsourceReviewStatsExtension.PageExtension.java
private static String escapeToHtmlAttribute(String s) { return StringUtils.replaceEach(s, new String[] { "&", "<", ">", "\"", "'", "/" }, new String[] { "&", "<", ">", """, "'", "/" }); }
From source file:gobblin.data.management.copy.hive.HiveDataset.java
/** * Resolve {@value #DATABASE_TOKEN} and {@value #TABLE_TOKEN} in <code>rawString</code> to {@link Table#getDbName()} * and {@link Table#getTableName()}//from w w w . ja v a 2 s.c o m */ public static String resolveTemplate(String rawString, Table table) { if (StringUtils.isBlank(rawString)) { return rawString; } return StringUtils.replaceEach(rawString, new String[] { DATABASE_TOKEN, TABLE_TOKEN }, new String[] { table.getDbName(), table.getTableName() }); }