public Date parse()

in src/java/org/apache/fulcrum/intake/validator/DateStringValidator.java [166:221]


    public Date parse(String s)
            throws ParseException
    {
        Date date = null;

        if (s == null)
        {
            throw new ParseException("Input string was null", -1);
        }

        SimpleDateFormat sdf = new SimpleDateFormat();
        sdf.setLenient(flexible);

        for (int i = 1; i < dateFormats.size() && date == null; i++)
        {
            sdf.applyPattern(dateFormats.get(i));

            try
            {
                date = sdf.parse(s);
            }
            catch (ParseException e)
            {
                // ignore
            }
        }

        if (date == null)
        {
            sdf.applyPattern(dateFormats.get(0));

            try
            {
                date = sdf.parse(s);
            }
            catch (ParseException e)
            {
                // ignore
            }
        }

        if (date == null)
        {
            // Try default
            date = SimpleDateFormat.getInstance().parse(s);
        }

        // if the date still has not been parsed at this point, throw
        // a ParseException.
        if (date == null)
        {
            throw new ParseException("Could not parse the date", 0);
        }

        return date;
    }