📄 paramchecker.java~2~
字号:
try {
max = DateUtil.parse(strMax, format,
SkinUtil.getLocale(request));
}
catch (Exception e) {
addMsg("err_format", new String[] {strMax});
}
if (max!=null) {
if (DateUtil.compare(d, max) == 2 ||
DateUtil.compare(d, max) == 0)
;
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(5, cond.length()).
trim();
try {
Date max = null;
try {
max = DateUtil.parse(strMax, format,
SkinUtil.getLocale(request));
}
catch (Exception e) {
addMsg("err_format", new String[] {strMax});
}
if (max!=null) {
if (DateUtil.compare(d, max) == 2)
;
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 checkFieldLong(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);
checkFieldLong(ruleStr, value);
}
public void checkFieldLong(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];
// String value = getFieldValue(fieldName);
Long longValue = null;
if (value == null) {
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(8, NULL.length());
String[] ary = s.split("\\$");
try {
ISequence is = (ISequence)Class.forName(ary[0]).newInstance();
int typeId = Integer.parseInt(ary[1]);
longValue = new Long(is.getNextId(typeId));
}
catch (Exception e) {
addMsg("err_format", new String[] {e.getMessage()});
return;
}
} else {
try {
long v = Long.parseLong(NULL);
longValue = new Long(v);
}
catch (Exception e) {
addMsg("err_format", new String[] {NULL});
return;
}
}
}
else {
try {
long v = Long.parseLong(value);
longValue = new Long(v);
} catch (Exception e) {
addMsg("err_format", new String[] {NULL});
return;
}
}
// 存储field值
Field f = new Field(fieldName, fieldDesc, longValue, type);
fields.put(fieldName, f);
boolean isValid = true;
// 规则部分,以类似email=true的方式
for (int i = 4; i < len; i++) {
String cond = rule[i].trim();
if (cond.startsWith("min")) {
if (value != null) {
long fieldValue = longValue.longValue();
// 取出符号
char token = cond.charAt(3);
if (token == '>') {
if (cond.charAt(4) == '=') {
String strMin = cond.substring(5, cond.length()).
trim();
try {
long min = Long.parseLong(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 {
long min = Long.parseLong(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) {
long fieldValue = longValue.longValue();
char token = cond.charAt(3);
// 取出符号
if (token == '<') {
if (cond.charAt(4) == '=') {
String strMax = cond.substring(5, cond.length()).
trim();
try {
long max = Long.parseLong(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 {
long max = Long.parseLong(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) {
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 = (int)is.getNextId(typeId);
}
catch (Exception e) {
logger.error("checkFieldInt1:" + StrUtil.trace(e));
addMsg("err_format", new String[] {e.getMessage()});
return;
}
}
else {
try {
int v = Integer.parseInt(NULL);
intValue = new Integer(v);
}
catch (Exception e) {
addMsg("err_format", new String[] {NULL});
return;
}
}
}
else {
try {
int v = Integer.parseInt(value);
intValue = new Integer(v);
} catch (Exception e) {
addMsg("err_format", new String[] {NULL});
return;
}
}
// 存储field值
Field f = new Field(fieldName, fieldDesc, intValue, type);
fields.put(fieldName, f);
boolean isValid = true;
// 规则部分,以类似email=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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -