You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ni...@apache.org on 2006/01/19 07:38:52 UTC

svn commit: r370397 [1/4] - in /jakarta/commons/proper/validator/trunk: ./ src/share/org/apache/commons/validator/routines/ src/test/org/apache/commons/validator/routines/

Author: niallp
Date: Wed Jan 18 22:38:24 2006
New Revision: 370397

URL: http://svn.apache.org/viewcvs?rev=370397&view=rev
Log:
Add new routines package containing standard validations - first step in the process of clearly separating standard validation functions which can be used independantly, from the framework aspect of Commons Validator.

This initial step involves adding new and (hopefully) improved date and number validators. Improvements include:

* Factoring logic out of static methods into separate, extensible, validator classes
* Improved date validation (implements Bug 27414), including support for TimeZones and date comparison functions (provides Bug 31874).
* New Calendar and Time validators added.
* Improved number validation, providing "pattern" validation for standard types (i.e. Byte, Integer etc)
* New validators for BigDecimal and BigInteger types.
* New validators for Percentage amd Currency formats.

Added:
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractCalendarValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractFormatValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractNumberValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigDecimalValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigIntegerValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ByteValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CalendarValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CurrencyValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DateValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/DoubleValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/FloatValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/IntegerValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/LongValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/PercentValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ShortValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/TimeValidator.java   (with props)
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/package.html   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseCalendarValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BaseNumberValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigDecimalValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/BigIntegerValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/ByteValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CalendarValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/CurrencyValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DateValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/DoubleValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/FloatValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/IntegerValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/LongValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/PercentValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/RoutinesTestSuite.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/ShortValidatorTest.java   (with props)
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/routines/TimeValidatorTest.java   (with props)
Modified:
    jakarta/commons/proper/validator/trunk/project.xml

Modified: jakarta/commons/proper/validator/trunk/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/project.xml?rev=370397&r1=370396&r2=370397&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/project.xml (original)
+++ jakarta/commons/proper/validator/trunk/project.xml Wed Jan 18 22:38:24 2006
@@ -356,6 +356,7 @@
     <unitTest>
       <includes>
         <include>**/ValidatorTestSuite.java</include>
+        <include>**/RoutinesTestSuite.java</include>
       </includes>
       <resources>
         <resource>

Added: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractCalendarValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractCalendarValidator.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractCalendarValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractCalendarValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,393 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.text.Format;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * <p>Abstract class for Date/Time/Calendar validation.</p>
+ * 
+ * <p>This is a <i>base</i> class for building Date / Time
+ *    Validators using format parsing.</p>
+ *    
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public abstract class AbstractCalendarValidator extends AbstractFormatValidator {
+
+    private int dateStyle = -1;
+
+    private int timeStyle = -1;
+
+    /**
+     * Construct a <i>strict</i> instance with <i>short</i>
+     * date style.
+     */
+    public AbstractCalendarValidator() {
+        this(true, DateFormat.SHORT, -1);
+    }
+
+    /**
+     * Construct an instance with the specified <i>strict</i>, 
+     * <i>time</i> and <i>date</i> style parameters.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     * @param dateStyle the date style to use for Locale validation.
+     * @param timeStyle the time style to use for Locale validation.
+     */
+    public AbstractCalendarValidator(boolean strict, int dateStyle, int timeStyle) {
+        super(strict);
+        this.dateStyle = dateStyle;
+        this.timeStyle = timeStyle;
+    }
+
+    /**
+     * <p>Creates a <code>SimpleDateFormat</code> for the specified
+     *    pattern.</p>
+     * 
+     * <p>If no pattern is specified the default Locale is used
+     *    to determine the <code>DateFormat</code>.
+     * 
+     * @param pattern The pattern of the required the <code>DateFormat</code>.
+     * @return The <code>DateFormat</code> to created.
+     */
+    protected Format getFormat(String pattern) {
+
+        DateFormat formatter = null; 
+        if (pattern == null || pattern.length() == 0) {
+            formatter = (DateFormat)getFormat(Locale.getDefault());
+        } else {
+            formatter = new SimpleDateFormat(pattern);
+        }
+        formatter.setLenient(false);
+        return formatter;
+
+    }
+
+    /**
+     * <p>Returns a <code>DateFormat</code> for the specified Locale.</p>
+     * 
+     * @param locale The locale a <code>DateFormat</code> is required for,
+     *        system default if null.
+     * @return The <code>DateFormat</code> to created.
+     */
+    protected Format getFormat(Locale locale) {
+
+        if (locale == null) {
+            locale = Locale.getDefault();
+        }
+
+        DateFormat formatter = null; 
+        if (dateStyle >= 0 && timeStyle >= 0) {
+            formatter = DateFormat.getDateTimeInstance(dateStyle, timeStyle, locale);
+        } else if (timeStyle >= 0) {
+            formatter = DateFormat.getTimeInstance(timeStyle, locale);
+        } else if (dateStyle >= 0) {
+            formatter = DateFormat.getDateInstance(dateStyle, locale);
+        } else {
+            formatter = DateFormat.getDateInstance(DateFormat.SHORT, locale);
+        }
+        formatter.setLenient(false);
+        return formatter;
+
+    }
+
+    /**
+     * <p>Checks if the value is valid against a specified pattern.</p>
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @return The parsed value if valid or <code>null</code> if invalid.
+     */
+    protected Object validateObj(String value, String pattern) {
+        return validateObj(value, pattern, (TimeZone)null);
+    }
+
+    /**
+     * <p>Checks if the value is valid against a specified pattern.</p>
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @param timeZone The Time Zone used to parse the date, system default if null.
+     * @return The parsed value if valid or <code>null</code> if invalid.
+     */
+    protected Object validateObj(String value, String pattern, TimeZone timeZone) {
+
+        if (value == null || value.length() == 0) {
+            return null;
+        }
+        DateFormat formatter = (DateFormat)getFormat(pattern);
+        if (timeZone != null) {
+            formatter.setTimeZone(timeZone);
+        }
+        return parse(value, formatter);
+
+    }
+
+    /**
+     * <p>Checks if the value is valid for a specified <code>Locale</code>.</p>
+     *
+     * @param value The value validation is being performed on.
+     * @param locale The locale to use for the date format, system default if null.
+     * @return The parsed value if valid or <code>null</code> if invalid.
+     */
+    protected Object validateObj(String value, Locale locale) {
+        return validateObj(value, locale, (TimeZone)null);
+    }
+
+    /**
+     * <p>Checks if the value is valid for a specified <code>Locale</code>.</p>
+     *
+     * @param value The value validation is being performed on.
+     * @param locale The locale to use for the date format, system default if null.
+     * @param timeZone The Time Zone used to parse the date, system default if null.
+     * @return The parsed value if valid or <code>null</code> if invalid.
+     */
+    protected Object validateObj(String value, Locale locale, TimeZone timeZone) {
+
+        if (value == null || value.length() == 0) {
+            return null;
+        }
+        DateFormat formatter = (DateFormat)getFormat(locale);
+        if (timeZone != null) {
+            formatter.setTimeZone(timeZone);
+        }
+        return parse(value, formatter);
+
+    }
+
+    /**
+     * <p>Parse the value with the specified <code>Format</code>.</p>
+     * 
+     * @param value The value to be parsed.
+     * @param formatter The Format to parse the value with.
+     * @return The parsed value if valid or <code>null</code> if invalid.
+     */
+    protected Object parse(String value, Format formatter) {
+
+        Object parsedValue = super.parse(value, formatter);
+        if (parsedValue == null) {
+            return null;
+        }
+
+        // Process the Calendar, not the parsed Date object
+        Calendar calendar = ((DateFormat)formatter).getCalendar();
+        return processCalendar(calendar);
+
+    }
+
+    /**
+     * <p>Perform further validation and convert the <code>Calendar</code> to
+     * the appropriate type.</p>
+     * 
+     * @param calendar The calendar object create from the parsed value.
+     * @return The validated/converted <code>Calendar</code> value if valid 
+     * or <code>null</code> if invalid.
+     */
+    protected abstract Object processCalendar(Calendar calendar);
+
+    /**
+     * <p>Format a value with the specified <code>DateFormat</code>.</p>
+     * 
+     * @param value The value to be formatted.
+     * @param formatter The Format to use.
+     * @return The formatted value.
+     */
+    protected String format(Object value, Format formatter) {
+        if (value instanceof Calendar) {
+            value = ((Calendar)value).getTime(); 
+        }
+        return formatter.format(value);
+    }
+
+    /**
+     * <p>Compares a calendar value to another, indicating whether it is
+     *    equal, less then or more than at a specified level.</p>
+     * 
+     * @param value The Calendar value.
+     * @param compare The <code>Calendar</code> to check the value against.
+     * @param field The field <i>level</i> to compare to - e.g. specifying
+     *        <code>Calendar.MONTH</code> will compare the year and month
+     *        portions of the calendar. 
+     * @return Zero if the first value is equal to the second, -1
+     *         if it is less than the second or +1 if it is greater than the second.  
+     */
+    protected int compare(Calendar value, Calendar compare, int field) {
+
+        int result = 0;
+
+        // Compare Year
+        result = calculateCompareResult(value, compare, Calendar.YEAR);
+        if (result != 0 || field == Calendar.YEAR) {
+            return result;
+        }
+
+        // Compare Week of Year
+        if (field == Calendar.WEEK_OF_YEAR) {
+            return calculateCompareResult(value, compare, Calendar.WEEK_OF_YEAR);
+        }
+
+        // Compare Day of the Year
+        if (field == Calendar.DAY_OF_YEAR) {
+            return calculateCompareResult(value, compare, Calendar.DAY_OF_YEAR);
+        }
+
+        // Compare Month
+        result = calculateCompareResult(value, compare, Calendar.MONTH);
+        if (result != 0 || field == Calendar.MONTH) {
+            return result;
+        }
+
+        // Compare Week of Month
+        if (field == Calendar.WEEK_OF_MONTH) {
+            return calculateCompareResult(value, compare, Calendar.WEEK_OF_MONTH);
+        }
+
+        // Compare Date
+        result = calculateCompareResult(value, compare, Calendar.DATE);
+        if (result != 0 || (field == Calendar.DATE || 
+                          field == Calendar.DAY_OF_MONTH ||
+                          field == Calendar.DAY_OF_WEEK ||
+                          field == Calendar.DAY_OF_WEEK_IN_MONTH)) {
+            return result;
+        }
+
+        // Compare Time fields
+        return compareTime(value, compare, field);
+
+    }
+
+    /**
+     * <p>Compares a calendar time value to another, indicating whether it is
+     *    equal, less then or more than at a specified level.</p>
+     * 
+     * @param value The Calendar value.
+     * @param compare The <code>Calendar</code> to check the value against.
+     * @param field The field <i>level</i> to compare to - e.g. specifying
+     *        <code>Calendar.MINUTE</code> will compare the hours and minutes
+     *        portions of the calendar. 
+     * @return Zero if the first value is equal to the second, -1
+     *         if it is less than the second or +1 if it is greater than the second.  
+     */
+    protected int compareTime(Calendar value, Calendar compare, int field) {
+
+        int result = 0;
+
+        // Compare Hour
+        result = calculateCompareResult(value, compare, Calendar.HOUR_OF_DAY);
+        if (result != 0 || (field == Calendar.HOUR || field == Calendar.HOUR_OF_DAY)) {
+            return result;
+        }
+
+        // Compare Minute
+        result = calculateCompareResult(value, compare, Calendar.MINUTE);
+        if (result != 0 || field == Calendar.MINUTE) {
+            return result;
+        }
+
+        // Compare Second
+        result = calculateCompareResult(value, compare, Calendar.SECOND);
+        if (result != 0 || field == Calendar.SECOND) {
+            return result;
+        }
+
+        // Compare Milliseconds
+        if (field == Calendar.MILLISECOND) {
+            return calculateCompareResult(value, compare, Calendar.MILLISECOND);
+        }
+
+        throw new IllegalArgumentException("Invalid field: " + field);
+
+    }
+
+    /**
+     * <p>Compares a calendar's quarter value to another, indicating whether it is
+     *    equal, less then or more than the specified quarter.</p>
+     * 
+     * @param value The Calendar value.
+     * @param compare The <code>Calendar</code> to check the value against.
+     * @param monthOfFirstQuarter The  month that the first quarter starts.
+     * @return Zero if the first quarter is equal to the second, -1
+     *         if it is less than the second or +1 if it is greater than the second.  
+     */
+    protected int compareQuarters(Calendar value, Calendar compare, int monthOfFirstQuarter) {
+        int valueQuarter   = calculateQuarter(value, monthOfFirstQuarter);
+        int compareQuarter = calculateQuarter(compare, monthOfFirstQuarter);
+        if (valueQuarter < compareQuarter) {
+            return -1;
+        } else if (valueQuarter > compareQuarter) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+
+    /**
+     * <p>Calculate the quarter for the specified Calendar.</p>
+     * 
+     * @param calendar The Calendar value.
+     * @param monthOfFirstQuarter The  month that the first quarter starts.
+     * @return The calculated quarter.
+     */
+    private int calculateQuarter(Calendar calendar, int monthOfFirstQuarter) {
+        // Add Year
+        int year = calendar.get(Calendar.YEAR);
+
+        int month = (calendar.get(Calendar.MONTH) + 1);
+        int relativeMonth = (month >= monthOfFirstQuarter)
+                          ? (month - monthOfFirstQuarter)
+                          : (month + (12 - monthOfFirstQuarter));
+        int quarter = ((relativeMonth / 3) + 1);
+        // adjust the year if the quarter doesn't start in January
+        if (month < monthOfFirstQuarter) {
+            --year;
+        }
+        return (year * 10) + quarter;
+    }
+
+    /**
+     * <p>Compares the field from two calendars indicating whether the field for the
+     *    first calendar is equal to, less than or greater than the field from the
+     *    second calendar.
+     *    
+     * @param value The Calendar value.
+     * @param compare The <code>Calendar</code> to check the value against.
+     * @param field The field to compare for the calendars.
+     * @return Zero if the first calendar's field is equal to the seconds, -1
+     *         if it is less than the seconds or +1 if it is greater than the seconds.  
+     */
+    private int calculateCompareResult(Calendar value, Calendar compare, int field) {
+        int difference = value.get(field) - compare.get(field);
+        if (difference < 0) {
+            return -1;
+        } else if (difference > 0) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractCalendarValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractCalendarValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractFormatValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractFormatValidator.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractFormatValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractFormatValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,246 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.text.Format;
+import java.text.ParsePosition;
+import java.util.Locale;
+import java.io.Serializable;
+
+/**
+ * <p>Abstract class for <i>Format</i> based Validation.</p>
+ *
+ * <p>This is a <i>base</i> class for building Date and Number
+ *    Validators using format parsing.</p>
+ * 
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public abstract class AbstractFormatValidator implements Serializable {
+
+    private boolean strict = true;
+
+    /**
+     * Construct an instance with the specified strict setting.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     */
+    public AbstractFormatValidator(boolean strict) {
+        this.strict = strict;
+    }
+
+    /**
+     * <p>Indicates whether validated values should adhere
+     *    strictly to the <code>Format</code> used.</p>
+     * 
+     * <p>Typically implementations of <code>Format</code>
+     *    ignore invalid characters at the end of the value
+     *    and just stop parsing. For example parsing a date
+     *    value of <code>01/01/20x0</code> using a pattern
+     *    of <code>dd/MM/yyyy</code> will result in a year
+     *    of <code>20</code> if <code>strict</code> is set
+     *    to <code>false</code>, whereas setting <code>strict</code>
+     *    to <code>true</code> will cause this value to fail
+     *    validation.</p>
+     * 
+     * @return <code>true</code> if strict <code>Format</code>
+     *         parsing should be used.
+     */
+    public boolean isStrict() {
+        return strict;
+    }
+
+    /**
+     * <p>Validate using the default <code>Locale</code>. 
+     * 
+     * @param value The value validation is being performed on.
+     * @return <code>true</code> if the value is valid.
+     */
+    public boolean isValid(String value) {
+        Object parsedValue = validateObj(value);
+        return (parsedValue == null ? false : true);
+    }
+
+    /**
+     * <p>Validate using the specified <i>pattern</i>. 
+     * 
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @return <code>true</code> if the value is valid.
+     */
+    public boolean isValid(String value, String pattern) {
+        Object parsedValue = validateObj(value, pattern);
+        return (parsedValue == null ? false : true);
+    }
+
+    /**
+     * <p>Validate using the specified <code>Locale</code>. 
+     * 
+     * @param value The value validation is being performed on.
+     * @param locale The locale to use for the Format, defaults to the default
+     * @return <code>true</code> if the value is valid.
+     */
+    public boolean isValid(String value, Locale locale) {
+        Object parsedValue = validateObj(value, locale);
+        return (parsedValue == null ? false : true);
+    }
+
+    /**
+     * <p>Format an object into a <code>String</code> using
+     * the default Locale.</p>
+     *
+     * @param value The value validation is being performed on.
+     * @return The value formatted as a <code>String</code>.
+     */
+    public String format(Object value) {
+        return format(value, Locale.getDefault());
+    }
+
+    /**
+     * <p>Format an object into a <code>String</code> using
+     * the specified pattern.</p>
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to format the value.
+     * @return The value formatted as a <code>String</code>.
+     */
+    public String format(Object value, String pattern) {
+        Format formatter = getFormat(pattern);
+        return format(value, formatter);
+    }
+
+    /**
+     * <p>Format an object into a <code>String</code> using
+     * the specified Locale.</p>
+     *
+     * @param value The value validation is being performed on.
+     * @param locale The locale to use for the Format.
+     * @return The value formatted as a <code>String</code>.
+     */
+    public String format(Object value, Locale locale) {
+        Format formatter = getFormat(locale);
+        return format(value, formatter);
+    }
+
+    /**
+     * <p>Format a value with the specified <code>Format</code>.</p>
+     * 
+     * @param value The value to be formatted.
+     * @param formatter The Format to use.
+     * @return The formatted value.
+     */
+    protected String format(Object value, Format formatter) {
+        return formatter.format(value);
+    }
+
+    /**
+     * <p>Checks if the value is valid using the default Locale.</p>
+     *
+     * @param value The value validation is being performed on.
+     * @return The processed value if valid or <code>null</code> if invalid.
+     */
+    protected Object validateObj(String value) {
+        return validateObj(value, Locale.getDefault());
+    }
+
+    /**
+     * <p>Checks if the value is valid against a specified pattern.</p>
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @return The parsed value if valid or <code>null</code> if invalid.
+     */
+    protected Object validateObj(String value, String pattern) {
+
+        if (value == null || value.length() == 0) {
+            return null;
+        }
+        Format formatter = getFormat(pattern);
+        return parse(value, formatter);
+
+    }
+
+    /**
+     * <p>Checks if the value is valid for a specified <code>Locale</code>.</p>
+     *
+     * @param value The value validation is being performed on.
+     * @param locale The locale to use for the date format, defaults to the default
+     * system default if null.
+     * @return The parsed value if valid or <code>null</code> if invalid.
+     */
+    protected Object validateObj(String value, Locale locale) {
+
+        if (value == null || value.length() == 0) {
+            return null;
+        }
+        Format formatter = getFormat(locale);
+        return parse(value, formatter);
+
+    }
+
+    /**
+     * <p>Parse the value with the specified <code>Format</code>.</p>
+     * 
+     * @param value The value to be parsed.
+     * @param formatter The Format to parse the value with.
+     * @return The parsed value if valid or <code>null</code> if invalid.
+     */
+    protected Object parse(String value, Format formatter) {
+
+        String tempValue = (value == null ? null : value.trim());
+        if (tempValue == null || tempValue.length() == 0) {
+            return null;
+        }
+
+        ParsePosition pos = new ParsePosition(0);
+        Object parsedValue = formatter.parseObject(tempValue, pos);
+
+        if (pos.getErrorIndex() > -1) {
+            return null;
+        }
+
+        if (isStrict() && pos.getIndex() < tempValue.length()) {
+            return null;
+        }
+
+        return parsedValue;
+
+    }
+
+    /**
+     * <p>Returns a <code>Format</code> for the specified pattern.</p>
+     * 
+     * @param pattern The pattern of the required the <code>Format</code>.
+     * @return The <code>Format</code> to created.
+     */
+    protected abstract Format getFormat(String pattern);
+
+    /**
+     * <p>Returns a <code>Format</code> for the specified Locale.</p>
+     * 
+     * @param locale The locale a <code>Format</code> is required for,
+     *        defaults to the default
+     * @return The <code>Format</code> to created.
+     */
+    protected abstract Format getFormat(Locale locale);
+
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractFormatValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractFormatValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractNumberValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractNumberValidator.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractNumberValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractNumberValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,184 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.text.Format;
+import java.text.NumberFormat;
+import java.text.DecimalFormat;
+import java.util.Locale;
+
+/**
+ * <p>Abstract class for Number Validation.</p>
+ *
+ * <p>This is a <i>base</i> class for building Number
+ *    Validators using format parsing.</p>
+ *    
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public abstract class AbstractNumberValidator extends AbstractFormatValidator {
+
+    private boolean decimal;
+
+    /**
+     * Construct a <i>strict</i> instance for <i>decimal</i>
+     * formats.
+     */
+    public AbstractNumberValidator() {
+        this(true, true);
+    }
+
+    /**
+     * Construct an instance with specified <i>strict</i>
+     * and <i>decimal</i> parameters.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     * @param decimal Set whether this validator handlers decimal
+     * values (or only integer numbers).
+     */
+    public AbstractNumberValidator(boolean strict, boolean decimal) {
+        super(strict);
+        this.decimal = decimal;
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(Number value, Number min, Number max) {
+        return (minValue(value, min) && maxValue(value, max));
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(Number value, Number min) {
+        if (decimal) {
+            return (value.doubleValue() >= min.doubleValue());
+        } else {
+            return (value.longValue() >= min.longValue());
+        }
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(Number value, Number max) {
+        if (decimal) {
+            return (value.doubleValue() <= max.doubleValue());
+        } else {
+            return (value.longValue() <= max.longValue());
+        }
+    }
+
+    /**
+     * <p>Creates a <code>DecimalFormat</code> for the specified
+     *    pattern.</p>
+     * 
+     * <p>If no pattern is specified the default Locale is used
+     *    to determine the <code>NumberFormat</code>.
+     * 
+     * @param pattern The pattern of the required the <code>DecimalFormat</code>.
+     * @return The <code>NumberFormat</code> to created.
+     */
+    protected Format getFormat(String pattern) {
+
+        NumberFormat formatter = null;
+        if (pattern == null || pattern.length() == 0) {
+            formatter = (NumberFormat)getFormat(Locale.getDefault());
+        } else {
+            formatter = new DecimalFormat(pattern);
+        }
+        if (isStrict() && !decimal) {
+            formatter.setParseIntegerOnly(true);
+        }
+        return formatter;
+
+    }
+
+    /**
+     * <p>Returns a <code>NumberFormat</code> for the specified Locale.</p>
+     * 
+     * @param locale The locale a <code>NumberFormat</code> is required
+     *        for, defaults to the default.
+     * @return The <code>NumberFormat</code> to created.
+     */
+    protected Format getFormat(Locale locale) {
+
+        if (locale == null) {
+            locale = Locale.getDefault();
+        }
+
+        NumberFormat formatter = NumberFormat.getInstance(locale);
+        if (isStrict() && !decimal) {
+            formatter.setParseIntegerOnly(true);
+        }
+
+        return formatter;
+
+    }
+
+    /**
+     * <p>Parse the value with the specified <code>NumberFormat</code>.</p>
+     * 
+     * @param value The value to be parsed.
+     * @param formatter The Format to parse the value with.
+     * @return The parsed value if valid or <code>null</code> if invalid.
+     */
+    protected Object parse(String value, Format formatter) {
+
+        Number number = (Number)super.parse(value, formatter);
+        if (number == null) {
+            return null;
+        }
+
+        // Process the parsed Number
+        return processNumber(number);
+
+    }
+
+    /**
+     * <p>Perform further validation and convert the <code>Number</code> to
+     * the appropriate type.</p>
+     * 
+     * @param number The number object created from the parsed value.
+     * @return The validated/converted <code>Number</code> value if valid 
+     * or <code>null</code> if invalid.
+     */
+    protected abstract Object processNumber(Number number);
+
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractNumberValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/AbstractNumberValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigDecimalValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigDecimalValidator.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigDecimalValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigDecimalValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,184 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.math.BigDecimal;
+import java.util.Locale;
+
+/**
+ * <p><b>BigDecimal Validation</b> and Conversion routines (<code>java.math.BigDecimal</code>).</p>
+ *
+ * <p>This validator provides a number of methods for
+ *    validating/converting a <code>String</code> value to
+ *    a <code>BigDecimal</code> using <code>java.text.NumberFormat</code>
+ *    to parse either:</p>
+ *    <ul>
+ *       <li>using a specified pattern</li>
+ *       <li>using the format for a specified <code>Locale</code></li>
+ *       <li>using the format for the <i>default</i> <code>Locale</code></li>
+ *    </ul>
+ *    
+ * <p>Use one of the <code>isValid()</code> methods to just validate or
+ *    one of the <code>validate()</code> methods to validate and receive a
+ *    <i>converted</i> <code>BigDecimal</code> value.</p>
+ * 
+ * <p>Once a value has been sucessfully converted the following
+ *    methods can be used to perform minimum, maximum and range checks:</p>
+ *    <ul>
+ *       <li><code>minValue()</code> checks whether the value is greater
+ *           than or equal to a specified minimum.</li>
+ *       <li><code>maxValue()</code> checks whether the value is less
+ *           than or equal to a specified maximum.</li>
+ *       <li><code>isInRange()</code> checks whether the value is within
+ *           a specified range of values.</li>
+ *    </ul>
+ * 
+ * <p>So that the same mechanism used for parsing an <i>input</i> value 
+ *    for validation can be used to format <i>output</i>, corresponding
+ *    <code>format()</code> methods are also provided. That is you can 
+ *    format either:</p>
+ *    <ul>
+ *       <li>using a specified pattern</li>
+ *       <li>using the format for a specified <code>Locale</code></li>
+ *       <li>using the format for the <i>default</i> <code>Locale</code></li>
+ *    </ul>
+ * 
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class BigDecimalValidator extends AbstractNumberValidator {
+
+    private static final BigDecimalValidator VALIDATOR = new BigDecimalValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the BigDecimalValidator.
+     */
+    public static BigDecimalValidator getInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance.
+     */
+    public BigDecimalValidator() {
+        this(true);
+    }
+
+    /**
+     * Construct an instance with the specified strict setting.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     */
+    public BigDecimalValidator(boolean strict) {
+        super(strict, true);
+    }
+
+    /**
+     * <p>Validate/convert a <code>BigDecimal</code> using the default
+     *    <code>Locale</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @return The parsed <code>BigDecimal</code> if valid or <code>null</code>
+     *  if invalid.
+     */
+    public BigDecimal validate(String value) {
+        return (BigDecimal)validateObj(value);
+    }
+
+    /**
+     * <p>Validate/convert a <code>BigDecimal</code> using the
+     *    specified <i>pattern</i>. 
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @return The parsed <code>BigDecimal</code> if valid or <code>null</code> if invalid.
+     */
+    public BigDecimal validate(String value, String pattern) {
+        return (BigDecimal)validateObj(value, pattern);
+    }
+
+    /**
+     * <p>Validate/convert a <code>BigDecimal</code> using the
+     *    specified <code>Locale</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @param locale The locale to use for the date format, defaults to the default
+     * system default if null.
+     * @return The parsed <code>BigDecimal</code> if valid or <code>null</code> if invalid.
+     */
+    public BigDecimal validate(String value, Locale locale) {
+        return (BigDecimal)validateObj(value, locale);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(BigDecimal value, double min, double max) {
+        return (value.doubleValue() >= min && value.doubleValue() <= max);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(BigDecimal value, double min) {
+        return (value.doubleValue() >= min);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(BigDecimal value, double max) {
+        return (value.doubleValue() <= max);
+    }
+
+    /**
+     * Returns the parsed number un-changed.
+     * 
+     * @param number The number validation is being performed on.
+     * @return The validated/converted <code>BigDecimal</code> value if valid 
+     * or <code>null</code> if invalid.
+     */
+    protected Object processNumber(Number number) {
+        if (number instanceof Long) {
+            return BigDecimal.valueOf(number.longValue());
+        } else {
+            return new BigDecimal(number.toString());
+        }
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigDecimalValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigDecimalValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigIntegerValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigIntegerValidator.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigIntegerValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigIntegerValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,183 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.math.BigInteger;
+import java.util.Locale;
+
+/**
+ * <p><b>BigInteger Validation</b> and Conversion routines (<code>java.math.BigInteger</code>).</p>
+ *
+ * <p>This validator provides a number of methods for
+ *    validating/converting a <code>String</code> value to
+ *    a <code>BigInteger</code> using <code>java.text.NumberFormat</code>
+ *    to parse either:</p>
+ *    <ul>
+ *       <li>using a specified pattern</li>
+ *       <li>using the format for a specified <code>Locale</code></li>
+ *       <li>using the format for the <i>default</i> <code>Locale</code></li>
+ *    </ul>
+ *    
+ * <p>Use one of the <code>isValid()</code> methods to just validate or
+ *    one of the <code>validate()</code> methods to validate and receive a
+ *    <i>converted</i> <code>BigInteger</code> value.</p>
+ * 
+ * <p>Once a value has been sucessfully converted the following
+ *    methods can be used to perform minimum, maximum and range checks:</p>
+ *    <ul>
+ *       <li><code>minValue()</code> checks whether the value is greater
+ *           than or equal to a specified minimum.</li>
+ *       <li><code>maxValue()</code> checks whether the value is less
+ *           than or equal to a specified maximum.</li>
+ *       <li><code>isInRange()</code> checks whether the value is within
+ *           a specified range of values.</li>
+ *    </ul>
+ * 
+ * <p>So that the same mechanism used for parsing an <i>input</i> value 
+ *    for validation can be used to format <i>output</i>, corresponding
+ *    <code>format()</code> methods are also provided. That is you can 
+ *    format either:</p>
+ *    <ul>
+ *       <li>using a specified pattern</li>
+ *       <li>using the format for a specified <code>Locale</code></li>
+ *       <li>using the format for the <i>default</i> <code>Locale</code></li>
+ *    </ul>
+ *
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class BigIntegerValidator extends AbstractNumberValidator {
+
+    private static final BigIntegerValidator VALIDATOR = new BigIntegerValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the BigIntegerValidator.
+     */
+    public static BigIntegerValidator getInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance.
+     */
+    public BigIntegerValidator() {
+        this(true);
+    }
+
+    /**
+     * Construct an instance with the specified strict setting.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     */
+    public BigIntegerValidator(boolean strict) {
+        super(strict, false);
+    }
+
+    /**
+     * <p>Validate/convert a <code>BigInteger</code> using the default
+     *    <code>Locale</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @return The parsed <code>BigInteger</code> if valid or <code>null</code>
+     *  if invalid.
+     */
+    public BigInteger validate(String value) {
+        return (BigInteger)validateObj(value);
+    }
+
+    /**
+     * <p>Validate/convert a <code>BigInteger</code> using the
+     *    specified <i>pattern</i>. 
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @return The parsed <code>BigInteger</code> if valid or <code>null</code> if invalid.
+     */
+    public BigInteger validate(String value, String pattern) {
+        return (BigInteger)validateObj(value, pattern);
+    }
+
+    /**
+     * <p>Validate/convert a <code>BigInteger</code> using the
+     *    specified <code>Locale</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @param locale The locale to use for the date format, defaults to the default
+     * system default if null.
+     * @return The parsed <code>BigInteger</code> if valid or <code>null</code> if invalid.
+     */
+    public BigInteger validate(String value, Locale locale) {
+        return (BigInteger)validateObj(value, locale);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(BigInteger value, long min, long max) {
+        return (value.longValue() >= min && value.longValue() <= max);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(BigInteger value, long min) {
+        return (value.longValue() >= min);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(BigInteger value, long max) {
+        return (value.longValue() <= max);
+    }
+
+    /**
+     * <p>Perform further validation and convert the <code>Number</code> to
+     * a <code>BigInteger</code>.</p>
+     * 
+     * @param number The number validation is being performed on.
+     * @return The validated/converted <code>BigInteger</code> value if valid 
+     * or <code>null</code> if invalid.
+     */
+    protected Object processNumber(Number number) {
+
+        return BigInteger.valueOf(number.longValue());
+
+    }
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigIntegerValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/BigIntegerValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ByteValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ByteValidator.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ByteValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ByteValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,230 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.util.Locale;
+
+/**
+ * <p><b>Byte Validation</b> and Conversion routines (<code>java.lang.Byte</code>).</p>
+ *
+ * <p>This validator provides a number of methods for
+ *    validating/converting a <code>String</code> value to
+ *    a <code>Byte</code> using <code>java.text.NumberFormat</code>
+ *    to parse either:</p>
+ *    <ul>
+ *       <li>using a specified pattern</li>
+ *       <li>using the format for a specified <code>Locale</code></li>
+ *       <li>using the format for the <i>default</i> <code>Locale</code></li>
+ *    </ul>
+ *    
+ * <p>Use one of the <code>isValid()</code> methods to just validate or
+ *    one of the <code>validate()</code> methods to validate and receive a
+ *    <i>converted</i> <code>Byte</code> value.</p>
+ * 
+ * <p>Once a value has been sucessfully converted the following
+ *    methods can be used to perform minimum, maximum and range checks:</p>
+ *    <ul>
+ *       <li><code>minValue()</code> checks whether the value is greater
+ *           than or equal to a specified minimum.</li>
+ *       <li><code>maxValue()</code> checks whether the value is less
+ *           than or equal to a specified maximum.</li>
+ *       <li><code>isInRange()</code> checks whether the value is within
+ *           a specified range of values.</li>
+ *    </ul>
+ * 
+ * <p>So that the same mechanism used for parsing an <i>input</i> value 
+ *    for validation can be used to format <i>output</i>, corresponding
+ *    <code>format()</code> methods are also provided. That is you can 
+ *    format either:</p>
+ *    <ul>
+ *       <li>using a specified pattern</li>
+ *       <li>using the format for a specified <code>Locale</code></li>
+ *       <li>using the format for the <i>default</i> <code>Locale</code></li>
+ *    </ul>
+ *
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class ByteValidator extends AbstractNumberValidator {
+
+    private static final ByteValidator VALIDATOR = new ByteValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the ByteValidator.
+     */
+    public static ByteValidator getInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance.
+     */
+    public ByteValidator() {
+        this(true);
+    }
+
+    /**
+     * Construct an instance with the specified strict setting.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     */
+    public ByteValidator(boolean strict) {
+        super(strict, false);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Byte</code> using the default
+     *    <code>Locale</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @return The parsed <code>Byte</code> if valid or <code>null</code>
+     *  if invalid.
+     */
+    public Byte validate(String value) {
+        return (Byte)validateObj(value);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Byte</code> using the
+     *    specified <i>pattern</i>. 
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @return The parsed <code>Byte</code> if valid or <code>null</code> if invalid.
+     */
+    public Byte validate(String value, String pattern) {
+        return (Byte)validateObj(value, pattern);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Byte</code> using the
+     *    specified <code>Locale</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @param locale The locale to use for the date format, defaults to the default
+     * system default if null.
+     * @return The parsed <code>Byte</code> if valid or <code>null</code> if invalid.
+     */
+    public Byte validate(String value, Locale locale) {
+        return (Byte)validateObj(value, locale);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(byte value, byte min, byte max) {
+        return (value >= min && value <= max);
+    }
+
+    /**
+     * Check if the value is within a specified range.
+     * 
+     * @param value The <code>Number</code> value to check.
+     * @param min The minimum value of the range.
+     * @param max The maximum value of the range.
+     * @return <code>true</code> if the value is within the
+     *         specified range.
+     */
+    public boolean isInRange(Byte value, byte min, byte max) {
+        return isInRange(value.byteValue(), min, max);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(byte value, byte min) {
+        return (value >= min);
+    }
+
+    /**
+     * Check if the value is greater than or equal to a minimum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param min The minimum value.
+     * @return <code>true</code> if the value is greater than
+     *         or equal to the minimum.
+     */
+    public boolean minValue(Byte value, byte min) {
+        return minValue(value.byteValue(), min);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(byte value, byte max) {
+        return (value <= max);
+    }
+
+    /**
+     * Check if the value is less than or equal to a maximum.
+     * 
+     * @param value The value validation is being performed on.
+     * @param max The maximum value.
+     * @return <code>true</code> if the value is less than
+     *         or equal to the maximum.
+     */
+    public boolean maxValue(Byte value, byte max) {
+        return maxValue(value.byteValue(), max);
+    }
+
+    /**
+     * <p>Perform further validation and convert the <code>Number</code> to
+     * a <code>Byte</code>.</p>
+     * 
+     * @param number The number validation is being performed on.
+     * @return The validated/converted <code>Byte</code> value if valid 
+     * or <code>null</code> if invalid.
+     */
+    protected Object processNumber(Number number) {
+
+        long longValue = number.longValue();
+
+        if (longValue < Byte.MIN_VALUE) {
+            return null;
+        }
+
+        if (longValue > Byte.MAX_VALUE) {
+            return null;
+        }
+
+        return new Byte(number.byteValue());
+
+    }
+
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ByteValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/ByteValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CalendarValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CalendarValidator.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CalendarValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CalendarValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,307 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * <p><b>Calendar Validation</b> and Conversion routines (<code>java.util.Calendar</code>).</p>
+ *
+ * <p>This validator provides a number of methods for
+ *    validating/converting a <code>String</code> value to
+ *    a <code>Calendar</code> using <code>java.text.DateFormat</code>
+ *    to parse either:</p>
+ *    <ul>
+ *       <li>using a specified pattern</li>
+ *       <li>using the format for a specified <code>Locale</code></li>
+ *       <li>using the format for the <i>default</i> <code>Locale</code></li>
+ *    </ul>
+ *
+ * <p>Use one of the <code>isValid()</code> methods to just validate or
+ *    one of the <code>validate()</code> methods to validate and receive a
+ *    <i>converted</i> <code>Calendar</code> value.</p>
+ *
+ * <p>Implementations of the <code>validate()</code> method are provided
+ *    to create <code>Calendar</code> objects for different <i>time zones</i>
+ *    if the system default is not appropriate.</p>
+ *    
+ * <p>Alternatively the CalendarValidator's <code>adjustToTimeZone()</code> method
+ *    can be used to adjust the <code>TimeZone</code> of the <code>Calendar</code>
+ *    object afterwards.</p> 
+ * 
+ * <p>Once a value has been sucessfully converted the following
+ *    methods can be used to perform various date comparison checks:</p>
+ *    <ul>
+ *       <li><code>compareDates()</code> compares the day, month and
+ *           year of two calendars, returing 0, -1 or +1 indicating
+ *           whether the first date is equal, before or after the second.</li>
+ *       <li><code>compareWeeks()</code> compares the week and 
+ *           year of two calendars, returing 0, -1 or +1 indicating
+ *           whether the first week is equal, before or after the second.</li>
+ *       <li><code>compareMonths()</code> compares the month and
+ *           year of two calendars, returing 0, -1 or +1 indicating
+ *           whether the first month is equal, before or after the second.</li>
+ *       <li><code>compareQuarters()</code> compares the quarter and
+ *           year of two calendars, returing 0, -1 or +1 indicating
+ *           whether the first quarter is equal, before or after the second.</li>
+ *       <li><code>compareYears()</code> compares the 
+ *           year of two calendars, returing 0, -1 or +1 indicating
+ *           whether the first year is equal, before or after the second.</li>
+ *    </ul>
+ * 
+ * <p>So that the same mechanism used for parsing an <i>input</i> value 
+ *    for validation can be used to format <i>output</i>, corresponding
+ *    <code>format()</code> methods are also provided. That is you can 
+ *    format either:</p>
+ *    <ul>
+ *       <li>using a specified pattern</li>
+ *       <li>using the format for a specified <code>Locale</code></li>
+ *       <li>using the format for the <i>default</i> <code>Locale</code></li>
+ *    </ul>
+ * 
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class CalendarValidator extends AbstractCalendarValidator {
+
+    private static final CalendarValidator VALIDATOR = new CalendarValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the CalendarValidator.
+     */
+    public static CalendarValidator getInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance with <i>short</i>
+     * date style.
+     */
+    public CalendarValidator() {
+        this(true, DateFormat.SHORT);
+    }
+
+    /**
+     * Construct an instance with the specified <i>strict</i>
+     * and <i>date style</i> parameters.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     * @param dateStyle the date style to use for Locale validation.
+     */
+    public CalendarValidator(boolean strict, int dateStyle) {
+        super(strict, dateStyle, -1);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Calendar</code> using the default
+     *    <code>Locale</code> and <code>TimeZone</code>. 
+     *
+     * @param value The value validation is being performed on.
+     * @return The parsed <code>Calendar</code> if valid or <code>null</code>
+     *  if invalid.
+     */
+    public Calendar validate(String value) {
+        return (Calendar)validateObj(value);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Calendar</code> using the specified
+     *    <code>TimeZone</code> and default  <code>Locale</code>.
+     *
+     * @param value The value validation is being performed on.
+     * @param timeZone The Time Zone used to parse the date, system default if null.
+     * @return The parsed <code>Calendar</code> if valid or <code>null</code>
+     *  if invalid.
+     */
+    public Calendar validate(String value, TimeZone timeZone) {
+        return (Calendar)validateObj(value, Locale.getDefault(), timeZone);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Calendar</code> using the specified
+     *    <i>pattern</i> and default <code>TimeZone</code>.
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @return The parsed <code>Calendar</code> if valid or <code>null</code> if invalid.
+     */
+    public Calendar validate(String value, String pattern) {
+        return (Calendar)validateObj(value, pattern);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Calendar</code> using the specified
+     *    <i>pattern</i> and <code>TimeZone</code>.
+     *
+     * @param value The value validation is being performed on.
+     * @param pattern The pattern used to validate the value against.
+     * @param timeZone The Time Zone used to parse the date, system default if null.
+     * @return The parsed <code>Calendar</code> if valid or <code>null</code> if invalid.
+     */
+    public Calendar validate(String value, String pattern, TimeZone timeZone) {
+        return (Calendar)validateObj(value, pattern, timeZone);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Calendar</code> using the specified
+     *    <code>Locale</code> and default <code>TimeZone</code>.
+     *
+     * @param value The value validation is being performed on.
+     * @param locale The locale to use for the date format, system default if null.
+     * @return The parsed <code>Calendar</code> if valid or <code>null</code> if invalid.
+     */
+    public Calendar validate(String value, Locale locale) {
+        return (Calendar)validateObj(value, locale);
+    }
+
+    /**
+     * <p>Validate/convert a <code>Calendar</code> using the specified
+     *    <code>Locale</code> and <code>TimeZone</code>.
+     *
+     * @param value The value validation is being performed on.
+     * @param locale The locale to use for the date format, system default if null.
+     * @param timeZone The Time Zone used to parse the date, system default if null.
+     * @return The parsed <code>Calendar</code> if valid or <code>null</code> if invalid.
+     */
+    public Calendar validate(String value, Locale locale, TimeZone timeZone) {
+        return (Calendar)validateObj(value, locale, timeZone);
+    }
+
+    /**
+     * <p>Adjusts a Calendar's value to a different TimeZone.</p>
+     * 
+     * @param value The value to adjust.
+     * @param timeZone The new time zone to use to adjust the Calendar to.
+     */
+    public static void adjustToTimeZone(Calendar value, TimeZone timeZone) {
+        if (value.getTimeZone().hasSameRules(timeZone)) {
+            value.setTimeZone(timeZone);
+        } else {
+            int year   = value.get(Calendar.YEAR);
+            int month  = value.get(Calendar.MONTH);
+            int date   = value.get(Calendar.DATE);
+            int hour   = value.get(Calendar.HOUR_OF_DAY);
+            int minute = value.get(Calendar.MINUTE);
+            value.setTimeZone(timeZone);
+            value.set(year, month, date, hour, minute);
+        }
+    }
+
+    /**
+     * <p>Compare Dates (day, month and year - not time).</p>
+     * 
+     * @param value The <code>Calendar</code> value to check.
+     * @param compare The <code>Calendar</code> to compare the value to.
+     * @return Zero if the dates are equal, -1 if first
+     * date is less than the seconds and +1 if the first
+     * date is greater than.
+     */
+    public int compareDates(Calendar value, Calendar compare) {
+        return compare(value, compare, Calendar.DATE);
+    }
+
+    /**
+     * <p>Compare Weeks (week and year).</p>
+     * 
+     * @param value The <code>Calendar</code> value to check.
+     * @param compare The <code>Calendar</code> to compare the value to.
+     * @return Zero if the weeks are equal, -1 if first
+     * parameter's week is less than the seconds and +1 if the first
+     * parameter's week is greater than.
+     */
+    public int compareWeeks(Calendar value, Calendar compare) {
+        return compare(value, compare, Calendar.WEEK_OF_YEAR);
+    }
+
+    /**
+     * <p>Compare Months (month and year).</p>
+     * 
+     * @param value The <code>Calendar</code> value to check.
+     * @param compare The <code>Calendar</code> to compare the value to.
+     * @return Zero if the months are equal, -1 if first
+     * parameter's month is less than the seconds and +1 if the first
+     * parameter's month is greater than.
+     */
+    public int compareMonths(Calendar value, Calendar compare) {
+        return compare(value, compare, Calendar.MONTH);
+    }
+
+    /**
+     * <p>Compare Quarters (quarter and year).</p>
+     * 
+     * @param value The <code>Calendar</code> value to check.
+     * @param compare The <code>Calendar</code> to check the value against.
+     * @return Zero if the quarters are equal, -1 if first
+     * parameter's quarter is less than the seconds and +1 if the first
+     * parameter's quarter is greater than.
+     */
+    public int compareQuarters(Calendar value, Calendar compare) {
+        return compareQuarters(value, compare, 1);
+    }
+
+    /**
+     * <p>Compare Quarters (quarter and year).</p>
+     * 
+     * @param value The <code>Calendar</code> value to check.
+     * @param compare The <code>Calendar</code> to compare the value to.
+     * @param monthOfFirstQuarter The  month that the first quarter starts.
+     * @return Zero if the quarters are equal, -1 if first
+     * parameter's quarter is less than the seconds and +1 if the first
+     * parameter's quarter is greater than.
+     */
+    public int compareQuarters(Calendar value, Calendar compare, int monthOfFirstQuarter) {
+        return super.compareQuarters(value, compare, monthOfFirstQuarter);
+    }
+
+    /**
+     * <p>Compare Years.</p>
+     * 
+     * @param value The <code>Calendar</code> value to check.
+     * @param compare The <code>Calendar</code> to compare the value to.
+     * @return Zero if the years are equal, -1 if first
+     * parameter's year is less than the seconds and +1 if the first
+     * parameter's year is greater than.
+     */
+    public int compareYears(Calendar value, Calendar compare) {
+        return compare(value, compare, Calendar.YEAR);
+    }
+
+    /**
+     * <p>Perform further validation and convert the <code>Calendar</code> to
+     * the appropriate type.</p>
+     * 
+     * <p>This implementation returns the <code>Calendar</code> object
+     *    unchanged</p>
+     * 
+     * @param calendar The calendar object create from the parsed value.
+     * @return The validated/converted <code>Calendar</code> value if valid 
+     * or <code>null</code> if invalid.
+     */
+    protected Object processCalendar(Calendar calendar) {
+        return calendar;
+    }
+
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CalendarValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CalendarValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CurrencyValidator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CurrencyValidator.java?rev=370397&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CurrencyValidator.java (added)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CurrencyValidator.java Wed Jan 18 22:38:24 2006
@@ -0,0 +1,86 @@
+/*
+ * $Id$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.validator.routines;
+
+import java.text.Format;
+import java.text.NumberFormat;
+import java.util.Locale;
+
+/**
+ * <p><b>Currency Validation</b> and Conversion routines (<code>java.math.BigDecimal</code>).</p>
+ * 
+ * <p>This validator is a variation of the <code>BigDecimal</code> Validator
+ *    that uses the <i>currency</i> format when validating using
+ *    a <code>Locale</code>.</p>
+ * 
+ * <p>Otherwise it provides the same functionality as the <code>BigDecimal</code>
+ *    with converted values being returned as a  <code>BigDecimal</code>.</p>
+ *
+ * @version $Revision$ $Date$
+ * @since Validator 1.2.1
+ */
+public class CurrencyValidator extends BigDecimalValidator {
+
+    private static final CurrencyValidator VALIDATOR = new CurrencyValidator();
+
+    /**
+     * Return a singleton instance of this validator.
+     * @return A singleton instance of the CurrencyValidator.
+     */
+    public static BigDecimalValidator getInstance() {
+        return VALIDATOR;
+    }
+
+    /**
+     * Construct a <i>strict</i> instance.
+     */
+    public CurrencyValidator() {
+        this(true);
+    }
+
+    /**
+     * Construct an instance with the specified strict setting.
+     * 
+     * @param strict <code>true</code> if strict 
+     *        <code>Format</code> parsing should be used.
+     */
+    public CurrencyValidator(boolean strict) {
+        super(strict);
+    }
+
+    /**
+     * <p>Returns a currency <code>NumberFormat</code> for the specified Locale.</p>
+     * 
+     * @param locale The locale a currency <code>NumberFormat</code> is required
+     *        for, defaults to the default.
+     * @return The currency <code>NumberFormat</code> to created.
+     */
+    public Format getFormat(Locale locale) {
+
+        if (locale == null) {
+            locale = Locale.getDefault();
+        }
+
+        return NumberFormat.getCurrencyInstance(locale);
+
+    }
+
+}

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CurrencyValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/routines/CurrencyValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



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