Java Code Examples for cn.hutool.core.lang.Validator#isChinese()

The following examples show how to use cn.hutool.core.lang.Validator#isChinese() . 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: ChineseValidator.java    From yue-library with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
	String validValue = null;
	if ((CharUtil.isChar(value) && !CharUtil.isBlankChar((char) value))
			|| (value instanceof String && StrUtil.isNotBlank((String) value))) {
		validValue = StrUtil.toString(value);
	}
	
	if (StringUtils.isNotBlank(validValue)) {
		return Validator.isChinese(validValue);
	}
	
	if (notNull) {
		return false;
	}
	
	return true;
}
 
Example 2
Source File: CertificateController.java    From Jpom with MIT License 6 votes vote down vote up
/**
 * 获取证书信息
 *
 * @param certModel  实体
 * @param jsonObject json对象
 * @return 错误消息
 */
private String getCertModel(CertModel certModel, JSONObject jsonObject) {
    String id = jsonObject.getString("id");
    String path = jsonObject.getString("path");
    String name = jsonObject.getString("name");
    if (StrUtil.isEmpty(id)) {
        return JsonMessage.getString(400, "请填写证书id");
    }
    if (Validator.isChinese(id)) {
        return JsonMessage.getString(400, "证书id不能使用中文");
    }
    if (StrUtil.isEmpty(name)) {
        return JsonMessage.getString(400, "请填写证书名称");
    }
    if (!whitelistDirectoryService.checkCertificateDirectory(path)) {
        return JsonMessage.getString(400, "请选择正确的项目路径,或者还没有配置白名单");
    }
    certModel.setId(id);
    certModel.setWhitePath(path);
    certModel.setName(name);
    return null;
}
 
Example 3
Source File: ManageEditProjectController.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 检查项目lib 情况
 *
 * @param id     项目id
 * @param newLib 新路径
 * @return 状态码,400是一定不能操作的,401 是提醒
 */
@RequestMapping(value = "judge_lib.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public String saveProject(String id, String newLib) {
    File file = new File(newLib);
    //  填写的jar路径是一个存在的文件
    if (file.exists() && file.isFile()) {
        return JsonMessage.getString(400, "填写jar目录当前是一个已经存在的文件,请修改");
    }
    ProjectInfoModel exits = projectInfoService.getItem(id);
    if (exits == null) {
        // 创建项目 填写的jar路径是已经存在的文件夹
        if (file.exists()) {
            return JsonMessage.getString(401, "填写jar目录当前已经在,创建成功后会自动同步文件");
        }
    } else {
        // 已经存在的项目
        File oldLib = new File(exits.allLib());
        Path newPath = file.toPath();
        Path oldPath = oldLib.toPath();
        if (newPath.equals(oldPath)) {
            // 新 旧没有变更
            return JsonMessage.getString(200, "");
        }
        if (file.exists()) {
            if (oldLib.exists()) {
                // 新旧jar路径都存在,会自动覆盖新的jar路径中的文件
                return JsonMessage.getString(401, "原jar目录已经存在并且新的jar目录已经存在,保存将覆盖新文件夹并会自动同步原jar目录");
            }
            return JsonMessage.getString(401, "填写jar目录当前已经在,创建成功后会自动同步文件");
        }
    }
    if (Validator.isChinese(newLib)) {
        return JsonMessage.getString(401, "不建议使用中文目录");
    }
    return JsonMessage.getString(200, "");
}
 
Example 4
Source File: ManageEditProjectController.java    From Jpom with MIT License 4 votes vote down vote up
/**
 * 基础检查
 *
 * @param projectInfo        项目实体
 * @param whitelistDirectory 白名单
 * @param previewData        预检查数据
 * @return null 检查正常
 */
private String checkParameter(ProjectInfoModel projectInfo, String whitelistDirectory, boolean previewData) {
    String id = projectInfo.getId();
    if (StrUtil.isEmptyOrUndefined(id)) {
        return JsonMessage.getString(400, "项目id不能为空");
    }
    if (!StringUtil.isGeneral(id, 2, 20)) {
        return JsonMessage.getString(401, "项目id 长度范围2-20(英文字母 、数字和下划线)");
    }
    if (JpomApplication.SYSTEM_ID.equals(id)) {
        return JsonMessage.getString(401, "项目id " + JpomApplication.SYSTEM_ID + " 关键词被系统占用");
    }
    // 防止和Jpom冲突
    if (StrUtil.isNotEmpty(ConfigBean.getInstance().applicationTag) && ConfigBean.getInstance().applicationTag.equalsIgnoreCase(id)) {
        return JsonMessage.getString(401, "当前项目id已经被Jpom占用");
    }
    // 运行模式
    String runMode = getParameter("runMode");
    RunMode runMode1 = RunMode.ClassPath;
    try {
        runMode1 = RunMode.valueOf(runMode);
    } catch (Exception ignored) {
    }
    projectInfo.setRunMode(runMode1);
    // 监测
    if (runMode1 == RunMode.ClassPath || runMode1 == RunMode.JavaExtDirsCp) {
        if (StrUtil.isEmpty(projectInfo.getMainClass())) {
            return JsonMessage.getString(401, "ClassPath、JavaExtDirsCp 模式 MainClass必填");
        }
    } else if (runMode1 == RunMode.Jar || runMode1 == RunMode.JarWar) {
        projectInfo.setMainClass("");
    }
    if (runMode1 == RunMode.JavaExtDirsCp) {
        if (StrUtil.isEmpty(projectInfo.getJavaExtDirsCp())) {
            return JsonMessage.getString(401, "JavaExtDirsCp 模式 javaExtDirsCp必填");
        }
    }
    // 判断是否为分发添加
    String strOutGivingProject = getParameter("outGivingProject");
    boolean outGivingProject = Boolean.parseBoolean(strOutGivingProject);

    projectInfo.setOutGivingProject(outGivingProject);
    if (!previewData) {
        // 不是预检查数据才效验白名单
        if (!whitelistDirectoryService.checkProjectDirectory(whitelistDirectory)) {
            if (outGivingProject) {
                whitelistDirectoryService.addProjectWhiteList(whitelistDirectory);
            } else {
                return JsonMessage.getString(401, "请选择正确的项目路径,或者还没有配置白名单");
            }
        }
    }

    String lib = projectInfo.getLib();
    if (StrUtil.isEmpty(lib) || StrUtil.SLASH.equals(lib) || Validator.isChinese(lib)) {
        return JsonMessage.getString(401, "项目Jar路径不能为空,不能为顶级目录,不能包含中文");
    }
    if (!checkPathSafe(lib)) {
        return JsonMessage.getString(401, "项目Jar路径存在提升目录问题");
    }
    // java 程序副本
    if (runMode1 == RunMode.ClassPath || runMode1 == RunMode.Jar || runMode1 == RunMode.JarWar || runMode1 == RunMode.JavaExtDirsCp) {
        String javaCopyIds = getParameter("javaCopyIds");
        if (StrUtil.isEmpty(javaCopyIds)) {
            projectInfo.setJavaCopyItemList(null);
        } else {
            String[] split = StrUtil.split(javaCopyIds, StrUtil.COMMA);
            List<ProjectInfoModel.JavaCopyItem> javaCopyItemList = new ArrayList<>(split.length);
            for (String copyId : split) {
                String jvm = getParameter("jvm_" + copyId);
                String args = getParameter("args_" + copyId);
                //
                ProjectInfoModel.JavaCopyItem javaCopyItem = new ProjectInfoModel.JavaCopyItem();
                javaCopyItem.setId(copyId);
                javaCopyItem.setParendId(id);
                javaCopyItem.setModifyTime(DateUtil.now());
                javaCopyItem.setJvm(StrUtil.emptyToDefault(jvm, StrUtil.EMPTY));
                javaCopyItem.setArgs(StrUtil.emptyToDefault(args, StrUtil.EMPTY));
                javaCopyItemList.add(javaCopyItem);
            }
            projectInfo.setJavaCopyItemList(javaCopyItemList);
        }
    } else {
        projectInfo.setJavaCopyItemList(null);
    }
    return null;
}