Search in sources :

Example 11 with ValidatorConfigBean

use of org.eweb4j.mvc.config.bean.ValidatorConfigBean 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;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Example 12 with ValidatorConfigBean

use of org.eweb4j.mvc.config.bean.ValidatorConfigBean 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;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) ParamConfigBean(org.eweb4j.mvc.config.bean.ParamConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Example 13 with ValidatorConfigBean

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

the class UrlImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    if (val == null || !Validators.URL.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(Validators.URL);
    }
    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
    val.getField().add(fcb);
    return val;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Example 14 with ValidatorConfigBean

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

the class ZipImpl method create.

public ValidatorConfigBean create(String fieldName, ValidatorConfigBean val) {
    if (this.ann == null)
        return null;
    if (val == null || !Validators.ZIP.equals(val.getName())) {
        val = new ValidatorConfigBean();
        val.setName(Validators.ZIP);
    }
    FieldConfigBean fcb = new FieldConfigBean();
    fcb.setName(fieldName);
    fcb.setMessage(CommonUtil.parsePropValue(ann.mess()));
    val.getField().add(fcb);
    return val;
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) FieldConfigBean(org.eweb4j.mvc.config.bean.FieldConfigBean)

Example 15 with ValidatorConfigBean

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

the class ActionAnnotationConfig method handleActionConfigInfo.

/**
	 * 处理Action配置信息
	 * 
	 * @param ru
	 * @param controller
	 * @param method
	 * @param moduleName
	 */
private void handleActionConfigInfo(ReflectUtil ru, Class<?> controller, Method method, String moduleName) {
    //log.debug("now parse the method...... moduleName->" + moduleName);
    // 这一步解析约定好的方法名doXxxAtXxx
    final ActionConfigBean action = parseUriMappingSuffix(moduleName, method);
    //log.debug("parse uri mapping by default rule -> " + action);
    if (action == null)
        return;
    action.setClazz(controller.getName());
    action.setMethod(method.getName());
    /* 解析出验证器错误信息输出类型 */
    //		action.setShowValErrorType(parseShowValErrType(controller, method));
    /* 解析出Http Method */
    String httpMethod = parseHttpMethodByAnnotation(controller, method);
    // 如果方法上的注解不为空则覆盖约定好的
    if (httpMethod != null && httpMethod.trim().length() > 0)
        action.setHttpMethod(httpMethod);
    //log.debug("parse httpMethod -> " + httpMethod);
    /* 解析出最终的uriMapping */
    String uriMapping = parseUriMapping(controller, moduleName, action.getUriMapping());
    //log.debug("parse uriMapping -> " + uriMapping);
    if (uriMapping != null && uriMapping.trim().length() > 0)
        action.setUriMapping(uriMapping);
    // 解析@Result注解
    Result resultAnn = method.getAnnotation(Result.class);
    if (resultAnn != null)
        action.getResult().addAll(ResultAnnUtil.readResultAnn(resultAnn));
    /* 解析@ActionLevel */
    int level = parseActionLevel(controller, method);
    action.setLevel(String.valueOf(level));
    /* 解析@Produces */
    List<String> pcbs = parseProduces(method);
    if (pcbs != null)
        action.getProduces().addAll(pcbs);
    /* 解析@Validator和各种验证器 */
    List<ValidatorConfigBean> vals = parseValidators(ru, method);
    if (vals != null)
        action.getValidator().addAll(vals);
    /* 解析最终的actionKey (包括合并http method、正则等) */
    String actionConfigKey = parseFullUriMapping(controller, method, action.getHttpMethod(), action.getUriMapping());
    //log.debug("parse actionConfigKey -> " + actionConfigKey);
    if (actionConfigKey == null)
        return;
    // 将读取成功的配置信息放入缓存供框架运行期使用
    //log.debug("action cache add key -> "+actionConfigKey + ", action->"  + action);
    ActionConfigBeanCache.add(actionConfigKey, action);
    ActionClassCache.add(action.getClazz(), controller);
}
Also used : ValidatorConfigBean(org.eweb4j.mvc.config.bean.ValidatorConfigBean) ActionConfigBean(org.eweb4j.mvc.config.bean.ActionConfigBean) Result(org.eweb4j.mvc.action.annotation.Result)

Aggregations

ValidatorConfigBean (org.eweb4j.mvc.config.bean.ValidatorConfigBean)25 FieldConfigBean (org.eweb4j.mvc.config.bean.FieldConfigBean)21 ParamConfigBean (org.eweb4j.mvc.config.bean.ParamConfigBean)11 ArrayList (java.util.ArrayList)3 ActionConfigBean (org.eweb4j.mvc.config.bean.ActionConfigBean)3 ResultConfigBean (org.eweb4j.mvc.config.bean.ResultConfigBean)2 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConfigBean (org.eweb4j.config.bean.ConfigBean)1 LogConfigBean (org.eweb4j.config.bean.LogConfigBean)1 IOCConfigBean (org.eweb4j.ioc.config.bean.IOCConfigBean)1 Validation (org.eweb4j.mvc.action.Validation)1 Result (org.eweb4j.mvc.action.annotation.Result)1 InterConfigBean (org.eweb4j.mvc.config.bean.InterConfigBean)1 Skip (org.eweb4j.mvc.validator.annotation.Skip)1 Validate (org.eweb4j.mvc.validator.annotation.Validate)1 ORMConfigBean (org.eweb4j.orm.config.bean.ORMConfigBean)1 DBInfoConfigBean (org.eweb4j.orm.dao.config.bean.DBInfoConfigBean)1