/**
 * Copyright 2012 A24Group
 *  
 * 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.ssgwt.client.validation.validators;

import java.util.Date;

import com.google.gwt.i18n.client.DateTimeFormat;

/**
 * Date Validator.
 * 
 * This class is used to validate date properties and values.
 * 
 * @todo Allow user to pass in date format via configuration
 * 
 * @author Jaco Nel <jaco.nel@a24group.com>
 * @since 12 June 2012
 */
public class DateValidator extends AbstractValidator implements ValidatorInterface<String> {

    /**
     * The date format to parse with.
     */
    public static final String DATE_FORMAT = "dd MMM yyyy";

    /**
     * Name of the validator name.
     */
    private static final String VALIDATOR_NAME = "DateValidator";
    
    /**
     * Default error message to use for validation
     */
    private static final String DEFAULT_VALIDATION_MESSAGE = "Invalid date entered";
    
    /**
     * Validates the value passed in.
     * 
     * @param value
     *            The value to validate
     * 
     * @author Jaco Nel <jaco.nel@a24group.com>
     * @since 13 June 2012
     * 
     * @return whether the value is valid or not
     */
    @Override
    public boolean isValid(String value) {
        try {
            Date date = DateTimeFormat.getFormat(DateValidator.DATE_FORMAT).parse(value);
        } catch (Exception exception) {
            return false;
        }

        return true;
    }

    /**
     * Retrieves the validator name.
     * 
     * @author Jaco Nel <jaco.nel@a24group.com>
     * @since 13 June 2012
     * 
     * @return validator name
     */
    @Override
    public String getName() {
        return DateValidator.VALIDATOR_NAME;
    }
    
    /**
     * Returns default error message to use for validation
     * 
     * @author Ruan Naude <ruan.naude@a24group.com>
     * @since 26 June 2012
     * 
     * @return The default error message to use
     */
    @Override
    public String getDefaultValidationMessage() {;
        return DateValidator.DEFAULT_VALIDATION_MESSAGE;
    }

}

@@ -1415,16 +1415,172 @@
 ntered%22;
+%0A%0A    /**%0A     * The index for the configuration item to set a custom date format.%0A     */%0A    public static final String CONFIG_DATE_FORMAT = %22dateFormat%22;
 %0A    %0A  
@@ -1926,45 +1926,305 @@
     
-Date date = DateTimeFormat.get
+String dateFormat;%0A            if (this.configuration%0A                    .containsKey(DateValidator.CONFIG_DATE_FORMAT)) %7B%0A                dateFormat = this.configuration.get(%0A                        DateValidator.CONFIG_DATE_FORMAT).toString();%0A            %7D else %7B%0A                date
 Format
-(
+ = 
 Date
@@ -2244,16 +2244,92 @@
 E_FORMAT
+;%0A            %7D%0A%0A            Date date = DateTimeFormat.getFormat(dateFormat
 ).parse(

Add ability to date validator to accept custom date formats.