You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by se...@apache.org on 2003/11/10 04:39:36 UTC

cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/intake/validator DateStringValidator.java

seade       2003/11/09 19:39:36

  Modified:    src/java/org/apache/turbine/services/intake/validator
                        DateStringValidator.java
  Log:
  Add back the changes wiped out by Eric's last commit.
  
  Revision  Changes    Path
  1.13      +26 -9     jakarta-turbine-2/src/java/org/apache/turbine/services/intake/validator/DateStringValidator.java
  
  Index: DateStringValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/intake/validator/DateStringValidator.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DateStringValidator.java	14 Oct 2003 12:17:25 -0000	1.12
  +++ DateStringValidator.java	10 Nov 2003 03:39:36 -0000	1.13
  @@ -77,7 +77,7 @@
    * <td>&nbsp;</td></tr>
    * <tr><td>formatx</td><td>see SimpleDateFormat javadoc</td>
    * <td>&nbsp;</td></tr>
  - * <tr><td colspan=3>where x is &gt;= 0 to specify multiple date
  + * <tr><td colspan=3>where x is &gt;= 1 to specify multiple date
    *         formats.  Only one format rule should have a message</td></tr>
    * <tr><td>flexible</td><td>true, as long as DateFormat can parse the date,
    *                            allow it, and false</td>
  @@ -89,6 +89,7 @@
    * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
    * @author <a href="mailto:Colin.Chalmers@maxware.nl">Colin Chalmers</a>
    * @author <a href="mailto:jh@byteaction.de">J&uuml;rgen Hoffmann</a>
  + * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
    * @version $Id$
    */
   public class DateStringValidator
  @@ -170,15 +171,15 @@
               flexible = Boolean.valueOf(constraint.getValue()).booleanValue();
           }
   
  -        if (dateFormats.size() == 0 || flexible)
  +        if (dateFormats.size() == 0)
           {
               df = DateFormat.getInstance();
  -            df.setLenient(true);
  +            df.setLenient(flexible);
           }
  -
  -        if (dateFormats.size() != 0)
  +        else
           {
               sdf = new SimpleDateFormat();
  +            sdf.setLenient(flexible);
           }
       }
   
  @@ -210,8 +211,11 @@
       }
   
       /**
  -     * Parses the String s according to the rules/formats for this
  -     * validator.
  +     * Parses the String s according to the rules/formats for this validator.  
  +     * The formats provided by the "formatx" rules (where x is &gt;= 1) are 
  +     * used <strong>before</strong> the "format" rules to allow for a display 
  +     * format that includes a 4 digit year, but that will parse the date using
  +     * a format that accepts 2 digit years.
        *
        * @throws ParseException indicates that the string could not be
        * parsed into a date.
  @@ -226,7 +230,7 @@
               throw new ParseException("Input string was null", -1);
           }
   
  -        for (int i = 0; i < dateFormats.size() && date == null; i++)
  +        for (int i = 1; i < dateFormats.size() && date == null; i++)
           {
               sdf.applyPattern((String) dateFormats.get(i));
   
  @@ -238,7 +242,20 @@
               {
                   // ignore
               }
  +        }
  +
  +        if (date == null)
  +        {
  +            sdf.applyPattern((String) dateFormats.get(0));
   
  +            try
  +            {
  +                date = sdf.parse(s);
  +            }
  +            catch (ParseException e)
  +            {
  +                // ignore
  +            }
           }
   
           if (date == null && df != null)
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


RE: cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/intake/validator DateStringValidator.java

Posted by Eric Pugh <ep...@upstate.com>.
Oops..  Sorray about that..  I appreciate the updates to the fulcrum tree as
well..  I guess this is the kinda thing that more unit tests would catch..
when you accidentally regress something.   I'll keep a better eye on the
diffs...

Eric

> -----Original Message-----
> From: seade@apache.org [mailto:seade@apache.org]
> Sent: Monday, November 10, 2003 4:40 AM
> To: jakarta-turbine-2-cvs@apache.org
> Subject: cvs commit:
> jakarta-turbine-2/src/java/org/apache/turbine/services/intake/
> validator
> DateStringValidator.java
>
>
> seade       2003/11/09 19:39:36
>
>   Modified:    src/java/org/apache/turbine/services/intake/validator
>                         DateStringValidator.java
>   Log:
>   Add back the changes wiped out by Eric's last commit.
>
>   Revision  Changes    Path
>   1.13      +26 -9
> jakarta-turbine-2/src/java/org/apache/turbine/services/intake/
> validator/DateStringValidator.java
>
>   Index: DateStringValidator.java
>   ===================================================================
>   RCS file:
> /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/servic
> es/intake/validator/DateStringValidator.java,v
>   retrieving revision 1.12
>   retrieving revision 1.13
>   diff -u -r1.12 -r1.13
>   --- DateStringValidator.java	14 Oct 2003 12:17:25
> -0000	1.12
>   +++ DateStringValidator.java	10 Nov 2003 03:39:36
> -0000	1.13
>   @@ -77,7 +77,7 @@
>     * <td>&nbsp;</td></tr>
>     * <tr><td>formatx</td><td>see SimpleDateFormat javadoc</td>
>     * <td>&nbsp;</td></tr>
>   - * <tr><td colspan=3>where x is &gt;= 0 to specify multiple date
>   + * <tr><td colspan=3>where x is &gt;= 1 to specify multiple date
>     *         formats.  Only one format rule should have a
> message</td></tr>
>     * <tr><td>flexible</td><td>true, as long as DateFormat
> can parse the date,
>     *                            allow it, and false</td>
>   @@ -89,6 +89,7 @@
>     * @author <a href="mailto:quintonm@bellsouth.net">Quinton
> McCombs</a>
>     * @author <a
> href="mailto:Colin.Chalmers@maxware.nl">Colin Chalmers</a>
>     * @author <a href="mailto:jh@byteaction.de">J&uuml;rgen
> Hoffmann</a>
>   + * @author <a
> href="mailto:seade@backstagetech.com.au">Scott Eade</a>
>     * @version $Id$
>     */
>    public class DateStringValidator
>   @@ -170,15 +171,15 @@
>                flexible =
> Boolean.valueOf(constraint.getValue()).booleanValue();
>            }
>
>   -        if (dateFormats.size() == 0 || flexible)
>   +        if (dateFormats.size() == 0)
>            {
>                df = DateFormat.getInstance();
>   -            df.setLenient(true);
>   +            df.setLenient(flexible);
>            }
>   -
>   -        if (dateFormats.size() != 0)
>   +        else
>            {
>                sdf = new SimpleDateFormat();
>   +            sdf.setLenient(flexible);
>            }
>        }
>
>   @@ -210,8 +211,11 @@
>        }
>
>        /**
>   -     * Parses the String s according to the rules/formats for this
>   -     * validator.
>   +     * Parses the String s according to the rules/formats
> for this validator.
>   +     * The formats provided by the "formatx" rules (where
> x is &gt;= 1) are
>   +     * used <strong>before</strong> the "format" rules to
> allow for a display
>   +     * format that includes a 4 digit year, but that will
> parse the date using
>   +     * a format that accepts 2 digit years.
>         *
>         * @throws ParseException indicates that the string
> could not be
>         * parsed into a date.
>   @@ -226,7 +230,7 @@
>                throw new ParseException("Input string was null", -1);
>            }
>
>   -        for (int i = 0; i < dateFormats.size() && date ==
> null; i++)
>   +        for (int i = 1; i < dateFormats.size() && date ==
> null; i++)
>            {
>                sdf.applyPattern((String) dateFormats.get(i));
>
>   @@ -238,7 +242,20 @@
>                {
>                    // ignore
>                }
>   +        }
>   +
>   +        if (date == null)
>   +        {
>   +            sdf.applyPattern((String) dateFormats.get(0));
>
>   +            try
>   +            {
>   +                date = sdf.parse(s);
>   +            }
>   +            catch (ParseException e)
>   +            {
>   +                // ignore
>   +            }
>            }
>
>            if (date == null && df != null)
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org