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 org.w3c.dom.*;
008:
009: /**
010: * The atom field control.
011: *
012: * Die Klasse TKAtomField ist die Basisklasse aller HTML-Eingabe-Objekte
013: * für HTML-Formulare.
014: *
015: * @author $Author: uli $
016: * @version $Revision: 1.18 $
017: */
018: public abstract class TKAtomField extends TKBaseField {
019: // $Id: TKAtomField.java,v 1.18 2002/02/25 17:47:40 uli Exp $
020:
021: protected StringBuffer paramClasses = new StringBuffer();
022:
023: protected TKAtomField() {
024: };
025:
026: protected TKAtomField(String fieldType, String fieldName,
027: String showName) {
028: initAtomField(fieldType, fieldName, showName);
029: }
030:
031: public final void initAtomField(String fieldType, String fieldName,
032: String showName) {
033: initBaseField(fieldType, fieldName, showName);
034: }
035:
036: public void addClass(String newClass) {
037: if ((newClass == null) || (newClass.length() == 0))
038: return;
039:
040: paramClasses.append(";" + newClass);
041: }
042:
043: public Object compileData(String prefix, TKHashtable data,
044: TKHashtable context) {
045: Object result = data.get(prefix + fieldName);
046: if (result == null)
047: return getDefault();
048: return result;
049: }
050:
051: public Object compileData(String prefix, TKMarkupNode data,
052: TKHashtable context) {
053: TKXmlMarkup markup = data == null ? null
054: : (TKXmlMarkup) data.markup;
055: if (markup == null) {
056: return null;
057: }
058:
059: if (!markup.name.equals(getName())) {
060: return null;
061: }
062:
063: String val = TKMarkupParam.paramValue(markup.params, "VALUE");
064:
065: if (val == null)
066: return getDefault();
067: else
068: return val;
069: }
070:
071: public void fillIntoTemplate(TKHTMLTemplate t, Object value,
072: String prefix) {
073: super .fillIntoTemplate(t, value, prefix);
074: t.set("CLASSES", paramClasses);
075: if (value != null)
076: t.set("VALUE", value);
077: }
078:
079: public void fillIntoPresentation(TKHTMLTemplate t, Object data,
080: String scope) {
081: String scopedName = scope + "." + getName();
082: TKVector realData;
083: if (data instanceof TKVector) {
084: realData = (TKVector) data;
085: } else {
086: realData = new TKVector(1);
087: realData.addElement(data);
088: }
089:
090: t.set(scopedName, data.toString());
091: t.set(scopedName + ".SIZE", String.valueOf(realData.size()));
092: // das so lassen ???
093: t.setListIterator(new TKAtomFieldShowIterator(realData, t
094: .getListIterator(), scopedName));
095: }
096:
097: /**
098: Feldklassen repraesentieren sich als DOM Baum
099: @param doc Documentroot zum Erzeugen weiterer Elemente
100: @param node Vaterknoten, an den weitere Knoten rangehaengt werden
101: */
102: public void fillIntoDOM(Document doc, Element node, Object data)
103: throws DOMException {
104: Element me = doc.createElement(getInternationalName());
105: node.appendChild(me);
106: fillAttributesIntoNode(me, data);
107: fillDataIntoNode(doc, me, data);
108: }
109:
110: /**
111: fuellt in den DOM Node die Daten ein
112: */
113: protected void fillDataIntoNode(Document doc, Element node,
114: Object data) throws DOMException {
115: if (data != null) {
116: TKVector realData;
117: if (data instanceof TKVector) {
118: realData = (TKVector) data;
119: node.setAttribute(MULTIPLE, Boolean.TRUE.toString());
120: } else {
121: realData = new TKVector();
122: realData.addElement(data);
123: node.setAttribute(MULTIPLE, Boolean.FALSE.toString());
124: }
125: for (int i = 0; i < realData.size(); i++) {
126: createValueNode(doc, node, realData.elementAt(i)
127: .toString());
128: }
129: }
130: }
131:
132: protected void createValueNode(Document doc, Element node,
133: String data) throws DOMException {
134: Element me = doc.createElement(VALUE_NODE_NAME);
135: node.appendChild(me);
136: Text txt = doc.createTextNode(data);
137: me.appendChild(txt);
138: }
139:
140: public int insertDataIntoDB(TKContentDBData db, Object data,
141: int contentId, int leftNr) {
142: TKContentNodeTableData node = insertNewContentNode(db,
143: contentId, leftNr);
144: int newNodeId = node.content_node_id;
145: if (data instanceof TKVector) {
146: TKVector values = (TKVector) data;
147: for (int i = 0; i < values.size(); i++) {
148: insertNewContentValue(db, contentId, newNodeId, i,
149: (String) values.get(i));
150: }
151: } else if (data != null) {
152: insertNewContentValue(db, contentId, newNodeId, 0,
153: (String) data);
154: }
155: return leftNr + 1;
156: }
157:
158: public Object getDataFromDB(TKContentDBData db) {
159: TKContentNodeTableData node = getContentNodeFromDB(db);
160: TKContentValueTableData value;
161: boolean done = false;
162: TKVector result = new TKVector();
163: do {
164: try {
165: value = getContentNodeValueFromDB(db, node);
166: result.addElement(value.value);
167: } catch (Throwable e) {
168: done = true;
169: }
170: } while (!done);
171:
172: int size = result.size();
173: if (size == 0)
174: return null;
175: if (size == 1)
176: return result.elementAt(0);
177: return result;
178: }
179:
180: }
|