View Javadoc

1   package org.apache.turbine.services.intake.model;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  }