Search in sources :

Example 21 with FieldConfigBean

use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.

the class EnumImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    if (val == null || !Validators.ENUM.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(Validators.ENUM);
    }
    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
    ParamConfigBean pcb = new ParamConfigBean();
    pcb.setName(Validators.ENUM_WORD_PARAM);
    StringBuilder sb = new StringBuilder();
    for (String s : ann.words()) {
        if (sb.length() > 0)
            sb.append("#");
        sb.append(CommonUtil.parsePropValue(s));
    }
    pcb.setValue(sb.toString());
    fcb.getParam().add(pcb);
    val.getField().add(fcb);
    return val;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Example 22 with FieldConfigBean

use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.

the class EqualsImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    if (val == null || !Validators.EQUALS.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(Validators.EQUALS);
    }
    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
    ParamConfigBean pcb = new ParamConfigBean();
    pcb.setName(Validators.EQUALS_TO_PARAM);
    String value = CommonUtil.parsePropValue(ann.to());
    value = fieldName.substring(0, fieldName.lastIndexOf(".") + 1) + value;
    pcb.setValue(value);
    fcb.getParam().add(pcb);
    val.getField().add(fcb);
    return val;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Example 23 with FieldConfigBean

use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.

the class ForbidImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    if (val == null || !Validators.FORBID.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(Validators.FORBID);
    }
    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
    ParamConfigBean pcb = new ParamConfigBean();
    pcb.setName(Validators.FORBID_WORD_PARAM);
    StringBuilder sb = new StringBuilder();
    for (String s : ann.words()) {
        if (sb.length() > 0)
            sb.append("#");
        sb.append(CommonUtil.parsePropValue(s));
    }
    pcb.setValue(sb.toString());
    fcb.getParam().add(pcb);
    val.getField().add(fcb);
    return val;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Example 24 with FieldConfigBean

use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.

the class DateValidator method validate.

public Validation validate(ValidatorConfigBean val, Context context) {
    Map<String, String> valError = new HashMap<String, String>();
    for (FieldConfigBean f : val.getField()) {
        String[] value = context.getQueryParamMap().get(f.getName());
        if (value == null || value.length == 0)
            continue;
        String mess = f.getMessage();
        param: for (ParamConfigBean p : f.getParam()) {
            if (!Validators.DATE_FORMAT_PARAM.equalsIgnoreCase(p.getName()))
                continue;
            String paramValue = p.getValue();
            mess = mess.replace("{format}", paramValue);
            DateFormat df = new SimpleDateFormat(paramValue);
            for (String v : value) {
                try {
                    df.parse(v);
                } catch (Exception e) {
                    valError.put(f.getName(), mess);
                    break param;
                }
            }
        }
        context.getRequest().setAttribute(f.getName(), value);
    }
    Validation validation = new Validation();
    if (!valError.isEmpty())
        validation.getErrors().put(val.getName(), valError);
    return validation;
}
Also used : Validation(org.eweb4j.mvc.action.Validation) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) HashMap(java.util.HashMap) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 25 with FieldConfigBean

use of org.eweb4j.mvc.config.bean.FieldConfigBean in project eweb4j-framework by laiweiwei.

the class ForbidWordValidator method validate.

public Validation validate(ValidatorConfigBean val, Context context) {
    Map<String, String> valError = new HashMap<String, String>();
    for (FieldConfigBean f : val.getField()) {
        String[] value = context.getQueryParamMap().get(f.getName());
        if (value == null || value.length == 0)
            continue;
        String mess = f.getMessage();
        param: for (ParamConfigBean p : f.getParam()) {
            if (Validators.FORBID_WORD_PARAM.equalsIgnoreCase(p.getName())) {
                String[] forbidWord = p.getValue().split("#");
                if (forbidWord == null || forbidWord.length == 0)
                    continue;
                boolean flag = false;
                for (String v : value) {
                    for (String word : forbidWord) {
                        if (v.indexOf(word) != -1) {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                        continue;
                    valError.put(f.getName(), mess.replace("{words}", p.getValue()));
                    break param;
                }
            }
        }
        context.getRequest().setAttribute(f.getName(), value);
    }
    Validation validation = new Validation();
    if (!valError.isEmpty())
        validation.getErrors().put(val.getName(), valError);
    return validation;
}
Also used : Validation(org.eweb4j.mvc.action.Validation) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) HashMap(java.util.HashMap) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Aggregations

FieldConfigBean (org.eweb4j.mvc.config.bean.FieldConfigBean)32 ValidatorConfigBean (org.eweb4j.mvc.config.bean.ValidatorConfigBean)21 ParamConfigBean (org.eweb4j.mvc.config.bean.ParamConfigBean)19 HashMap (java.util.HashMap)11 Validation (org.eweb4j.mvc.action.Validation)11 ActionConfigBean (org.eweb4j.mvc.config.bean.ActionConfigBean)2 ResultConfigBean (org.eweb4j.mvc.config.bean.ResultConfigBean)2 UploadFile (org.eweb4j.mvc.upload.UploadFile)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 ConfigBean (org.eweb4j.config.bean.ConfigBean)1 LogConfigBean (org.eweb4j.config.bean.LogConfigBean)1 IOCConfigBean (org.eweb4j.ioc.config.bean.IOCConfigBean)1 InterConfigBean (org.eweb4j.mvc.config.bean.InterConfigBean)1 ORMConfigBean (org.eweb4j.orm.config.bean.ORMConfigBean)1 DBInfoConfigBean (org.eweb4j.orm.dao.config.bean.DBInfoConfigBean)1