01: /*
02: * Copyright 2006 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.core.web.format;
17:
18: import java.text.NumberFormat;
19:
20: import org.kuali.RiceKeyConstants;
21: import org.kuali.core.util.KualiDecimal;
22: import org.kuali.core.util.KualiInteger;
23:
24: public class KualiIntegerCurrencyFormatter extends CurrencyFormatter {
25:
26: protected Object convertToObject(String target) {
27: KualiDecimal value = (KualiDecimal) (super
28: .convertToObject(target));
29: return new KualiInteger(value.longValue());
30: }
31:
32: /**
33: * Returns a string representation of its argument formatted as a currency value.
34: */
35: public Object format(Object obj) {
36: if (obj == null)
37: return null;
38:
39: NumberFormat formatter = NumberFormat.getNumberInstance();
40: String string = null;
41:
42: try {
43: KualiInteger number = (KualiInteger) obj;
44: string = formatter.format(number.doubleValue());
45: } catch (IllegalArgumentException e) {
46: throw new FormatException("formatting",
47: RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e);
48: } catch (ClassCastException e) {
49: throw new FormatException("formatting",
50: RiceKeyConstants.ERROR_CURRENCY, obj.toString(), e);
51: }
52:
53: return showSymbol() ? string : removeSymbol(string);
54: }
55: }
|