001: package com.teamkonzept.field;
002:
003: import com.teamkonzept.lib.*;
004: import com.teamkonzept.publishing.markups.*;
005: import com.teamkonzept.web.*;
006: import com.teamkonzept.field.db.*;
007: import com.teamkonzept.international.LanguageManager;
008: import org.w3c.dom.*;
009:
010: /**
011: * The text field control.
012: *
013: * @author $Author: uli $
014: * @version $Revision: 1.27 $
015: */
016: public class TKTextField extends TKAtomField {
017: // $Id: TKTextField.java,v 1.27 2002/02/27 11:07:04 uli Exp $
018:
019: /**
020: * The class identifier.
021: */
022: public static final String CLASS_ID = "TEXT";
023: public static final String COLS_KEY = "COLS";
024: public static final String ROWS_KEY = "ROWS";
025: public static final String MAX_SIZE_KEY = "MAX_SIZE";
026:
027: /**
028: * The column field size.
029: */
030: public static final int COLUMN_FIELD_SIZE = 3;
031:
032: /**
033: * The length field size.
034: */
035: public static final int LENGTH_FIELD_SIZE = 6;
036:
037: protected int rows = 0;
038:
039: protected int cols = 0;
040:
041: protected int maxSize = 0;
042:
043: public TKTextField() {
044: };
045:
046: public TKTextField(String name, int rows, int cols, int maxSize) {
047: this (name, rows, cols, maxSize, null);
048: }
049:
050: public TKTextField(String name, int rows, int cols, int maxSize,
051: String showName) {
052: initTextField(CLASS_ID, name, rows, cols, maxSize, showName);
053: }
054:
055: public void initTextField(String type, String name, int rows,
056: int cols, int maxSize, String showName) {
057: initAtomField(type, name, showName);
058: this .rows = rows;
059: this .cols = cols;
060: this .maxSize = maxSize;
061: }
062:
063: public void init(String fieldType, Object initData)
064: throws TKUnregisteredClassException,
065: ClassNotFoundException, InstantiationException,
066: IllegalAccessException {
067: super .init(fieldType, initData);
068: TKHashtable data = (TKHashtable) initData;
069: rows = Integer.parseInt((String) data.get(ROWS_KEY));
070: cols = Integer.parseInt((String) data.get(COLS_KEY));
071:
072: String value = (String) data.get(MAX_SIZE_KEY);
073: this .maxSize = value != null && value.length() > 0 ? Integer
074: .parseInt(value) : 0;
075: }
076:
077: /**
078: * Methode zur Definition eines Textfeldes
079: */
080: public TKFieldGroup getDefGroup(TKFieldSwitch allSwitch,
081: TKFieldSwitchList allSwitchList) {
082:
083: TKBaseField[] textArray = {
084: new TKInputField(TKTextField.NAME_KEY,
085: TKInputField.SMALL_DEFAULT_SIZE,
086: TKInputField.SMALL_DEFAULT_LENGTH,
087: LanguageManager.getText(LANGUAGE_CONTEXT,
088: "INPUT_NAME"),
089: TKInputField.CHECK_STRING),
090: new TKInputField(TKTextField.SHOW_NAME_KEY,
091: TKInputField.LARGE_DEFAULT_SIZE,
092: TKInputField.LARGE_DEFAULT_LENGTH,
093: LanguageManager.getText(LANGUAGE_CONTEXT,
094: "INPUT_SHOWNAME"),
095: TKInputField.CHECK_STRING),
096: new TKInputField(TKTextField.COLS_KEY,
097: COLUMN_FIELD_SIZE, COLUMN_FIELD_SIZE,
098: LanguageManager.getText(LANGUAGE_CONTEXT,
099: "TEXTFIELD_WIDTH"),
100: TKInputField.CHECK_INTEGER),
101: new TKInputField(TKTextField.ROWS_KEY,
102: COLUMN_FIELD_SIZE, COLUMN_FIELD_SIZE,
103: LanguageManager.getText(LANGUAGE_CONTEXT,
104: "TEXTFIELD_HEIGHT"),
105: TKInputField.CHECK_INTEGER),
106: new TKInputField(MAX_SIZE_KEY, LENGTH_FIELD_SIZE,
107: LENGTH_FIELD_SIZE, LanguageManager.getText(
108: LANGUAGE_CONTEXT, "INPUT_MAXLENGTH"),
109: TKInputField.CHECK_OPTIONAL_INTEGER)
110:
111: };
112: TKFieldGroup textGroup = new TKFieldGroup(TKTextField.CLASS_ID,
113: new TKVector(textArray), LanguageManager.getText(
114: LANGUAGE_CONTEXT, TKTextField.CLASS_ID));
115: return textGroup;
116: }
117:
118: public Object toData() {
119: TKHashtable result = (TKHashtable) super .toData();
120:
121: result.put(ROWS_KEY, String.valueOf(rows));
122: result.put(COLS_KEY, String.valueOf(cols));
123:
124: if (maxSize > 0) {
125: result.put(MAX_SIZE_KEY, String.valueOf(maxSize));
126: }
127:
128: return result;
129: }
130:
131: public void fillIntoTemplate(TKHTMLTemplate t, Object value,
132: String prefix) {
133: super .fillIntoTemplate(t, value, prefix);
134:
135: t.set(ROWS_KEY, String.valueOf(rows));
136: t.set(COLS_KEY, String.valueOf(cols));
137:
138: if (maxSize > 0) {
139: t.set(MAX_SIZE_KEY, String.valueOf(maxSize));
140: }
141: }
142:
143: public void fillAttributesIntoNode(Element node, Object data)
144: throws DOMException {
145: super .fillAttributesIntoNode(node, data);
146: node.setAttribute(ROWS_KEY, String.valueOf(rows));
147: node.setAttribute(COLS_KEY, String.valueOf(cols));
148: node.setAttribute(MAX_SIZE_KEY, String.valueOf(maxSize));
149: }
150:
151: public int realInsertIntoDB(TKFormDBData db, int formId) {
152: if (super .realInsertIntoDB(db, formId) == -1)
153: return -1;
154: insertNewFieldAttribute(db, formId, ROWS_KEY, 0, String
155: .valueOf(rows));
156: insertNewFieldAttribute(db, formId, COLS_KEY, 0, String
157: .valueOf(cols));
158: insertNewFieldAttribute(db, formId, MAX_SIZE_KEY, 0, String
159: .valueOf(maxSize));
160: return fieldId;
161: }
162:
163: public void initFromDB(String classId, TKFormDBData db,
164: TKVector otherFields) throws TKUnregisteredClassException,
165: ClassNotFoundException, InstantiationException,
166: IllegalAccessException {
167: super .initFromDB(classId, db, otherFields);
168: rows = Integer.parseInt(getFieldAttribute(db, ROWS_KEY, 0));
169: cols = Integer.parseInt(getFieldAttribute(db, COLS_KEY, 0));
170: if (hasFieldAttribute(db, MAX_SIZE_KEY, 0))
171: maxSize = Integer.parseInt(getFieldAttribute(db,
172: MAX_SIZE_KEY, 0));
173: }
174:
175: public Object compileData(String prefix, TKHashtable data,
176: TKHashtable context) {
177: Object result = super .compileData(prefix, data, context);
178: Object[] args = new Object[1];
179: args[0] = fieldName;
180: String text = (String) data.get(prefix + fieldName);
181:
182: // Laenge ueberpruefen
183:
184: if (maxSize > 0) {
185: if (text.length() > maxSize && context != null) {
186: TKHashtable table = new TKHashtable();
187: table.put("DIAG", LanguageManager.getText(
188: LANGUAGE_CONTEXT, "TEXTFIELD_TOO_LONG", args));
189: table.put("PATH", prefix + fieldName);
190: addToContext(table, DIAGS_KEY, context);
191: }
192: }
193: return result;
194: }
195:
196: public Object compileData(String prefix, TKMarkupNode data,
197: TKHashtable context) {
198: TKXmlMarkup markup = data == null ? null
199: : (TKXmlMarkup) data.markup;
200: if (markup == null) {
201: return null;
202: }
203:
204: if (!markup.name.equals(getName())) {
205:
206: return null;
207: }
208:
209: TKXmlTree tree = (TKXmlTree) data.tree;
210: if (tree == null) {
211: return null;
212: }
213:
214: String val = tree.getSingleText();
215:
216: if (val == null)
217: return getDefault();
218: else
219: return val.trim();
220: }
221:
222: /**
223: * Checks wether this object and the specified object
224: * may be treated as equal.
225: *
226: * @param object the object to checked for equality.
227: * @return <CODE>true</CODE> if this object and the
228: * specified object may be treated as equal, otherwise
229: * <CODE>false</CODE>.
230: */
231: public boolean equals(Object object) {
232: if (!super .equals(object)) {
233: return false;
234: }
235:
236: TKTextField field = (TKTextField) object;
237:
238: return (this .rows == field.rows) && (this .cols == field.cols)
239: && (this .maxSize == field.maxSize);
240: }
241:
242: /**
243: * Returns the hash code for this object.
244: *
245: * @return the hash code for this object.
246: */
247: public int hashCode() {
248: // Implementation for JTest only ;-(
249: return super.hashCode();
250: }
251:
252: }
|