KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > field > TKInputField


1 package com.teamkonzept.field;
2
3 import com.teamkonzept.lib.*;
4 import com.teamkonzept.publishing.markups.*;
5 import com.teamkonzept.web.*;
6 import com.teamkonzept.field.db.*;
7 import com.teamkonzept.international.LanguageManager;
8
9 /**
10  * The input field control.
11  *
12  * @author $Author: uli $
13  * @version $Revision: 1.26 $
14  */

15 public class TKInputField
16     extends TKAtomField
17 {
18     // $Id: TKInputField.java,v 1.26 2002/02/27 11:07:04 uli Exp $
19

20     /**
21      * The class identifier.
22      */

23     public static final String JavaDoc CLASS_ID = "INPUT";
24     public static final String JavaDoc LENGTH_KEY = "LENGTH";
25     public static final String JavaDoc SIZE_KEY = "SIZE";
26     public static final String JavaDoc INPUT_CHECK_KEY = "INPUT_CHECK";
27     public static final String JavaDoc INPUT_MANDATORY_KEY = "INPUT_MANDATORY";
28
29     public static final int CHECK_UNDEFINED = -1;
30     public static final int CHECK_INTEGER = 0;
31     public static final int CHECK_OPTIONAL_INTEGER = 1;
32     public static final int CHECK_STRING = 2;
33
34     public final static int SMALL_DEFAULT_SIZE = 16;
35     public final static int LARGE_DEFAULT_SIZE = 50;
36     public final static int SMALL_DEFAULT_LENGTH = 80;
37     public final static int LARGE_DEFAULT_LENGTH = 254;
38
39     public static final boolean[] CHECK_MANDATORY =
40     {
41         true,
42         false,
43         true
44     };
45
46     public static final String JavaDoc[] CHECK_NAMES =
47     {
48         "integer",
49         "optional_integer",
50         "string"
51     };
52
53     protected int size;
54     protected int length;
55
56     // Initialize to default: no check at all.
57
protected int check = CHECK_UNDEFINED;
58
59     public TKInputField() {};
60
61     public TKInputField( String JavaDoc name, int size )
62     {
63         this( name, size, size, null );
64     }
65
66     public TKInputField( String JavaDoc name, int size, String JavaDoc showName )
67     {
68         this( name, size, size, showName );
69     }
70
71     public TKInputField( String JavaDoc name, int size, int length, String JavaDoc showName )
72     {
73         this(name, size, length, showName, CHECK_UNDEFINED);
74     }
75
76     public TKInputField (String JavaDoc name,
77                          int size,
78                          int length,
79                          String JavaDoc showName,
80                          int check)
81     {
82         initInputField(CLASS_ID, name, size, length, showName, check);
83     }
84
85     public final void initInputField (String JavaDoc type,
86                                       String JavaDoc name,
87                                       int size,
88                                       int length,
89                                       String JavaDoc showName,
90                                       int check)
91     {
92         initAtomField(type, name, showName);
93
94         this.size = size;
95         this.length = length;
96         this.check = check;
97     }
98
99     public void init (String JavaDoc classId, Object JavaDoc initData)
100         throws
101             TKUnregisteredClassException,
102             ClassNotFoundException JavaDoc,
103             InstantiationException JavaDoc,
104             IllegalAccessException JavaDoc
105     {
106         super.init(classId, initData);
107
108         String JavaDoc value = null;
109         TKHashtable data = (TKHashtable) initData;
110
111         this.size = Integer.parseInt((String JavaDoc) data.get(SIZE_KEY));
112
113         value = (String JavaDoc) data.get(LENGTH_KEY);
114         this.length = value != null && value.length() > 0
115                            ? Integer.parseInt(value)
116                            : -1;
117
118         value = (String JavaDoc) data.get(INPUT_CHECK_KEY);
119         this.check = value != null && value.length() > 0
120                            ? Integer.parseInt(value)
121                            : CHECK_UNDEFINED;
122     }
123
124     /**
125         ueberschrieben, damit der NAME und SHOWNAME ausgegeben wird
126     */

127     public String JavaDoc getInternationalName()
128     {
129         if (fieldName.equals(NAME_KEY) || fieldName.equals(SHOW_NAME_KEY))
130             return fieldName;
131         else
132             return super.getInternationalName();
133     }
134
135     /**
136      * Methode zur Definition eines Eingabefeldes
137      */

138     public TKFieldGroup getDefGroup (TKFieldSwitch allSwitch, TKFieldSwitchList allSwitchList)
139     {
140             TKBaseField [] inputArray =
141             {
142                 new TKInputField(TKInputField.NAME_KEY,
143                                  SMALL_DEFAULT_SIZE, SMALL_DEFAULT_LENGTH,
144                                  LanguageManager.getText(LANGUAGE_CONTEXT, "INPUT_NAME"), TKInputField.CHECK_STRING),
145                 new TKInputField(TKInputField.SHOW_NAME_KEY,
146                                  LARGE_DEFAULT_SIZE, LARGE_DEFAULT_LENGTH,
147                                  LanguageManager.getText(LANGUAGE_CONTEXT, "INPUT_SHOWNAME"), TKInputField.CHECK_STRING),
148                 new TKInputField(TKInputField.SIZE_KEY, 3, 3, LanguageManager.getText(LANGUAGE_CONTEXT, "INPUT_SIZE"), TKInputField.CHECK_INTEGER),
149                 new TKInputField(TKInputField.LENGTH_KEY, 3, 3, LanguageManager.getText(LANGUAGE_CONTEXT, "INPUT_MAXLENGTH"), TKInputField.CHECK_OPTIONAL_INTEGER)
150                     };
151
152             return new TKFieldGroup(TKInputField.CLASS_ID, new TKVector(inputArray), LanguageManager.getText(LANGUAGE_CONTEXT, TKInputField.CLASS_ID));
153     }
154
155     public Object JavaDoc toData ()
156     {
157         TKHashtable result = (TKHashtable) super.toData();
158
159         result.put(SIZE_KEY, String.valueOf(size));
160
161         if (this.length > -1)
162         {
163             result.put(LENGTH_KEY, String.valueOf(this.length));
164         }
165
166         if (this.check > CHECK_UNDEFINED)
167         {
168             result.put(INPUT_CHECK_KEY, String.valueOf(this.check));
169         }
170
171         return result;
172     }
173
174     public void fillIntoTemplate (TKHTMLTemplate t, Object JavaDoc value, String JavaDoc prefix)
175     {
176         super.fillIntoTemplate(t, value, prefix);
177
178         t.set(SIZE_KEY, String.valueOf(this.size));
179
180         if (this.length > -1)
181         {
182             t.set(LENGTH_KEY, String.valueOf(this.length));
183         }
184
185         if (this.check > CHECK_UNDEFINED)
186         {
187             t.set(INPUT_CHECK_KEY, CHECK_NAMES[this.check]);
188
189             if (CHECK_MANDATORY[this.check])
190             {
191                 t.set(INPUT_MANDATORY_KEY, INPUT_MANDATORY_KEY);
192             }
193         }
194     }
195
196     public void initFromDB (String JavaDoc classId, TKFormDBData db, TKVector otherFields)
197         throws
198             TKUnregisteredClassException,
199             ClassNotFoundException JavaDoc,
200             InstantiationException JavaDoc,
201             IllegalAccessException JavaDoc
202     {
203         super.initFromDB(classId, db, otherFields);
204
205         this.size = Integer.parseInt(getFieldAttribute(db, SIZE_KEY, 0));
206         this.length = Integer.parseInt(getFieldAttribute(db, LENGTH_KEY, 0));
207     }
208
209     public int realInsertIntoDB (TKFormDBData db, int formId)
210     {
211         if (super.realInsertIntoDB(db, formId) == -1) return -1;
212
213         insertNewFieldAttribute(db, formId, SIZE_KEY, 0, String.valueOf(this.size));
214         insertNewFieldAttribute(db, formId, LENGTH_KEY, 0, String.valueOf(this.length));
215
216         return fieldId;
217     }
218
219     public Object JavaDoc compileData( String JavaDoc prefix, TKMarkupNode data, TKHashtable context )
220     {
221         TKXmlMarkup markup = data == null ? null : (TKXmlMarkup) data.markup;
222         if (markup == null) { return null;}
223
224         if (!markup.name.equals (getName())) {
225             return null;
226         }
227
228         TKXmlTree tree = (TKXmlTree) data.tree;
229         if (tree == null) { return null;}
230
231         String JavaDoc val = tree.getSingleText ();
232
233         return val == null ? getDefault() : val.trim();
234     }
235
236     /**
237      * Checks wether this object and the specified object
238      * may be treated as equal.
239      *
240      * @param object the object to checked for equality.
241      * @return <CODE>true</CODE> if this object and the
242      * specified object may be treated as equal, otherwise
243      * <CODE>false</CODE>.
244      */

245     public boolean equals (Object JavaDoc object)
246     {
247         if (! super.equals(object))
248         {
249             return false;
250         }
251
252         TKInputField field = (TKInputField) object;
253
254         return (this.size == field.size) &&
255                (this.length == field.length);
256     }
257
258     /**
259      * Returns the hash code for this object.
260      *
261      * @return the hash code for this object.
262      */

263     public int hashCode ()
264     {
265         // Implementation for JTest only ;-(
266
return super.hashCode();
267     }
268
269 }
270
Popular Tags