struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-struts/src/share/org/apache/struts/util StrutsValidator.java
Date Fri, 19 Jul 2002 04:02:06 GMT
craigmcc    2002/07/18 21:02:06

  Modified:    .        STATUS
               src/share/org/apache/struts/util StrutsValidator.java
  Log:
  Make StrutsValidator validators work with indexed string values.
  
  PR: Bugzilla #10919
  Submitted by:	James Turner <turner at blackbear.com>
                  Thanks for the patch!
  
  Revision  Changes    Path
  1.31      +2 -3      jakarta-struts/STATUS
  
  Index: STATUS
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/STATUS,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- STATUS	19 Jul 2002 03:30:19 -0000	1.30
  +++ STATUS	19 Jul 2002 04:02:05 -0000	1.31
  @@ -6,7 +6,7 @@
               OUTSTANDING BUGS IN STRUTS 1.1-b1 AND NIGHTLY BUILDS
               ====================================================
   
  -                           20 open bugs to swat!!
  +                           18 open bugs to swat!!
   
   
   Controller:
  @@ -65,7 +65,6 @@
   10584 Not all validation files are read in Validation PlugIn
   10782 If two fields are required, and one has a mask, the mask is not checked if the other
field is blank
   10868 Validator  does not support non-default resource bundles
  -10919 PATCH: ValidatorUtils can't handle StringArrays
   
   
   Web Site:
  
  
  
  1.5       +126 -39   jakarta-struts/src/share/org/apache/struts/util/StrutsValidator.java
  
  Index: StrutsValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/StrutsValidator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StrutsValidator.java	30 Jun 2002 03:28:46 -0000	1.4
  +++ StrutsValidator.java	19 Jul 2002 04:02:06 -0000	1.5
  @@ -101,19 +101,24 @@
                                  ActionErrors errors,
                                              HttpServletRequest request) {
   
  -       String value = null;
  -       if (field.getProperty() != null && field.getProperty().length() > 0)
  -          value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  -
  -       if (GenericValidator.isBlankOrNull(value)) {
  -          errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
  +        String value = null;
  +        if (isString(bean)) {
  +            value = (String) bean;
  +        } else {
  +            value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +        }
  +        if (GenericValidator.isBlankOrNull(value)) {
  +            errors.add(field.getKey(),
  +                       StrutsValidatorUtil.getActionError(request, va, field));
  +            
  +            return false;
  +        } else {
  +            return true;
  +        }
   
  -          return false;
  -       } else {
  -          return true;
  -       }
       }
   
  +
       /**
        * <p>Checks if the field matches the regular expression in the field's mask
attribute.</p>
        *
  @@ -130,25 +135,30 @@
                              ActionErrors errors,
                                          HttpServletRequest request) {
   
  -         String mask = field.getVarValue("mask");
  -
  -     if (field.getProperty() != null && field.getProperty().length() > 0) {
  -        String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  -
  -            try {
  -           if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.matchRegexp(value,
mask)) {
  -              errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va,
field));
  -
  -                  return false;
  -               } else {
  -                  return true;
  -               }
  +        String mask = field.getVarValue("mask");
  +        String value = null;
  +        if (isString(bean)) {
  +            value = (String) bean;
  +        } else {
  +            value = ValidatorUtil.getValueAsString(bean,
  +                                                   field.getProperty());
  +        }
  +        try {
  +            if (!GenericValidator.isBlankOrNull(value) &&
  +                !GenericValidator.matchRegexp(value, mask)) {
  +                errors.add(field.getKey(),
  +                           StrutsValidatorUtil.getActionError(request, va,
  +                                                              field));
  +                
  +                return false;
  +            } else {
  +                return true;
  +            }
           } catch (Exception e) {
  -           LOG.error(e.getMessage(), e);
  +            LOG.error(e.getMessage(), e);
           }
  -         }
  +        return true;
   
  -         return true;
       }
   
   
  @@ -169,7 +179,12 @@
                                       HttpServletRequest request) {
   
          Byte result = null;
  -       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       String value = null;
  +       if (isString(bean)) {
  +           value = (String) bean;
  +       } else {
  +           value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       }
   
          if (!GenericValidator.isBlankOrNull(value)) {
             result = GenericTypeValidator.formatByte(value);
  @@ -198,7 +213,12 @@
                             ActionErrors errors,
                                         HttpServletRequest request) {
          Short result = null;
  -       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       String value = null;
  +       if (isString(bean)) {
  +           value = (String) bean;
  +       } else {
  +           value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       }
   
          if (!GenericValidator.isBlankOrNull(value)) {
             result = GenericTypeValidator.formatShort(value);
  @@ -227,7 +247,12 @@
                                 ActionErrors errors,
                                             HttpServletRequest request) {
          Integer result = null;
  -       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       String value = null;
  +       if (isString(bean)) {
  +           value = (String) bean;
  +       } else {
  +           value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       }
   
          if (!GenericValidator.isBlankOrNull(value)) {
             result = GenericTypeValidator.formatInt(value);
  @@ -256,7 +281,12 @@
                           ActionErrors errors,
                                       HttpServletRequest request) {
          Long result = null;
  -       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       String value = null;
  +       if (isString(bean)) {
  +           value = (String) bean;
  +       } else {
  +           value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       }
   
          if (!GenericValidator.isBlankOrNull(value)) {
             result = GenericTypeValidator.formatLong(value);
  @@ -285,7 +315,12 @@
                             ActionErrors errors,
                                         HttpServletRequest request) {
          Float result = null;
  -       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       String value = null;
  +       if (isString(bean)) {
  +           value = (String) bean;
  +       } else {
  +           value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       }
   
          if (!GenericValidator.isBlankOrNull(value)) {
             result = GenericTypeValidator.formatFloat(value);
  @@ -314,7 +349,12 @@
                               ActionErrors errors,
                                           HttpServletRequest request) {
          Double result = null;
  -       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       String value = null;
  +       if (isString(bean)) {
  +           value = (String) bean;
  +       } else {
  +           value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       }
   
          if (!GenericValidator.isBlankOrNull(value)) {
             result = GenericTypeValidator.formatDouble(value);
  @@ -350,8 +390,13 @@
                           ActionErrors errors,
                                       HttpServletRequest request) {
   
  -    Date result = null;
  -        String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +        Date result = null;
  +        String value = null;
  +        if (isString(bean)) {
  +            value = (String) bean;
  +        } else {
  +           value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +        }
           String datePattern = field.getVarValue("datePattern");
           String datePatternStrict = field.getVarValue("datePatternStrict");
           Locale locale = StrutsValidatorUtil.getLocale(request);
  @@ -397,7 +442,12 @@
                               ActionErrors errors,
                                           HttpServletRequest request) {
   
  -       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       String value = null;
  +       if (isString(bean)) {
  +           value = (String) bean;
  +       } else {
  +           value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       }
          String sMin = field.getVarValue("min");
          String sMax = field.getVarValue("max");
   
  @@ -440,7 +490,12 @@
                                                HttpServletRequest request) {
   
          Long result = null;
  -       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       String value = null;
  +       if (isString(bean)) {
  +           value = (String) bean;
  +       } else {
  +           value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       }
   
          if (!GenericValidator.isBlankOrNull(value)) {
             result = GenericTypeValidator.formatCreditCard(value);
  @@ -471,7 +526,12 @@
                               ActionErrors errors,
                                           HttpServletRequest request) {
   
  -       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       String value = null;
  +       if (isString(bean)) {
  +           value = (String) bean;
  +       } else {
  +           value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       }
   
          if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.isEmail(value))
{
             errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
  @@ -498,7 +558,12 @@
                                   ActionErrors errors,
                                               HttpServletRequest request) {
   
  -       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       String value = null;
  +       if (isString(bean)) {
  +           value = (String) bean;
  +       } else {
  +           value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       }
          String sMaxLength = field.getVarValue("maxlength");
   
          if (value != null) {
  @@ -537,7 +602,12 @@
                                   ActionErrors errors,
                                               HttpServletRequest request) {
   
  -       String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       String value = null;
  +       if (isString(bean)) {
  +           value = (String) bean;
  +       } else {
  +           value = ValidatorUtil.getValueAsString(bean, field.getProperty());
  +       }
          String sMinLength = field.getVarValue("minlength");
   
          if (value != null) {
  @@ -557,5 +627,22 @@
   
          return true;
       }
  +
  +
  +    /**
  +     * <p>Return <code>true</code> if the specified object is a String
or
  +     * a <code>null</code> value.</p>
  +     *
  +     * @param o Object to be tested
  +     */
  +    private static boolean isString(Object o) {
  +
  +        if (o == null) {
  +            return (true);
  +        }
  +        return (String.class.isInstance(o));
  +
  +    }
  +
   
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:struts-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-dev-help@jakarta.apache.org>


Mime
View raw message