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 15 public class TKInputField 16 extends TKAtomField 17 { 18 20 23 public static final String CLASS_ID = "INPUT"; 24 public static final String LENGTH_KEY = "LENGTH"; 25 public static final String SIZE_KEY = "SIZE"; 26 public static final String INPUT_CHECK_KEY = "INPUT_CHECK"; 27 public static final String 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 [] CHECK_NAMES = 47 { 48 "integer", 49 "optional_integer", 50 "string" 51 }; 52 53 protected int size; 54 protected int length; 55 56 protected int check = CHECK_UNDEFINED; 58 59 public TKInputField() {}; 60 61 public TKInputField( String name, int size ) 62 { 63 this( name, size, size, null ); 64 } 65 66 public TKInputField( String name, int size, String showName ) 67 { 68 this( name, size, size, showName ); 69 } 70 71 public TKInputField( String name, int size, int length, String showName ) 72 { 73 this(name, size, length, showName, CHECK_UNDEFINED); 74 } 75 76 public TKInputField (String name, 77 int size, 78 int length, 79 String showName, 80 int check) 81 { 82 initInputField(CLASS_ID, name, size, length, showName, check); 83 } 84 85 public final void initInputField (String type, 86 String name, 87 int size, 88 int length, 89 String 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 classId, Object initData) 100 throws 101 TKUnregisteredClassException, 102 ClassNotFoundException , 103 InstantiationException , 104 IllegalAccessException  105 { 106 super.init(classId, initData); 107 108 String value = null; 109 TKHashtable data = (TKHashtable) initData; 110 111 this.size = Integer.parseInt((String ) data.get(SIZE_KEY)); 112 113 value = (String ) data.get(LENGTH_KEY); 114 this.length = value != null && value.length() > 0 115 ? Integer.parseInt(value) 116 : -1; 117 118 value = (String ) data.get(INPUT_CHECK_KEY); 119 this.check = value != null && value.length() > 0 120 ? Integer.parseInt(value) 121 : CHECK_UNDEFINED; 122 } 123 124 127 public String 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 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 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 value, String 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 classId, TKFormDBData db, TKVector otherFields) 197 throws 198 TKUnregisteredClassException, 199 ClassNotFoundException , 200 InstantiationException , 201 IllegalAccessException  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 compileData( String 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 val = tree.getSingleText (); 232 233 return val == null ? getDefault() : val.trim(); 234 } 235 236 245 public boolean equals (Object 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 263 public int hashCode () 264 { 265 return super.hashCode(); 267 } 268 269 } 270
| Popular Tags
|