📄 paramchecker.java
字号:
if (token == '<') { if (cond.charAt(4) == '=') { String strMax = cond.substring(5, cond.length()). trim(); try { float max = Float.parseFloat(strMax); if (fieldValue <= max) ; else { isValid = false; addMsg("err_need_less_equal", new String[] {fieldDesc, "" + max}); } } catch (Exception e) { isValid = false; addMsg("err_format", new String[] {cond}); } } else { String strMax = cond.substring(4, cond.length()). trim(); try { float max = Float.parseFloat(strMax); if (fieldValue < max) ; else { isValid = false; addMsg("err_need_less", new String[] {fieldDesc, "" + max}); } } catch (Exception e) { isValid = false; addMsg("err_format", new String[] {cond}); } } } else { isValid = false; addMsg("err_format", new String[] {cond}); } } } } if (!isValid) { if (onErrorExit) { throw new CheckErrException(msgs); } } } public void checkFieldInt(String ruleStr) throws CheckErrException { String fieldName = ""; String[] rule = split(ruleStr); if (rule == null) { addMsg("err_format", new String[] {ruleStr}); return; } int len = rule.length; if (len < 4) { addMsg("err_format", new String[] {ruleStr}); return; } fieldName = rule[1]; String value = getFieldValue(fieldName); checkFieldInt(ruleStr, value); } public void checkFieldInt(String ruleStr, String value) throws CheckErrException { String fieldName = ""; String type = ""; String fieldDesc = ""; String[] rule = split(ruleStr); if (rule == null) { addMsg("err_format", new String[] {ruleStr}); return; } int len = rule.length; if (len < 4) { addMsg("err_format", new String[] {ruleStr}); return; } type = rule[0]; fieldName = rule[1]; fieldDesc = parseFieldDesc(rule[2]); String NULL = rule[3]; Integer intValue = null; if (value == null || value.equals("")) { if (NULL.equalsIgnoreCase("not")) { addMsg("err_want", new String[] {fieldDesc}); return; } else if (NULL.equals("allow")) ; else if (NULL.startsWith("auto_inc")) { String s = NULL.substring(9, NULL.length()); String[] ary = s.split("\\$"); try { ISequence is = (ISequence)Class.forName(ary[0]).newInstance(); int typeId = Integer.parseInt(ary[1]); intValue = new Integer((int)is.getNextId(typeId)); } catch (Exception e) { logger.error("checkFieldInt1:" + StrUtil.trace(e)); addMsg("err_format", new String[] {fieldDesc + "=" + e.getMessage()}); return; } } else { try { int v = Integer.parseInt(NULL); intValue = new Integer(v); } catch (Exception e) { addMsg("err_format", new String[] {fieldDesc + "=" + NULL}); return; } } } else { try { int v = Integer.parseInt(value); intValue = new Integer(v); } catch (Exception e) { addMsg("err_format", new String[] {fieldDesc + "=" + value}); return; } } Field f = new Field(fieldName, fieldDesc, intValue, type); fields.put(fieldName, f); boolean isValid = true; for (int i = 4; i < len; i++) { String cond = rule[i].trim(); if (cond.startsWith("min")) { if (value != null) { int fieldValue = intValue.intValue(); char token = cond.charAt(3); if (token == '>') { if (cond.charAt(4) == '=') { String strMin = cond.substring(5, cond.length()). trim(); try { int min = Integer.parseInt(strMin); if (fieldValue >= min) ; else { isValid = false; addMsg("err_need_more_equal", new String[] {fieldDesc, "" + min}); } } catch (Exception e) { isValid = false; addMsg("err_format", new String[] {cond}); } } else { String strMin = cond.substring(4, cond.length()). trim(); try { int min = Integer.parseInt(strMin); if (fieldValue > min) ; else { isValid = false; addMsg("err_need_more", new String[] {fieldDesc, "" + min}); } } catch (Exception e) { addMsg("err_format", new String[] {cond}); } } } else { isValid = false; addMsg("err_format", new String[] {cond}); } } } else if (cond.startsWith("max")) { if (value != null) { int fieldValue = intValue.intValue(); char token = cond.charAt(3); if (token == '<') { if (cond.charAt(4) == '=') { String strMax = cond.substring(5, cond.length()). trim(); try { int max = Integer.parseInt(strMax); if (fieldValue <= max) ; else { isValid = false; addMsg("err_need_less_equal", new String[] {fieldDesc, "" + max}); } } catch (Exception e) { isValid = false; addMsg("err_format", new String[] {cond}); } } else { String strMax = cond.substring(4, cond.length()). trim(); try { int max = Integer.parseInt(strMax); if (fieldValue < max) ; else { isValid = false; addMsg("err_need_less", new String[] {fieldDesc, "" + max}); } } catch (Exception e) { isValid = false; addMsg("err_format", new String[] {cond}); } } } else { isValid = false; addMsg("err_format", new String[] {cond}); } } } } if (!isValid) { if (onErrorExit) { throw new CheckErrException(msgs); } } } public void checkFieldString(String ruleStr) throws CheckErrException { String fieldName = ""; String[] rule = split(ruleStr); if (rule == null) { addMsg("err_format", new String[] {ruleStr}); return; } int len = rule.length; if (len < 4) { addMsg("err_format", new String[] {ruleStr}); return; } fieldName = rule[1]; String value = getFieldValue(fieldName); checkFieldString(ruleStr, value); } public void checkFieldString(String ruleStr, String value) throws CheckErrException { String fieldName = ""; String type = ""; String fieldDesc = ""; String[] rule = split(ruleStr); if (rule == null) { addMsg("err_format", new String[] {ruleStr}); return; } int len = rule.length; if (len < 4) { addMsg("err_format", new String[] {ruleStr}); return; } type = rule[0]; fieldName = rule[1]; fieldDesc = parseFieldDesc(rule[2]); String NULL = rule[3]; boolean isValid = true; boolean isReturn = false; if (value == null) { isReturn = true; if (NULL.equalsIgnoreCase("not")) { addMsg("err_want", new String[] {fieldDesc}); } else if (NULL.equalsIgnoreCase("empty")) { value = ""; } else if (NULL.equalsIgnoreCase("allow")) { ; } else if (NULL.equalsIgnoreCase("ip")) { value = request.getHeader("HTTP_X_FORWARDED_FOR"); if (value == null) { value = StrUtil.getNullStr(request.getRemoteAddr()); } Field f = new Field(fieldName, fieldDesc, value, type); fields.put(fieldName, f); } else value = NULL; } else { value = value.trim(); if (value.equals("")) { isReturn = true; if (NULL.equalsIgnoreCase("not")) { addMsg("err_blank", new String[] {fieldDesc}); isValid = false; } if (NULL.equalsIgnoreCase("empty")) { Field f = new Field(fieldName, fieldDesc, value, type); fields.put(fieldName, f); return; } } } Field f = new Field(fieldName, fieldDesc, value, type); fields.put(fieldName, f); if (isReturn) return; for (int i = 4; i < len; i++) { String cond = rule[i].trim().toLowerCase(); if (cond.startsWith("email")) { if (value != null) { String v = getCondValue(cond); if (v.equals("true")) { if (!StrUtil.IsValidEmail(value)) { isValid = false; addMsg("err_email", new String[] {fieldDesc}); } } } } else if (cond.startsWith("isnotcn")) { if (value != null) { String v = getCondValue(cond); if (v.equals("true")) { if (!StrUtil.isNotCN(value)) { isValid = false; addMsg("err_cn", new String[] {fieldDesc}); } } } } else if (cond.startsWith("exclude")) { if (value != null) { String v = getCondValue(cond); String[] chars = StrUtil.split(v, "\\|");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -