001: package com.teamkonzept.webman.field;
002:
003: import com.teamkonzept.lib.*;
004: import com.teamkonzept.lib.templates.*;
005: import com.teamkonzept.publishing.markups.*;
006: import com.teamkonzept.web.*;
007: import com.teamkonzept.field.*;
008: import com.teamkonzept.field.db.*;
009: import com.teamkonzept.webman.attr.*;
010: import com.teamkonzept.international.LanguageManager;
011: import org.w3c.dom.*;
012:
013: /**
014: * The attributed text field.
015: *
016: * @author $Author: uli $
017: * @version $Revision: 1.25 $
018: */
019: public class TKWMTextAttrField extends TKTextField {
020: // $Id: TKWMTextAttrField.java,v 1.25 2002/02/25 17:05:16 uli Exp $
021:
022: public static final String CLASS_ID = "ATTR_TEXT";
023:
024: /**
025: * Creates an empty field.
026: */
027: public TKWMTextAttrField() {
028: super ();
029: }
030:
031: public TKWMTextAttrField(String name, int rows, int cols,
032: int maxSize) {
033: super (name, rows, maxSize, cols);
034: }
035:
036: public TKWMTextAttrField(String name, int rows, int cols,
037: int maxSize, String showName) {
038:
039: super (name, rows, cols, maxSize, showName);
040: }
041:
042: /**
043: * Methode zur Definition eines Textfeldes
044: */
045: public TKFieldGroup getDefGroup(TKFieldSwitch allSwitch,
046: TKFieldSwitchList allSwitchList) {
047: TKBaseField[] textArray = {
048: new TKInputField(TKTextField.NAME_KEY,
049: TKInputField.SMALL_DEFAULT_SIZE,
050: TKInputField.SMALL_DEFAULT_LENGTH,
051: LanguageManager.getText(LANGUAGE_CONTEXT,
052: "INPUT_NAME"),
053: TKInputField.CHECK_STRING),
054: new TKInputField(TKTextField.SHOW_NAME_KEY,
055: TKInputField.LARGE_DEFAULT_SIZE,
056: TKInputField.LARGE_DEFAULT_LENGTH,
057: LanguageManager.getText(LANGUAGE_CONTEXT,
058: "INPUT_SHOWNAME"),
059: TKInputField.CHECK_STRING),
060: new TKInputField(TKTextField.COLS_KEY, 3, 3,
061: LanguageManager.getText(LANGUAGE_CONTEXT,
062: "TEXTFIELD_WIDTH"),
063: TKInputField.CHECK_INTEGER),
064: new TKInputField(TKTextField.ROWS_KEY, 3, 3,
065: LanguageManager.getText(LANGUAGE_CONTEXT,
066: "TEXTFIELD_HEIGHT"),
067: TKInputField.CHECK_INTEGER),
068: new TKInputField(MAX_SIZE_KEY, 6, 6, LanguageManager
069: .getText(LANGUAGE_CONTEXT, "INPUT_MAXLENGTH"),
070: TKInputField.CHECK_OPTIONAL_INTEGER)
071:
072: };
073: TKFieldGroup textGroup = new TKFieldGroup(
074: TKWMTextAttrField.CLASS_ID, new TKVector(textArray),
075: LanguageManager.getText(LANGUAGE_CONTEXT,
076: TKWMTextAttrField.CLASS_ID));
077: return textGroup;
078: }
079:
080: public Object compileData(String prefix, TKHashtable data,
081: TKHashtable context) {
082: TKMarkupAdmin.setup();
083: Object[] args = new Object[1];
084: args[0] = fieldName;
085: String text = (String) data.get(prefix + fieldName);
086: TKWMTextAttrData attrData = new TKWMTextAttrData(prefix
087: + fieldName, text, data);
088: // Laenge ueberpruefen
089: if (attrData.hasDiagnostics() && context != null) {
090: TKHashtable table = new TKHashtable();
091: table.put("DIAG", "attributiertes Textfeld " + fieldName
092: + " enthält fehlerhaften Content");
093: table.put("PATH", prefix + fieldName);
094: addToContext(table, DIAGS_KEY, context);
095: }
096: if (maxSize > 0) {
097: if (attrData.getXML().length() > maxSize && context != null) {
098: TKHashtable table = new TKHashtable();
099: table.put("DIAG", LanguageManager.getText(
100: LANGUAGE_CONTEXT, "TEXTFIELD_TOO_LONG", args));
101: table.put("PATH", prefix + fieldName);
102: addToContext(table, DIAGS_KEY, context);
103: }
104: }
105: return attrData;
106: }
107:
108: public Object compileData(String prefix, TKMarkupNode data,
109: TKHashtable context) {
110: TKXmlMarkup markup = data == null ? null
111: : (TKXmlMarkup) data.markup;
112: if (markup == null) {
113: return null;
114: }
115:
116: if (!markup.name.equals(getName())) {
117: return null;
118: }
119:
120: TKXmlTree tree = (TKXmlTree) data.tree;
121: if (tree == null) {
122: return null;
123: }
124:
125: String val = tree.convert2Markup();
126: val = val == null ? (String) getDefault() : val.trim();
127:
128: TKWMTextAttrData attrData = new TKWMTextAttrData(val);
129: attrData.scanData();
130:
131: return attrData;
132: }
133:
134: protected void fillDataIntoNode(Document doc, Element node,
135: Object data) throws DOMException {
136: Element me = doc.createElement(VALUE_NODE_NAME);
137: node.appendChild(me);
138: TKWMTextAttrData attrData = (TKWMTextAttrData) data;
139: Text txt = doc.createTextNode(attrData.getXML());
140: me.appendChild(txt);
141: }
142:
143: public int insertDataIntoDB(TKContentDBData db, Object data,
144: int contentId, int leftNr) {
145:
146: TKWMTextAttrData attrData = (TKWMTextAttrData) data;
147: return super .insertDataIntoDB(db, attrData.getExpansion(),
148: contentId, leftNr);
149: }
150:
151: public Object getDataFromDB(TKContentDBData db) {
152:
153: TKMarkupAdmin.setup();
154:
155: Object content = super .getDataFromDB(db);
156:
157: if (content == null)
158: return null;
159:
160: TKWMTextAttrData attrData = null;
161:
162: if (content instanceof String) {
163:
164: attrData = new TKWMTextAttrData((String) content);
165: } else {
166:
167: TKVector vec = (TKVector) content;
168: if (vec.size() == 0)
169: return null;
170:
171: attrData = new TKWMTextAttrData((String) vec.get(0));
172: }
173:
174: attrData.scanData();
175:
176: return attrData;
177: }
178:
179: public void fillIntoTemplate(TKHTMLTemplate t, Object value,
180: String prefix) {
181:
182: TKWMTextAttrData attrData = (TKWMTextAttrData) value;
183:
184: if (attrData == null) {
185:
186: super .fillIntoTemplate(t, null, prefix);
187: return;
188: }
189:
190: super .fillIntoTemplate(t, attrData.getDigest(), prefix);
191:
192: TKTemplateSyntax syntax = attrData.getSyntax(t);
193: if (syntax != null)
194: t.set("FULL_VALUE", syntax);
195:
196: if (attrData.hasMarkups())
197: t.set(prefix + fieldName + ".HAS_MARKUPS", Boolean.TRUE);
198: if (attrData.hasDiagnostics())
199: t
200: .set(prefix + fieldName + ".HAS_DIAGNOSTICS",
201: Boolean.TRUE);
202: if (attrData.hasDump())
203: t.set(prefix + fieldName + ".HAS_DUMP", Boolean.TRUE);
204:
205: TKWMTextAttrIterator iterator = new TKWMTextAttrIterator(prefix
206: + fieldName, attrData, t.getListIterator());
207:
208: t.setListIterator(iterator);
209: }
210:
211: public void fillIntoPresentation(TKHTMLTemplate t, Object value,
212: String prefix) {
213:
214: TKWMTextAttrData attrData = (TKWMTextAttrData) value;
215:
216: TKTemplateSyntax syntax = attrData == null ? null : attrData
217: .getSyntax(t);
218: if (syntax != null)
219: t.set(prefix + "." + getName(), syntax);
220: }
221:
222: public Object modify(String action, String fieldPath, Object data,
223: String prefix, StringBuffer destination) {
224:
225: destination.append(prefix + fieldName);
226:
227: return data;
228: }
229:
230: public Object getDefault() {
231: TKMarkupAdmin.setup();
232:
233: TKWMTextAttrData attrData = new TKWMTextAttrData("");
234:
235: attrData.scanData();
236:
237: return attrData;
238: }
239:
240: }
|