Clover coverage report -
Coverage timestamp: Fri Nov 19 2004 13:41:51 PST
file stats: LOC: 83   Methods: 4
NCLOC: 60   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DateEditor.java 0% 58.6% 50% 48.7%
coverage coverage
 1    package photospace.beans;
 2   
 3    import java.beans.*;
 4    import java.text.*;
 5    import java.util.*;
 6   
 7    public class DateEditor extends PropertyEditorSupport
 8    {
 9   
 10    private final DateFormat dateFormat;
 11    private List formats = new ArrayList();
 12   
 13    private final boolean allowEmpty;
 14   
 15    /**
 16    * Create a new instance, using the given DateFormat for
 17    * parsing and rendering.
 18    * <p>The allowEmpty parameter states if an empty String should
 19    * be allowed for parsing, i.e. get interpreted as null value.
 20    * Else, an IllegalArgumentException gets thrown in that case.
 21    *
 22    * @param dateFormat DateFormat to use for parsing and rendering
 23    * @param allowEmpty if empty strings should be allowed
 24    */
 25  1 public DateEditor(DateFormat dateFormat, boolean allowEmpty)
 26    {
 27  1 this.dateFormat = dateFormat;
 28  1 this.allowEmpty = allowEmpty;
 29  1 addDateFormat(dateFormat);
 30  1 addDateFormat(new SimpleDateFormat ("MM/dd/yyyy HH:mmaa"));
 31  1 addDateFormat(DateFormat.getDateInstance(DateFormat.SHORT));
 32  1 addDateFormat(DateFormat.getDateInstance(DateFormat.MEDIUM));
 33  1 addDateFormat(DateFormat.getDateInstance(DateFormat.LONG));
 34  1 addDateFormat(DateFormat.getDateInstance(DateFormat.FULL));
 35  1 addDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
 36  1 addDateFormat(new SimpleDateFormat("yyyy/MM/dd"));
 37  1 addDateFormat(new SimpleDateFormat("yyyy.MM.dd"));
 38  1 addDateFormat(new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss aa"));
 39  1 addDateFormat(new SimpleDateFormat("dd-MMM-yyyy"));
 40  1 addDateFormat(new SimpleDateFormat("dd MMM yyyy"));
 41  1 addDateFormat(new SimpleDateFormat("EEE MMM dd kk:mm:ss zz yyyy")); //Tue Apr 01 00:00:00 PST 2003
 42  1 addDateFormat(new SimpleDateFormat("yyyy"));
 43    }
 44   
 45  14 public void addDateFormat(DateFormat format)
 46    {
 47  14 formats.add(format);
 48    }
 49   
 50  0 public void setAsText(String text) throws IllegalArgumentException
 51    {
 52  0 if (this.allowEmpty && (text == null || "".equals(text.trim())))
 53    {
 54    // treat empty String as null value
 55  0 setValue(null);
 56    }
 57    else
 58    {
 59  0 Object value = null;
 60  0 for (Iterator i = formats.iterator(); i.hasNext();)
 61    {
 62  0 DateFormat format = (DateFormat) i.next();
 63  0 try
 64    {
 65  0 value = format.parse(text);
 66  0 break;
 67    }
 68    catch (ParseException ex) {}
 69    }
 70  0 if (value == null) throw new IllegalArgumentException("Could not parse date: " + text);
 71  0 setValue(value);
 72    }
 73    }
 74   
 75    /**
 76    * Format the Date as String, using the specified DateFormat.
 77    */
 78  0 public String getAsText()
 79    {
 80  0 return this.dateFormat.format((Date) getValue());
 81    }
 82   
 83    }