Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
StringTranslator |
|
| 1.0;1 |
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.util.Locale; | |
18 | ||
19 | import org.apache.hivemind.util.PropertyUtils; | |
20 | import org.apache.tapestry.form.IFormComponent; | |
21 | import org.apache.tapestry.form.ValidationMessages; | |
22 | ||
23 | /** | |
24 | * A trivial {@link Translator} implementation. By default, empty text submissions are interpretted | |
25 | * as null. | |
26 | * | |
27 | * @author Paul Ferraro | |
28 | * @since 4.0 | |
29 | */ | |
30 | public class StringTranslator extends AbstractTranslator | |
31 | { | |
32 | ||
33 | 0 | private String _empty = null; |
34 | ||
35 | public StringTranslator() | |
36 | 0 | { |
37 | 0 | } |
38 | ||
39 | // Needed until HIVEMIND-134 fix is available | |
40 | ||
41 | public StringTranslator(String initializer) | |
42 | 0 | { |
43 | 0 | PropertyUtils.configureProperties(this, initializer); |
44 | 0 | } |
45 | ||
46 | /** | |
47 | * @see org.apache.tapestry.form.translator.AbstractTranslator#parseText(org.apache.tapestry.form.IFormComponent, | |
48 | * ValidationMessages, java.lang.String) | |
49 | */ | |
50 | protected Object parseText(IFormComponent field, ValidationMessages messages, String text) | |
51 | { | |
52 | 0 | return text; |
53 | } | |
54 | ||
55 | /** | |
56 | * @see org.apache.tapestry.form.translator.AbstractTranslator#formatObject(org.apache.tapestry.form.IFormComponent, | |
57 | * Locale, java.lang.Object) | |
58 | */ | |
59 | protected String formatObject(IFormComponent field, Locale locale, Object object) | |
60 | { | |
61 | 0 | return object.toString(); |
62 | } | |
63 | ||
64 | public Object getValueForEmptyInput() | |
65 | { | |
66 | 0 | return _empty; |
67 | } | |
68 | ||
69 | public void setEmpty(String empty) | |
70 | { | |
71 | 0 | _empty = empty; |
72 | 0 | } |
73 | ||
74 | public String getEmpty() | |
75 | { | |
76 | 0 | return _empty; |
77 | } | |
78 | } |