001: package com.teamkonzept.webman.mainint;
002:
003: import com.teamkonzept.field.*;
004: import com.teamkonzept.field.db.*;
005: import com.teamkonzept.lib.*;
006:
007: import java.util.*;
008:
009: public class TKContentAttributeIterator extends TKIteratorPlugin {
010:
011: private static final int JAVAYEAR = 1900;
012: private int attr_index;
013: private TKContentAttributeOptionsIterator options;
014:
015: TKContentAttributeIterator(String listName, TKVector list) {
016:
017: super (list, listName, true);
018:
019: TKHashtable currentAttributes = new TKHashtable();
020: Enumeration e = list.elements();
021: while (e.hasMoreElements()) {
022:
023: TKContentAttributeTableData data = (TKContentAttributeTableData) e
024: .nextElement();
025: currentAttributes.put(new Integer(data.attribute_id), data);
026: }
027:
028: TKHashtable availableAttributes = new TKHashtable();
029: e = TKContentAttributeOption.getOptions().elements();
030: while (e.hasMoreElements()) {
031:
032: TKContentAttributeOption option = (TKContentAttributeOption) e
033: .nextElement();
034: if (currentAttributes.get(new Integer(option.attributeId)) == null)
035: availableAttributes.put(option.name, option);
036: }
037:
038: options = new TKContentAttributeOptionsIterator(
039: "ATTRIBUTE_OPTIONS", availableAttributes);
040: }
041:
042: public void init() {
043:
044: attr_index = -1;
045: }
046:
047: public boolean applyThis(Object item, TKTemplate template,
048: String path) {
049:
050: if (item == null)
051: return false;
052:
053: attr_index++;
054:
055: TKContentAttributeTableData data = (TKContentAttributeTableData) item;
056:
057: template.set("CONTENT_ID", new Integer(data.content_id));
058: template.set("VALUE_ID", new Integer(data.value_id));
059: template.set("TYPE", new Integer(data.type));
060: template.set("TYPE_INFO", TKContentAttributeTableData
061: .typeInfo(data.type));
062: template.set("ATTRIBUTE_INDEX", new Integer(attr_index));
063: template.set("ATTRIBUTE_ID", new Integer(data.attribute_id));
064: template.set("NO_ID", new Integer(
065: new TKContentAttributeOption().attributeId));
066:
067: if (data.name != null)
068: template.set("NAME", data.name);
069: if (data.value != null)
070: template.set("ATTRIBUTE_VALUE", data.value);
071: {
072: // scanne datum
073: if (data.type == TKContentAttributeTableData.dateType) {
074: if (data.value.length() != 0) {
075:
076: Date date = TKContentAttributeTableData.dateScanFormat
077: .parse(data.value,
078: new java.text.ParsePosition(0));
079:
080: template.set("DAY", new Integer(date.getDate()));
081: template.set("MONTH", new Integer(
082: date.getMonth() + 1));
083: template.set("YEAR", new Integer(date.getYear()
084: + JAVAYEAR));
085: template.set("HOUR", new Integer(date.getHours()));
086: template.set("MINUTE", new Integer(date
087: .getMinutes()));
088: }
089: } else {
090: template.set("ATTRIBUTE_VALUE", data.value);
091: }
092: }
093:
094: return true;
095: }
096:
097: public boolean applyChilds(TKTemplate template, int i,
098: String currListName, String path) {
099:
100: if ((options != null)
101: && options.apply(template, i, currListName, null))
102: return true;
103: else
104: return false;
105: }
106: }
|