01: // /////////////////////////////
02: // Makumba, Makumba tag library
03: // Copyright (C) 2000-2003 http://www.makumba.org
04: //
05: // This library is free software; you can redistribute it and/or
06: // modify it under the terms of the GNU Lesser General Public
07: // License as published by the Free Software Foundation; either
08: // version 2.1 of the License, or (at your option) any later version.
09: //
10: // This library is distributed in the hope that it will be useful,
11: // but WITHOUT ANY WARRANTY; without even the implied warranty of
12: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: // Lesser General Public License for more details.
14: //
15: // You should have received a copy of the GNU Lesser General Public
16: // License along with this library; if not, write to the Free Software
17: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: //
19: // -------------
20: // $Id: intEditor.java 1749 2007-10-03 15:56:11Z manuel_gay $
21: // $Name$
22: /////////////////////////////////////
23:
24: package org.makumba.forms.html;
25:
26: import java.util.Dictionary;
27:
28: import org.makumba.commons.formatters.FieldFormatter;
29: import org.makumba.commons.formatters.InvalidValueException;
30: import org.makumba.commons.formatters.RecordFormatter;
31:
32: public class intEditor extends charEditor {
33:
34: private static final class SingletonHolder {
35: static final FieldEditor singleton = new intEditor();
36: }
37:
38: /** Don't use this, use getInstance() */
39: protected intEditor() {
40: }
41:
42: public static FieldFormatter getInstance() {
43: return SingletonHolder.singleton;
44: }
45:
46: static String[] __params = { "default", "empty", "size",
47: "maxlength" };
48:
49: static String[][] __paramValues = { null, null, null, null };
50:
51: public String[] getAcceptedParams() {
52: return __params;
53: }
54:
55: public String[][] getAcceptedValue() {
56: return __paramValues;
57: }
58:
59: public int getWidth(RecordFormatter rf, int fieldIndex) {
60: return 10;
61: }
62:
63: /** Formats the value to appear in an input statement. */
64: public String formatValue(RecordFormatter rf, int fieldIndex,
65: Object o, Dictionary formatParams) {
66: // note: only diff with charEditor.formatValue is not calling
67: // string2html
68: // maybe can just as well not redefine this method?
69: String s = (o == null) ? null : o.toString();
70: return resetValueFormat(rf, fieldIndex, s, formatParams);
71: }
72:
73: public Object readFrom(RecordFormatter rf, int fieldIndex,
74: org.makumba.commons.attributes.HttpParameters par,
75: String suffix) {
76: Object o = par
77: .getParameter(getInputName(rf, fieldIndex, suffix));
78:
79: if (o instanceof java.util.Vector) {
80: throw new InvalidValueException(rf.expr[fieldIndex],
81: "multiple value not accepted for integer: " + o);
82: }
83: return toInt(rf, fieldIndex, o);
84: }
85:
86: }
|