KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > webman > mainint > TKContentAttributeIterator


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 JavaDoc 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 JavaDoc (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 JavaDoc(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 JavaDoc item, TKTemplate template, String JavaDoc 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 JavaDoc(data.content_id));
53         template.set( "VALUE_ID", new Integer JavaDoc(data.value_id));
54         template.set( "TYPE", new Integer JavaDoc(data.type));
55         template.set( "TYPE_INFO", TKContentAttributeTableData.typeInfo(data.type));
56         template.set( "ATTRIBUTE_INDEX", new Integer JavaDoc(attr_index));
57         template.set( "ATTRIBUTE_ID", new Integer JavaDoc(data.attribute_id));
58         template.set( "NO_ID", new Integer JavaDoc (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             // scanne datum
64
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 JavaDoc(0));
70                     
71                     template.set("DAY", new Integer JavaDoc(date.getDate()));
72                     template.set("MONTH", new Integer JavaDoc(date.getMonth() + 1));
73                     template.set("YEAR", new Integer JavaDoc(date.getYear() + JAVAYEAR));
74                     template.set("HOUR", new Integer JavaDoc(date.getHours()));
75                     template.set("MINUTE", new Integer JavaDoc(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 JavaDoc currListName, String JavaDoc path) {
88
89         if ((options != null) && options.apply (template,i,currListName,null)) return true;
90         else return false;
91     }
92 }
Free Books   Free Magazines  
Popular Tags