1 15 package org.apache.tapestry.form.translator; 16 17 import java.text.DateFormatSymbols ; 18 import java.text.Format ; 19 import java.text.SimpleDateFormat ; 20 import java.util.Locale ; 21 22 import org.apache.tapestry.valid.ValidationConstraint; 23 import org.apache.tapestry.valid.ValidationStrings; 24 25 31 public class DateTranslator extends FormatTranslator 32 { 33 34 public DateTranslator() 35 { 36 } 37 38 public DateTranslator(String initializer) 40 { 41 super(initializer); 42 } 43 44 47 protected String defaultPattern() 48 { 49 return "MM/dd/yyyy"; 50 } 51 52 55 protected Format getFormat(Locale locale) 56 { 57 return getDateFormat(locale); 58 } 59 60 public SimpleDateFormat getDateFormat(Locale locale) 61 { 62 return new SimpleDateFormat (getPattern(), new DateFormatSymbols (locale)); 63 } 64 65 68 protected String getMessageKey() 69 { 70 return ValidationStrings.INVALID_DATE; 71 } 72 73 77 protected Object [] getMessageParameters(Locale locale, String label) 78 { 79 String pattern = getDateFormat(locale).toLocalizedPattern().toUpperCase(locale); 80 81 return new Object [] 82 { label, pattern }; 83 } 84 85 88 protected ValidationConstraint getConstraint() 89 { 90 return ValidationConstraint.DATE_FORMAT; 91 } 92 } 93 | Popular Tags |