|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DateTranslator.java | - | 87.5% | 87.5% | 87.5% |
|
1 | // Copyright 2005 The Apache Software Foundation | |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
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 | /** | |
26 | * A {@link java.text.SimpleDateFormat}-based {@link Translator} implementation. | |
27 | * | |
28 | * @author Paul Ferraro | |
29 | * @since 4.0 | |
30 | */ | |
31 | public class DateTranslator extends FormatTranslator | |
32 | { | |
33 | ||
34 | 11 | public DateTranslator() |
35 | { | |
36 | } | |
37 | ||
38 | // Needed until HIVEMIND-134 fix is available | |
39 | 0 | public DateTranslator(String initializer) |
40 | { | |
41 | 0 | super(initializer); |
42 | } | |
43 | ||
44 | /** | |
45 | * @see org.apache.tapestry.form.translator.FormatTranslator#defaultPattern() | |
46 | */ | |
47 | 11 | protected String defaultPattern() |
48 | { | |
49 | 11 | return "MM/dd/yyyy"; |
50 | } | |
51 | ||
52 | /** | |
53 | * @see org.apache.tapestry.form.translator.FormatTranslator#getFormat(java.util.Locale) | |
54 | */ | |
55 | 7 | protected Format getFormat(Locale locale) |
56 | { | |
57 | 7 | return getDateFormat(locale); |
58 | } | |
59 | ||
60 | 9 | public SimpleDateFormat getDateFormat(Locale locale) |
61 | { | |
62 | 9 | return new SimpleDateFormat(getPattern(), new DateFormatSymbols(locale)); |
63 | } | |
64 | ||
65 | /** | |
66 | * @see org.apache.tapestry.form.translator.FormatTranslator#getMessageKey() | |
67 | */ | |
68 | 2 | protected String getMessageKey() |
69 | { | |
70 | 2 | return ValidationStrings.INVALID_DATE; |
71 | } | |
72 | ||
73 | /** | |
74 | * @see org.apache.tapestry.form.translator.AbstractTranslator#getMessageParameters(java.util.Locale, | |
75 | * java.lang.String) | |
76 | */ | |
77 | 2 | protected Object[] getMessageParameters(Locale locale, String label) |
78 | { | |
79 | 2 | String pattern = getDateFormat(locale).toLocalizedPattern().toUpperCase(locale); |
80 | ||
81 | 2 | return new Object[] |
82 | { label, pattern }; | |
83 | } | |
84 | ||
85 | /** | |
86 | * @see org.apache.tapestry.form.translator.FormatTranslator#getConstraint() | |
87 | */ | |
88 | 2 | protected ValidationConstraint getConstraint() |
89 | { | |
90 | 2 | return ValidationConstraint.DATE_FORMAT; |
91 | } | |
92 | } |
|