/** * Load <code>ValidatorResources</code> from * validator-extension.xml. */ @Override protected void setUp() throws Exception { // Load resources InputStream in = null; try { in = this.getClass().getResourceAsStream("ExtensionTest-config.xml"); resources = new ValidatorResources(in); } finally { if (in != null) { in.close(); } } }
/** * Load <code>ValidatorResources</code> from multiple xml files. */ @Override protected void setUp() throws IOException, SAXException { InputStream[] streams = new InputStream[] { this.getClass().getResourceAsStream( "RetrieveFormTest-config.xml")}; this.resources = new ValidatorResources(streams); for (int i = 0; i < streams.length; i++) { streams[i].close(); } }
/** * Load <code>ValidatorResources</code> from * validator-numeric.xml. */ protected void loadResources(String file) throws IOException, SAXException { // Load resources InputStream in = null; try { in = this.getClass().getResourceAsStream(file); resources = new ValidatorResources(in); } finally { if (in != null) { in.close(); } } } }
/** * Load <code>ValidatorResources</code> from multiple xml files. */ @Override protected void setUp() throws IOException, SAXException { InputStream[] streams = new InputStream[] { this.getClass().getResourceAsStream( "MultipleConfigFilesTest-1-config.xml"), this.getClass().getResourceAsStream( "MultipleConfigFilesTest-2-config.xml")}; this.resources = new ValidatorResources(streams); for (int i = 0; i < streams.length; i++) { streams[i].close(); } }
/** * Test null Input Stream for Validator Resources. */ public void testNullInputStream() throws Exception { try { new ValidatorResources((InputStream)null); fail("Expected IllegalArgumentException"); } catch(IllegalArgumentException e) { // expected result // System.out.println("Exception: " + e); } }
/** * Tests the entity import loading the <code>byteForm</code> form. */ public void testEntityImport() throws Exception { URL url = getClass().getResource("EntityImportTest-config.xml"); ValidatorResources resources = new ValidatorResources(url.toExternalForm()); assertNotNull("Form should be found", resources.getForm(Locale.getDefault(), "byteForm")); }
/** * Tests loading ValidatorResources from a URL */ public void testParseURL() throws Exception { URL url = getClass().getResource("EntityImportTest-config.xml"); ValidatorResources resources = new ValidatorResources(url); assertNotNull("Form should be found", resources.getForm(Locale.getDefault(), "byteForm")); } }
ValidatorResources resources = new ValidatorResources();
private ValidatorResources setupDateResources(String property, String action) { ValidatorResources resources = new ValidatorResources(); ValidatorAction va = new ValidatorAction(); va.setName(action); va.setClassname("org.apache.commons.validator.ValidatorTest"); va.setMethod("formatDate"); va.setMethodParams("java.lang.Object,org.apache.commons.validator.Field"); FormSet fs = new FormSet(); Form form = new Form(); form.setName("testForm"); Field field = new Field(); field.setProperty(property); field.setDepends(action); form.addField(field); fs.addForm(form); resources.addValidatorAction(va); resources.addFormSet(fs); resources.process(); return resources; }
this.resources = new ValidatorResources(urlArray); } catch (SAXException sex) { log.error("Skipping all validation", sex);
getResourceAsStream(this.rulesFile); this.validatorResources = new ValidatorResources(is);
this.resources = new ValidatorResources(streamArray); } catch (SAXException sex) { log.error("Skipping all validation",sex);
/** * Gets and/or initializes validatorResources before returning it. Init- * ialization is expensive so only perform it if necessary. * Note: (1) CALLER's responsibility to close InputStream. * (2) XML Resources always looked for in same package as Bean. **/ private void setValidatorResources (String resourceName, Object bean, InputStream in) throws IOException, SAXException { if (getResourceName()==null || !getResourceName().equals(resourceName)) { // remember this resource setResourceName(resourceName); // Read in the XMLfile in = bean.getClass().getResourceAsStream(resourceName); // create a new "validator" resources object. This thing contains // FormSets stored against locale. _validatorResources = new ValidatorResources(in); } }
/** * Sets the locations of the validation configuration files from which to load validation rules. Creates an instance * of <code>ValidatorResources</code> from the specified configuration files. * * @see org.springframework.core.io.Resource * @see ValidatorResources */ public void setValidationConfigLocations(Resource[] validationConfigLocations) { if (DefaultValidatorFactory.log.isInfoEnabled()) { DefaultValidatorFactory.log.info("Loading validation configurations from [" + StringUtils.arrayToCommaDelimitedString(validationConfigLocations) + "]"); } try { InputStream[] inputStreams = new InputStream[validationConfigLocations.length]; for (int i = 0; i < inputStreams.length; i++) { inputStreams[i] = validationConfigLocations[i].getInputStream(); } this.validatorResources = new ValidatorResources(inputStreams); } catch (IOException e) { throw new FatalBeanException("Unable to read validation configuration due to IOException.", e); } catch (SAXException e) { throw new FatalBeanException("Unable to parse validation configuration XML", e); } }
return new ValidatorResources(urlArray); } catch (SAXException sex) { log.error("Skipping all validation", sex);
resources = new ValidatorResources(urlArray); } catch (SAXException sex) { LOG.error("Skipping all validation", sex);
try validatorResources = new ValidatorResources(inputs); applicationMap.put( VALIDATOR_RESOURCES_KEY,
resources = new ValidatorResources(in);
public Object invoke(MethodInvocation invocation) throws Throwable { String formKey; 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(); }
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); 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); } }