List of usage examples for org.apache.commons.lang3 StringUtils replace
public static String replace(final String text, final String searchString, final String replacement)
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"
From source file:com.ethlo.geodata.restdocs.AbstractJacksonFieldSnippet.java
protected void handleSchema(final Class<?> type, final ObjectNode root, final ObjectNode definitions, FieldDescriptor desc, final Iterator<String> path) { ObjectNode lastNode = (ObjectNode) root.get("properties"); Class<?> lastField = type; while (path.hasNext() && lastNode != null && lastField != null) { final String p = StringUtils.replace(path.next(), "[]", ""); final Field f = FieldUtils.getField(lastField, p, true); final Class<?> field = f != null ? (Collection.class.isAssignableFrom(f.getType()) ? (Class<?>) ((ParameterizedType) f.getGenericType()).getActualTypeArguments()[0] : f.getType()) : null;//from w w w . j ava 2 s .c o m final JsonNode currentNode = lastNode.get(p); if (currentNode instanceof ObjectNode && field != null) { if (!path.hasNext()) { // Leaf of path definition, set description final String description = desc.getDescription().toString(); ((ObjectNode) currentNode).put("description", description); } final String typeDef = currentNode.path("type").asText(); if (!StringUtils.isNotEmpty(typeDef)) { handleRef(field, root, definitions, (ObjectNode) currentNode, desc, path); } } lastNode = currentNode instanceof ObjectNode ? (ObjectNode) currentNode : null; lastField = field; } }
From source file:com.hesine.manager.generate.Generate.java
public static void execute(File curProjectPath, String packageName, String moduleName, Map<String, String> table, List<Map<String, String>> fileds) { // ========== ?? ==================== // ??????//from w w w . j a v 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.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 = "?"; // ?? String tableName = table.get("tableName"); // ???sys String subModuleName = ""; // ????? String className = table.get("className"); // ??product String classAuthor = "Jason"; // ThinkGem String functionName = table.get("comment"); // ?? // ??? 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 tmpProjectPath = "/Users/zhanghongbing/Workspaces/Projects/hesine-projects/github-framework/hesine-demo/hesine-portal"; String tplPath = StringUtils.replace(tmpProjectPath + "/src/main/java/com/hesine/manager/generate/template", "/", separator); // 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:com.jspxcms.core.setup.SetupServlet.java
private void copyFile(ServletRequest request, String host, String port, String name, String user, String password) throws IOException { String customPath = getServletContext().getRealPath("/WEB-INF/classes/custom.properties"); File customFile = new File(customPath); String customString = FileUtils.readFileToString(customFile, "utf-8"); customString = StringUtils.replace(customString, "{host}", host); if (StringUtils.isNotBlank(port)) { customString = StringUtils.replace(customString, "{port}", port); } else {/* w w w .j ava 2s. com*/ customString = StringUtils.remove(customString, ":{port}"); } customString = StringUtils.replace(customString, "{name}", name); customString = StringUtils.replace(customString, "{user}", user); customString = StringUtils.replace(customString, "{password}", password); String destCustomPath = getServletContext().getRealPath("/WEB-INF/classes/custom.properties"); FileUtils.write(new File(destCustomPath), customString, "utf-8"); String webPath = getServletContext().getRealPath("/setup/file/web.xml"); String destWebPath = getServletContext().getRealPath("/WEB-INF/web.xml"); FileUtils.copyFile(new File(webPath), new File(destWebPath)); }
From source file:de.crowdcode.kissmda.maven.plugin.KissMdaMojo.java
String getGuiceModuleName(String transformerClazzName) { String guiceModuleClazzName = StringUtils.replace(transformerClazzName, "Transformer", "Module"); return guiceModuleClazzName; }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil.java
private static <T> T readJsonValue(String name, Class<T> type, String json) { try {//from w w w.j a v a2 s .c om return reader.forType(type).readValue(json); } catch (IOException e) { if (ExceptionUtils.getRootCause(e) instanceof ClassNotFoundException) { //attempt to find the old class name and replace it with the new one ClassNotFoundException classNotFoundException = (ClassNotFoundException) ExceptionUtils .getRootCause(e); String msg = classNotFoundException.getMessage(); msg = StringUtils.remove(msg, "java.lang.ClassNotFound:"); String oldName = StringUtils.trim(msg); try { Class newName = ClassNameChangeRegistry.findClass(oldName); String newNameString = newName.getName(); if (StringUtils.contains(json, oldName)) { //replace and try again json = StringUtils.replace(json, oldName, newNameString); return readJsonValue(name, type, json); } } catch (ClassNotFoundException c) { } } throw new MetadataRepositoryException("Failed to deserialize JSON property: " + name, e); } }
From source file:net.ontopia.topicmaps.nav2.portlets.pojos.TMRAP.java
private String addParameters(String endpoint, Collection psis) { StringBuilder buf = new StringBuilder(endpoint); buf.append('?'); Iterator it = psis.iterator(); while (it.hasNext()) { String psi = (String) it.next(); buf.append("identifier="); buf.append(StringUtils.replace(psi, "#", "%23")); if (it.hasNext()) buf.append("&"); }//from w w w .jav a 2 s .co m return buf.toString(); }
From source file:com.oncore.calorders.core.utils.FormatHelper.java
public static Boolean isValidDecimal(String value) { Boolean result = Boolean.FALSE; try {//from w w w . ja v a 2 s . c o m value = StringUtils.replace(value, ",", ""); @SuppressWarnings("unused") BigDecimal bd = new BigDecimal(value); result = Boolean.TRUE; } catch (Exception ex) { Logger.warn(LOG, getStackTrace(ex)); } return result; }
From source file:io.wcm.devops.maven.nodejsproxy.resource.MavenProxyResource.java
private String mapGroupId(String groupIdPath) { return StringUtils.replace(groupIdPath, "/", "."); }
From source file:de.blizzy.documentr.page.CherryPicker.java
private CommitCherryPickResult tryResolveConflict(ILockedRepository repo, String branchName, String path, PageVersion pageVersion, String targetBranch, Set<CommitCherryPickConflictResolve> conflictResolves, User user, Locale locale) throws IOException, GitAPIException { File workingDir = RepositoryUtil.getWorkingDir(repo.r()); File pagesDir = new File(workingDir, DocumentrConstants.PAGES_DIR_NAME); File workingFile = Util.toFile(pagesDir, path + DocumentrConstants.PAGE_SUFFIX); String resolveText = getCherryPickConflictResolveText(conflictResolves, targetBranch, pageVersion.getCommitName()); CommitCherryPickResult result;/*from www .j a v a2s. c o m*/ if (resolveText != null) { if (!CONFLICT_MARKERS_RE.matcher("\n" + resolveText).matches()) { //$NON-NLS-1$ FileUtils.writeStringToFile(workingFile, resolveText, Charsets.UTF_8.name()); Git git = Git.wrap(repo.r()); git.add() .addFilepattern( DocumentrConstants.PAGES_DIR_NAME + "/" + path + DocumentrConstants.PAGE_SUFFIX) //$NON-NLS-1$ .call(); PersonIdent ident = new PersonIdent(user.getLoginName(), user.getEmail()); git.commit().setAuthor(ident).setCommitter(ident) .setMessage(DocumentrConstants.PAGES_DIR_NAME + "/" + path + DocumentrConstants.PAGE_SUFFIX) //$NON-NLS-1$ .call(); result = new CommitCherryPickResult(pageVersion, CommitCherryPickResult.Status.OK); } else { result = new CommitCherryPickResult(pageVersion, resolveText); } } else { String text = FileUtils.readFileToString(workingFile, Charsets.UTF_8); text = StringUtils.replace(text, "<<<<<<< OURS", //$NON-NLS-1$ "<<<<<<< " + messageSource.getMessage("targetBranchX", new Object[] { targetBranch }, locale)); //$NON-NLS-1$ //$NON-NLS-2$ text = StringUtils.replace(text, ">>>>>>> THEIRS", //$NON-NLS-1$ ">>>>>>> " + messageSource.getMessage("sourceBranchX", new Object[] { branchName }, locale)); //$NON-NLS-1$ //$NON-NLS-2$ result = new CommitCherryPickResult(pageVersion, text); } return result; }
From source file:io.treefarm.plugins.haxe.components.OpenFLCompiler.java
private List<String> getStandardArgumentsList(String nmml, String targetString, String buildDir, String appMain, String appFile, List<String> additionalArguments) { List<String> list = new ArrayList<String>(); list.add(nmml);//from w ww.java 2 s .c o m list.add(targetString); list.add("--app-path=" + buildDir); if (appMain != null) { list.add("--app-main=" + appMain); } if (appFile != null) { list.add("--app-file=" + appFile); } if (debug) { list.add("-debug"); list.add("--haxeflag='-D log'"); } if (verbose) { list.add("-verbose"); } if (additionalArguments != null) { List<String> compilerArgs = new ArrayList<String>(); for (String arg : additionalArguments) { if (StringUtils.startsWith(arg, "--macro ")) { compilerArgs.add(StringUtils.replace(arg, "--macro ", "--macro=")); } else { String haxeFlag = "--haxeflag='" + arg + "'"; compilerArgs.add(haxeFlag); } } list.addAll(compilerArgs); } return list; }