1 package org.apache.turbine.services.intake.model;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.text.DecimalFormatSymbols;
23 import java.util.Locale;
24
25 import org.apache.turbine.services.intake.IntakeException;
26 import org.apache.turbine.services.intake.xmlmodel.XmlField;
27
28 /***
29 * Provides helper methods for localizing floating point numbers
30 *
31 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
32 * @version $Id: BigDecimalField.java 223047 2004-07-01 11:30:52Z epugh $
33 */
34 public abstract class AbstractNumberField
35 extends Field
36 {
37 /***
38 * Constructor.
39 *
40 * @param field xml field definition object
41 * @param group xml group definition object
42 * @throws IntakeException thrown by superclass
43 */
44 public AbstractNumberField(XmlField field, Group group)
45 throws IntakeException
46 {
47 super(field, group);
48 }
49
50 /***
51 * Canonicalizes an user-inputted <code>BigDecimal</code> string
52 * to the system's internal format.
53 *
54 * @param number Text conforming to a <code>Number</code>
55 * description for a set of <code>DecimalFormatSymbols</code>.
56 * @return The canonicalized representation.
57 */
58 protected final String canonicalizeDecimalInput(String number)
59 {
60 if (getLocale() != null)
61 {
62 DecimalFormatSymbols internal = new DecimalFormatSymbols(Locale.US);
63 DecimalFormatSymbols user = new DecimalFormatSymbols(getLocale());
64
65 if (!internal.equals(user))
66 {
67 number = number.replace(user.getDecimalSeparator(),
68 internal.getDecimalSeparator());
69 }
70 }
71 return number;
72 }
73 }