01: package org.apache.turbine.services.intake.model;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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 extends Field {
35: /**
36: * Constructor.
37: *
38: * @param field xml field definition object
39: * @param group xml group definition object
40: * @throws IntakeException thrown by superclass
41: */
42: public AbstractNumberField(XmlField field, Group group)
43: throws IntakeException {
44: super (field, group);
45: }
46:
47: /**
48: * Canonicalizes an user-inputted <code>BigDecimal</code> string
49: * to the system's internal format.
50: *
51: * @param number Text conforming to a <code>Number</code>
52: * description for a set of <code>DecimalFormatSymbols</code>.
53: * @return The canonicalized representation.
54: */
55: protected final String canonicalizeDecimalInput(String number) {
56: if (getLocale() != null) {
57: DecimalFormatSymbols internal = new DecimalFormatSymbols(
58: Locale.US);
59: DecimalFormatSymbols user = new DecimalFormatSymbols(
60: getLocale());
61:
62: if (!internal.equals(user)) {
63: number = number.replace(user.getDecimalSeparator(),
64: internal.getDecimalSeparator());
65: }
66: }
67: return number;
68: }
69: }
|