Package org.apache.commons.validator

Examples of org.apache.commons.validator.ValidatorResources


    public static ValidatorResources getValidatorResources()
    {
        final FacesContext context = FacesContext.getCurrentInstance();
        final ExternalContext external = context.getExternalContext();
        final Map applicationMap = external.getApplicationMap();
        ValidatorResources validatorResources = (ValidatorResources)applicationMap.get(VALIDATOR_RESOURCES_KEY);
        if (validatorResources == null)
        {
            final String rulesResource = RULES_LOCATION;
            final String validationResource = "/WEB-INF/validation.xml";
            final InputStream rulesInput = external.getResourceAsStream(rulesResource);
            if (rulesInput == null)
            {
                throw new JSFValidatorException("Could not find rules file '" + rulesResource + "'");
            }
            final InputStream validationInput = external.getResourceAsStream(validationResource);
            if (validationInput != null)
            {
                final InputStream[] inputs = new InputStream[] {rulesInput, validationInput};
                try
                {
                    validatorResources = new ValidatorResources(inputs);
                    applicationMap.put(
                        VALIDATOR_RESOURCES_KEY,
                        validatorResources);
                }
                catch (final Throwable throwable)
View Full Code Here


            final EditableValueHolder valueHolder = (EditableValueHolder)component;
            if (form != null)
            {
                final String formId = form.getId();
                final String componentId = component.getId();
                final ValidatorResources resources = JSFValidator.getValidatorResources();
                if (resources != null)
                {
                    final Form validatorForm = resources.getForm(
                            Locale.getDefault(),
                            formId);
                    if (validatorForm != null)
                    {
                        final java.util.List validatorFields = validatorForm.getFields();
View Full Code Here

    }

    @Test
    public void testPluginDefault() {
        pluginInit();
        ValidatorResources res = CommonsValidatorWrapper
                .getValidatorResources();
        assertNotNull(res);

        pluginDestroy();
        res = CommonsValidatorWrapper.getValidatorResources();
View Full Code Here

        try {
            this.plugin.init(this.context, new HashMap<String, String>());
        } catch (PluginException e) {

            ValidatorResources res = CommonsValidatorWrapper
                    .getValidatorResources();
            assertNull(res);

            pluginDestroy();
            res = CommonsValidatorWrapper.getValidatorResources();
View Full Code Here

    return buildValidatorResources(DEF_FILE_PATH, DEF_MAPPINGS_FILE);
  }

  private ValidatorResources buildValidatorResources(final String filePath,
      final String mappingsFile) {
    ValidatorResources resources = null;
    try {
      CommonsValidatorWrapper.setFilePath(filePath);
      CommonsValidatorWrapper.setMappingsFile(mappingsFile);
      // CommonsValidatorWrapper.setRulesFile(rulesFile);
      CommonsValidatorWrapper.load(getContext());
View Full Code Here

  @SuppressWarnings("null")
  @Test
  public void testValidatorInitialization() {

    ValidatorResources resources = null;
    try {
      CommonsValidatorWrapper
          .setFilePath("/org/megatome/frame2/validator/config"); //$NON-NLS-1$
      CommonsValidatorWrapper.load(getContext());
      resources = CommonsValidatorWrapper.getValidatorResources();
      assertNotNull(resources);
    } catch (CommonsValidatorException e) {
      fail();
    }

    Form f = resources.getForm(new Locale("EN"), "ValidateBean"); //$NON-NLS-1$ //$NON-NLS-2$
    assertNotNull(f);

  }
View Full Code Here

    if (in == null) {
      // validatorResources = null;
      throw new CommonsValidatorException("invalid filePath: " + filePath); //$NON-NLS-1$
    }
    try {
      validatorResources = new ValidatorResources(in);
    } catch (IOException e) {
      validatorResources = null;
      throw new CommonsValidatorException(e);
    } catch (SAXException e) {
      validatorResources = null;
View Full Code Here

        // Look up this key to see if its a field of the current form
        boolean requiredField = false;
        boolean validationError = false;

        ValidatorResources resources = getValidatorResources();

        Locale locale = pageContext.getRequest().getLocale();

        if (locale == null) {
            locale = Locale.getDefault();
        }

        // get the name of the bean from the key
        String formName = key.substring(0, key.indexOf('.'));
        String fieldName = key.substring(formName.length() + 1);

        if (resources != null) {
            Form form = resources.getForm(locale, formName);

            if (form != null) {
                Field field = form.getField(fieldName);

                if (field != null) {
View Full Code Here

            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) {
View Full Code Here

        validator.setValidatorFactory(factory);
        return validator;
    }

    private Validator getCommonsValidator() {
        ValidatorResources res = new ValidatorResources();
        res.process();
        return new Validator(res);
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.validator.ValidatorResources

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.