use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.
the class PhoneImpl method create.
public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
if (this.ann == null)
return null;
if (val == null || !Validators.PHONE.equals(val.getName())) {
val = new ValidatorConfigBean();
val.setName(Validators.PHONE);
}
FieldConfigBean fcb = new FieldConfigBean();
fcb.setName(fieldName);
fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
val.getField().add(fcb);
return val;
}
use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.
the class RegexImpl method create.
public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
if (this.ann == null)
return null;
if (val == null || !Validators.REGEX.equals(val.getName())) {
val = new ValidatorConfigBean();
val.setName(Validators.REGEX);
}
FieldConfigBean fcb = new FieldConfigBean();
fcb.setName(fieldName);
fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
ParamConfigBean pcb = new ParamConfigBean();
pcb.setName(Validators.REGEX_PARAM);
pcb.setValue(CommonUtil.parsePropValue(ann.pattern()));
fcb.getParam().add(pcb);
val.getField().add(fcb);
return val;
}
use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.
the class TestValidator method validate.
public Validation validate(ValidatorConfigBean val, Context context) {
Map<String, String> errMap = new HashMap<String, String>();
for (FieldConfigBean fcb : val.getField()) {
// 比如我现在验证 "name"参数值不能出现 "中国" 字眼
String key = fcb.getName();
// 这个是封装了request请求传过来的参数map
String value = context.getQueryParamMap().get(key)[0];
if (value.indexOf("中国") != -1)
errMap.put(key, fcb.getMessage());
}
Validation validation = new Validation();
validation.getErrors().put(val.getName(), errMap);
return validation;
}
use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.
the class EmailImpl method create.
public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
if (this.ann == null)
return null;
if (val == null || !Validators.EMAIL.equals(val.getName())) {
val = new ValidatorConfigBean();
val.setName(Validators.EMAIL);
}
FieldConfigBean fcb = new FieldConfigBean();
fcb.setName(fieldName);
fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
val.getField().add(fcb);
return val;
}
use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.
the class UploadImpl method create.
public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
if (this.ann == null)
return null;
if (val == null || !Validators.UPLOAD.equals(val.getName())) {
val = new ValidatorConfigBean();
val.setName(Validators.UPLOAD);
}
FieldConfigBean fcb = new FieldConfigBean();
fcb.setName(fieldName);
ParamConfigBean suffix = new ParamConfigBean();
suffix.setName(Validators.UPLOAD_SUFFIX);
StringBuilder sb = new StringBuilder();
for (String s : ann.suffix()) {
if (sb.length() > 0)
sb.append(",");
sb.append(CommonUtil.parsePropValue(s));
}
suffix.setValue(sb.toString());
fcb.getParam().add(suffix);
ParamConfigBean suffixMsg = new ParamConfigBean();
suffixMsg.setName(Validators.UPLOAD_SUFFIX_MSG);
suffixMsg.setValue(CommonUtil.parsePropValue(ann.msg().suffix()));
fcb.getParam().add(suffixMsg);
ParamConfigBean maxFileSize = new ParamConfigBean();
maxFileSize.setName(Validators.UPLOAD_MAX_FILE_SIZE);
maxFileSize.setValue(CommonUtil.parsePropValue(ann.maxFileSize()));
fcb.getParam().add(maxFileSize);
ParamConfigBean maxFileSizeMsg = new ParamConfigBean();
maxFileSizeMsg.setName(Validators.UPLOAD_MAX_FILE_SIZE_MSG);
maxFileSizeMsg.setValue(CommonUtil.parsePropValue(ann.msg().maxFileSize()));
fcb.getParam().add(maxFileSizeMsg);
ParamConfigBean maxMemorySize = new ParamConfigBean();
maxMemorySize.setName(Validators.UPLOAD_MAX_MEMORY_SIZE);
maxMemorySize.setValue(CommonUtil.parsePropValue(ann.maxMemorySize()));
fcb.getParam().add(maxMemorySize);
ParamConfigBean maxMemorySizeMsg = new ParamConfigBean();
maxMemorySizeMsg.setName(Validators.UPLOAD_MAX_MEMORY_SIZE_MSG);
maxMemorySizeMsg.setValue(CommonUtil.parsePropValue(ann.msg().maxMemorySize()));
fcb.getParam().add(maxMemorySizeMsg);
ParamConfigBean maxRequestSize = new ParamConfigBean();
maxRequestSize.setName(Validators.UPLOAD_MAX_REQ_SIZE);
maxRequestSize.setValue(CommonUtil.parsePropValue(ann.maxRequestSize()));
fcb.getParam().add(maxRequestSize);
ParamConfigBean maxRequestSizeMsg = new ParamConfigBean();
maxRequestSizeMsg.setName(Validators.UPLOAD_MAX_REQ_SIZE_MSG);
maxRequestSizeMsg.setValue(CommonUtil.parsePropValue(ann.msg().maxRequestSize()));
fcb.getParam().add(maxRequestSizeMsg);
ParamConfigBean tmpDir = new ParamConfigBean();
tmpDir.setName(Validators.UPLOAD_TMP_DIR);
tmpDir.setValue(CommonUtil.parsePropValue(ann.tmpDir()));
fcb.getParam().add(tmpDir);
val.getField().add(fcb);
return val;
}
Aggregations