Example usage for org.apache.commons.validator ValidatorResources ValidatorResources

List of usage examples for org.apache.commons.validator ValidatorResources ValidatorResources

Introduction

In this page you can find the example usage for org.apache.commons.validator ValidatorResources ValidatorResources.

Prototype

public ValidatorResources() 

Source Link

Document

Create an empty ValidatorResources object.

Usage

From source file:jp.terasoluna.fw.web.struts.form.FieldChecksExTest06.java

/**
 * testValidateArraysIndex31()//  w  w  w  . jav  a2  s  .  c om
 * <br><br>
 *
 * (??n)
 * <br>
 * _?FF
 * <br><br>
 * l?F(?) bean:*<br>
 *         (?) va:methodParams?F6S??<br>
 *                name?F"requiredArray"<br>
 *         (?) field:property="/"<br>
 *                arg:position="0",key="##INDEX",<br>
 *                  resource="false"<br>
 *                msg:key="requiredArray",name="requiredArray"<br>
 *         (?) errors:not null<br>
 *                (vf)<br>
 *         (?) validator:not null<br>
 *         (?) request:ANVtH?[?F"logon"<br>
 *         (?) session:L?[?F"logon"l<br>
 *                ActionFormIuWFNg<br>
 *         (?) ActionForm:DynaValidatorActionFormExCX^X<br>
 *                ArrayList<JavaBean> rowList<br>
 *                 + rowList[0]<br>
 *                     + Map map = { key = null }<br>
 *                 + rowList[1]<br>
 *                     + Map map = { key = null }<br>
 *                 + rowList[2]<br>
 *                     + Map map = { key = null }<br>
 *         (?) ?bZ?[W\?[X:message={0}<br>
 *
 * <br>
 * l?F(l) boolean:true<br>
 *         (?) ?O:?Ox?FG?[
 *                         O?FIllegalArgumentException
 *                               "Invalid character has found within property name. '/' Cannot use [ / \" ' ]"
 *
 * <br>
 * s?v?peBw???AG?[?O?o?AtruemF?B
 * <br>
 *
 * @throws Exception ?\bh?O
 */
@SuppressWarnings({ "deprecation", "unchecked" })
public void testValidateArraysIndex31() throws Exception {
    //eXgf?[^?
    this.formEx = (DynaValidatorActionFormEx) creator.create(CONFIG_FILE_NAME);
    // ++++ beanIuWFNg ++++
    String bean = null;

    // ++++ ??IuWFNg
    ValidatorAction va = new ValidatorAction();
    va.setMethodParams(this.validClassStr);
    va.setName("requiredArray");

    // ++++ ?tB?[h?
    Field field = new Field();
    field.setProperty("/");
    Var var = new Var();
    field.addVar(var);
    Arg arg0 = new Arg();
    arg0.setPosition(0);
    arg0.setKey("##INDEX");
    arg0.setResource(false);
    field.addArg(arg0);
    Msg msg = new Msg();
    msg.setKey("requiredArray");
    msg.setName("requiredArray");
    field.addMsg(msg);
    UTUtil.invokePrivate(field, "process", Map.class, Map.class, new HashMap(), new HashMap());

    // G?[?
    ActionMessages errors = new ActionMessages();
    // [HTTPNGXg
    FieldChecksEx_HttpServletRequestImpl01 request = new FieldChecksEx_HttpServletRequestImpl01();
    ActionMappingEx mapping = new ActionMappingEx();
    mapping.setName("logon");
    request.setAttribute(Globals.MAPPING_KEY, mapping);
    MockHttpSession session = new MockHttpSession();
    List rowList = new ArrayList();
    FieldChecksEx_JavaBeanStub01 row = new FieldChecksEx_JavaBeanStub01();
    Map map = new HashMap();
    map.put("key", null);
    row.map = map;
    rowList.add(row);
    row = new FieldChecksEx_JavaBeanStub01();
    map = new HashMap();
    map.put("key", null);
    row.map = map;
    rowList.add(row);
    row = new FieldChecksEx_JavaBeanStub01();
    map = new HashMap();
    map.put("key", null);
    row.map = map;
    rowList.add(row);
    formEx.set("rowList", rowList);

    session.setAttribute("logon", formEx);
    request.setSession(session);

    FieldChecksEx_MessageResourcesImpl01 messageResources = new FieldChecksEx_MessageResourcesImpl01(null,
            null);
    messageResources.message = "{0}";
    request.setAttribute(Globals.MESSAGES_KEY, messageResources);

    // ValidatorResourcesCX^X
    ValidatorResources validatorResources = new ValidatorResources();
    // ValidatorCX^X
    Validator validator = new Validator(validatorResources);

    // eXg?s
    boolean result = FieldChecksEx.validateArraysIndex(bean, va, field, errors, validator, request);
    // eXgmF
    // truep?B
    assertTrue(result);
    // G?[?O
    assertTrue(LogUTUtil.checkError("", new IllegalArgumentException(
            "Invalid character has found " + "within property name. '/' Cannot use [ / \" ' ]")));

}

From source file:org.seasar.struts.lessconfig.autoregister.impl.StrutsConfigRegisterImpl.java

private void registerValidations(ModuleConfig config) {
    // Create Forms.
    ValidatorResources currentResources = getValidatorResources(config);
    FormSet formSet = new FormSet();

    FormBeanConfig[] formConfigs = config.findFormBeanConfigs();
    for (int i = 0; i < formConfigs.length; i++) {
        if (!registeredValidation(currentResources, formConfigs[i])) {
            Class clazz = ClassUtil.forName(formConfigs[i].getType());
            String name = formConfigs[i].getName();
            Form form = this.validationCreator.createForm(config, clazz, name);
            if (form != null) {
                formSet.addForm(form);/* w  ww .  j  a  v  a  2 s  . com*/

                if (log.isDebugEnabled()) {
                    log.debug("auto register " + form);
                }
            }
        }
    }

    // Initialize ValidatorResources
    if (formSet.getForms().size() != 0) {
        ValidatorResources resources = new ValidatorResources();
        resources.addFormSet(formSet);
        resources.process();
        addValidatorResources(config, resources);
    }
}

From source file:org.seasar.struts.lessconfig.hotdeploy.OndemandGetFormInterceptor.java

public Object invoke(MethodInvocation invocation) throws Throwable {
    String formKey;//from   w w w .  j  a va 2 s.  c om
    if (invocation.getArguments().length == 2) {
        formKey = (String) invocation.getArguments()[1];
    } else {
        formKey = (String) invocation.getArguments()[3];
    }
    if (formKey == null) {
        return invocation.proceed();
    }

    ModuleConfig config = ModuleUtils.getInstance().getModuleConfig(S2StrutsContextUtil.getRequest());
    Form form = this.validationCreator.createForm(config, formKey);
    if (form != null) {
        if (log.isDebugEnabled()) {
            log.debug("auto create " + form);
        }

        // initialize form...
        ValidatorResources resources = new ValidatorResources();
        FormSet formSet = new FormSet();
        formSet.addForm(form);
        resources.addFormSet(formSet);
        resources.process();
        // ...initialized form

        return form;
    }
    return invocation.proceed();
}