Java Code Examples for cn.hutool.core.util.StrUtil#replace()
The following examples show how to use
cn.hutool.core.util.StrUtil#replace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenServiceImpl.java From ruoyiplus with MIT License | 6 votes |
private void generatorAdvCodeOnlyWeb( String tmplName, TableInfo table, List<ColumnInfo> columns, Map<String, String[]> params, ZipOutputStream zip) { Map<String, String> swMap = generatorAdvCodeOnlyWeb(tmplName, table, columns, params); for (Map.Entry<String, String> entry : swMap.entrySet()) { String fileName = Convert.toStr(entry.getKey()); fileName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()); fileName = StrUtil.replace(fileName, ".vm", ""); try { // 添加到zip zip.putNextEntry(new ZipEntry(fileName)); IOUtils.write(Convert.toStr(entry.getValue()), zip, Constants.UTF8); zip.closeEntry(); } catch (IOException e) { log.error("渲染模板失败,表名:" + table.getTableName(), e); } } }
Example 2
Source File: CommandUtil.java From Jpom with MIT License | 6 votes |
/** * 在指定文件夹下执行命令 * * @param command 命令 * @param file 文件夹 * @return msg */ public static String execSystemCommand(String command, File file) { String newCommand = StrUtil.replace(command, StrUtil.CRLF, StrUtil.SPACE); newCommand = StrUtil.replace(newCommand, StrUtil.LF, StrUtil.SPACE); String result = "error"; try { List<String> commands = getCommand(); commands.add(newCommand); String[] cmd = commands.toArray(new String[]{}); result = exec(cmd, file); } catch (Exception e) { DefaultSystemLog.getLog().error("执行命令异常", e); result += e.getMessage(); } return result; }
Example 3
Source File: PostController.java From stone with GNU General Public License v3.0 | 5 votes |
/** * 去除html,htm后缀,以及将空格替换成- * * @param url url * @return String */ private static String urlFilter(String url) { if (null != url) { final boolean urlEndsWithHtmlPostFix = url.endsWith(".html") || url.endsWith(".htm"); if (urlEndsWithHtmlPostFix) { return url.substring(0, url.lastIndexOf(".")); } } return StrUtil.replace(url, " ", "-"); }
Example 4
Source File: LocalAutoConfigure.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
@Override protected void uploadFile(File file, MultipartFile multipartFile) throws Exception { //生成文件名 String fileName = UUID.randomUUID().toString() + StrPool.DOT + file.getExt(); String tenant = BaseContextHandler.getTenant(); //日期文件夹 String relativePath = Paths.get(tenant, LocalDate.now().format(DateTimeFormatter.ofPattern(DEFAULT_MONTH_FORMAT_SLASH))).toString(); // web服务器存放的绝对路径 String absolutePath = Paths.get(fileProperties.getStoragePath(), relativePath).toString(); java.io.File outFile = new java.io.File(Paths.get(absolutePath, fileName).toString()); org.apache.commons.io.FileUtils.writeByteArrayToFile(outFile, multipartFile.getBytes()); String url = new StringBuilder(fileProperties.getUriPrefix()) .append(relativePath) .append(StrPool.SLASH) .append(fileName) .toString(); //替换掉windows环境的\路径 url = StrUtil.replace(url, "\\\\", StrPool.SLASH); url = StrUtil.replace(url, "\\", StrPool.SLASH); file.setUrl(url); file.setFilename(fileName); file.setRelativePath(relativePath); }
Example 5
Source File: TieBaApi.java From tieba-api with MIT License | 5 votes |
/** * 根据百度盘分享url查询完整用户名(大部分可查) * @param panUrl 百度云盘分享url * @return 完整用户名 */ public String getFullNameByPanUrl(String panUrl) { try { panUrl = StrUtil.replace(panUrl, "wap", "share"); String html = EntityUtils.toString(hk.execute(panUrl).getEntity()); String uk = StrKit.substring(html, "uk\":", ","); String json = HttpUtil.get(String.format(Constants.UK_UN, uk)); JSONObject jsonObject = JSON.parseObject(json); String un = JSONPath.eval(jsonObject, "$.user_info.uname").toString(); return un; } catch (Exception e) { logger.error(e.getMessage(), e); } return null; }
Example 6
Source File: LocalAutoConfigure.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
@Override protected void uploadFile(File file, MultipartFile multipartFile) throws Exception { //生成文件名 String fileName = UUID.randomUUID().toString() + StrPool.DOT + file.getExt(); String tenant = BaseContextHandler.getTenant(); //日期文件夹 String relativePath = Paths.get(tenant, LocalDate.now().format(DateTimeFormatter.ofPattern(DEFAULT_MONTH_FORMAT_SLASH))).toString(); // web服务器存放的绝对路径 String absolutePath = Paths.get(fileProperties.getStoragePath(), relativePath).toString(); java.io.File outFile = new java.io.File(Paths.get(absolutePath, fileName).toString()); org.apache.commons.io.FileUtils.writeByteArrayToFile(outFile, multipartFile.getBytes()); String url = new StringBuilder(fileProperties.getUriPrefix()) .append(relativePath) .append(StrPool.SLASH) .append(fileName) .toString(); //替换掉windows环境的\路径 url = StrUtil.replace(url, "\\\\", StrPool.SLASH); url = StrUtil.replace(url, "\\", StrPool.SLASH); file.setUrl(url); file.setFilename(fileName); file.setRelativePath(relativePath); }
Example 7
Source File: PostController.java From blog-sharon with Apache License 2.0 | 5 votes |
/** * 去除html,htm后缀,以及将空格替换成- * * @param url url * @return String */ private static String urlFilter(String url) { if (null != url) { final boolean urlEndsWithHtmlPostFix = url.endsWith(".html") || url.endsWith(".htm"); if (urlEndsWithHtmlPostFix) { return url.substring(0, url.lastIndexOf(".")); } } return StrUtil.replace(url, " ", "-"); }
Example 8
Source File: AuxiliaryKit.java From kvf-admin with MIT License | 4 votes |
/** * 获取代码生成路径 * @param typeEnum 模板类型 * @param moduleName 模块名称 * @param funName 方法名 * @return */ public static String getGenerateCodePath(TemplateTypeEnum typeEnum, String moduleName, String funName) { ConfigConstant.PackageConfig packageConfig = new ConfigConstant.PackageConfig(); String pack = "", fileName = "", path = ""; switch (typeEnum.getType()) { case "ENTITY": pack = packageConfig.ENTITY_PACKAGE; fileName = StrUtil.upperFirst(funName) + ".java"; break; case "MAPPER": pack = packageConfig.MAPPER_PACKAGE; fileName = StrUtil.upperFirst(funName) + "Mapper.java"; break; case "SERVICE": pack = packageConfig.SERVICE_PACKAGE; fileName = StrUtil.upperFirst(funName) + "Service.java"; break; case "SERVICE_IMPL": pack = packageConfig.SERVICE_IMPL_PACKAGE; fileName = StrUtil.upperFirst(funName) + "ServiceImpl.java"; break; case "CONTROLLER": pack = packageConfig.CONTROLLER_PACKAGE; fileName = StrUtil.upperFirst(funName) + "Controller.java"; break; case "XML": pack = packageConfig.XML_PACKAGE; fileName = StrUtil.upperFirst(funName) + "Mapper.xml"; break; default: if (typeEnum.getType().equals("TABLE") || typeEnum.getType().equals("TREE_GRID")) { path = "templates/" + moduleName; fileName = funName + ".html"; } else if (typeEnum.getType().equals("OPERATION")) { path = "templates/" + moduleName; fileName = funName + "_edit.html"; } } if (!"".equals(pack)) { path = StrUtil.replace(packageConfig.BASE_PACKAGE + ".modules", ".", "/") + "/" + moduleName + "/" + pack; } if ("".equals(path)) { throw new RuntimeException("无法获取代码生成路径,请检查模板是否存在"); } path = ConfigConstant.CODE_GEN_PATH + "/" + ConfigConstant.CODE_FOLDER_NAME + "/" + path; return path + "/" + fileName; }
Example 9
Source File: SQLFilter.java From kvf-admin with MIT License | 4 votes |
/** * SQL注入过滤 * @param str 待验证的字符串 */ public String cleanSqlKeyWords(String str) { final String oldStr = str; if(StrUtil.isBlank(str)) { return ""; } if (StrUtil.isNullOrUndefined(str)) { return null; } // 去掉'|"|;|\字符 str = StrUtil.replace(str, "'", ""); str = StrUtil.replace(str, "\"", ""); str = StrUtil.replace(str, ";", ""); str = StrUtil.replace(str, "\\", ""); // 转换成小写 // str = str.toLowerCase(); String[] values = str.split(" "); if (values.length < 2) { return str; } // 非法字符 String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alert", "drop", "show"}; String badKeyStr = "'|and|exec|execute|insert|select|delete|update|count|drop|%|chr|mid|master|truncate|" + "char|declare|sitename|net user|xp_cmdshell|;|or|-|+|,|like'|and|exec|execute|insert|create|drop|" + "table|from|grant|use|group_concat|column_name|" + "information_schema.columns|table_schema|union|where|select|delete|update|order|by|count|" + "chr|mid|master|truncate|char|declare|or|;|-|--|,|like|//|/|%|#"; // 判断是否包含非法字符 for (String badKey : badKeyStr.split("\\|")) { for (String value : values) { if (value.equalsIgnoreCase(badKey)) { str = StrUtil.replace(str, badKey, "INVALID"); log.error("当前参数({})包含非法的sql关键词({}),系统已自动过滤。", oldStr, badKey); } } } return str; }