1 package com.teamkonzept.webman.mainint; 2 3 import com.teamkonzept.field.*; 4 import com.teamkonzept.field.db.*; 5 import com.teamkonzept.lib.*; 6 7 import java.util.*; 8 9 public class TKContentAttributeIterator extends TKIteratorPlugin { 10 11 private static final int JAVAYEAR = 1900; 12 private int attr_index; 13 private TKContentAttributeOptionsIterator options; 14 15 TKContentAttributeIterator (String listName, TKVector list) { 16 17 super (list,listName,true); 18 19 TKHashtable currentAttributes = new TKHashtable(); 20 Enumeration e = list.elements(); 21 while (e.hasMoreElements()) { 22 23 TKContentAttributeTableData data = (TKContentAttributeTableData) e.nextElement(); 24 currentAttributes.put (new Integer (data.attribute_id),data); 25 } 26 27 TKHashtable availableAttributes = new TKHashtable(); 28 e = TKContentAttributeOption.getOptions().elements(); 29 while (e.hasMoreElements()) { 30 31 TKContentAttributeOption option = (TKContentAttributeOption) e.nextElement(); 32 if (currentAttributes.get(new Integer (option.attributeId)) == null) 33 availableAttributes.put (option.name,option); 34 } 35 36 options = new TKContentAttributeOptionsIterator ("ATTRIBUTE_OPTIONS",availableAttributes); 37 } 38 39 public void init () { 40 41 attr_index = -1; 42 } 43 44 public boolean applyThis (Object item, TKTemplate template, String path) { 45 46 if (item == null) return false; 47 48 attr_index++; 49 50 TKContentAttributeTableData data = (TKContentAttributeTableData) item; 51 52 template.set( "CONTENT_ID", new Integer (data.content_id)); 53 template.set( "VALUE_ID", new Integer (data.value_id)); 54 template.set( "TYPE", new Integer (data.type)); 55 template.set( "TYPE_INFO", TKContentAttributeTableData.typeInfo(data.type)); 56 template.set( "ATTRIBUTE_INDEX", new Integer (attr_index)); 57 template.set( "ATTRIBUTE_ID", new Integer (data.attribute_id)); 58 template.set( "NO_ID", new Integer (new TKContentAttributeOption ().attributeId)); 59 60 if (data.name != null) template.set( "NAME", data.name ); 61 if (data.value != null) template.set( "ATTRIBUTE_VALUE",data.value); 62 { 63 if (data.type == TKContentAttributeTableData.dateType) 65 { 66 if (data.value.length() != 0) 67 { 68 69 Date date = TKContentAttributeTableData.dateScanFormat.parse(data.value, new java.text.ParsePosition (0)); 70 71 template.set("DAY", new Integer (date.getDate())); 72 template.set("MONTH", new Integer (date.getMonth() + 1)); 73 template.set("YEAR", new Integer (date.getYear() + JAVAYEAR)); 74 template.set("HOUR", new Integer (date.getHours())); 75 template.set("MINUTE", new Integer (date.getMinutes())); 76 } 77 } 78 else 79 { 80 template.set( "ATTRIBUTE_VALUE",data.value); 81 } 82 } 83 84 return true; 85 } 86 87 public boolean applyChilds (TKTemplate template, int i, String currListName, String path) { 88 89 if ((options != null) && options.apply (template,i,currListName,null)) return true; 90 else return false; 91 } 92 } | Popular Tags |