01: /*
02: * Copyright 2004 Jonathan M. Lehr
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
10: * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
11: * governing permissions and limitations under the License.
12: *
13: * MODIFIED BY THE KUALI FOUNDATION
14: */
15: // begin Kuali Foundation modification
16: package org.kuali.core.web.format;
17:
18: // end Kuali Foundation modification
19:
20: // begin Kuali Foundation modification
21: import org.apache.commons.lang.StringUtils;
22: import org.kuali.RiceKeyConstants;
23:
24: /**
25: * This class is used to format Integer objects.
26: */
27: public class IntegerFormatter extends Formatter {
28: // begin Kuali Foundation modification
29: private static final long serialVersionUID = 226069363610021292L;
30:
31: // removed INTEGER_ERROR_KEY, PARSE_MSG, getErrorKey()
32: // end Kuali Foundation modification
33:
34: /**
35: * begin Kuali Foundation modification
36: * Returns an object representation of the provided string.
37: * end Kuali Foundation modification
38: */
39: protected Object convertToObject(String string) {
40: // begin Kuali Foundation modification
41: if (StringUtils.isEmpty(string))
42: return null;
43:
44: try {
45: return new Integer(string);
46: } catch (NumberFormatException e) {
47: throw new FormatException("parsing",
48: RiceKeyConstants.ERROR_INTEGER, string, e);
49: }
50: // end Kuali Foundation modification
51: }
52:
53: // begin Kuali Foundation modification
54: /**
55: * Returns the provided value as a formatted string
56: */
57: public Object format(Object value) {
58: return (value == null ? null : value.toString());
59: }
60: // end Kuali Foundation modification
61: }
|