KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > lib > templates > TKTemplateData


1 package com.teamkonzept.lib.templates;
2
3 //import com.teamkonzept.lib.templates.xml.*;
4
import com.teamkonzept.lib.*;
5 import org.w3c.dom.*;
6 import de.webman.util.legacy.Legacy;
7
8 /**
9  * In dieser Klasse werden die Ersetzungsdaten eines Templates verwaltet.
10  *
11  * @author $Author: sebastian $
12  * @version $Revision: 1.25 $
13  */

14 public class TKTemplateData
15 {
16
17     /** incl. DOM Daten */
18     private DOMTemplateData domData;
19
20     /** Parent Template */
21     public TKTemplateData parent = null;
22
23     /** die TemplateVariablen */
24     private TKHashtable variables = new TKHashtable();
25
26     /** Lookup fuer Listenteilstuecke */
27     private TKTemplateData lookup = null;
28
29     /** der Listiterator */
30     private TKListIterator listIterator = null;
31
32     /** a hashtable of hashtables */
33     public TKHashtable enumerationContext = new TKHashtable();
34
35
36     /**
37      * Creates a new template data container.
38      */

39     public TKTemplateData ()
40     {
41         // NOP.
42
}
43
44     /**
45      * Creates a new template data container with the given parent.
46      *
47      * @param td the parent template data container.
48      */

49     public TKTemplateData (TKTemplateData td)
50     {
51         if (td == null)
52         {
53             return;
54         }
55
56         this.listIterator = td.listIterator;
57         this.parent = td;
58
59         merge(td);
60     }
61
62     /** @return DOMTemplateData */
63     public DOMTemplateData getDOMData()
64     {
65
66         try
67         {
68             if (domData == null)
69                 domData = new DOMTemplateData();
70             return domData;
71         }
72         catch (Exception JavaDoc e)
73         {
74             return null;
75         }
76     }
77
78     /**
79         Die Methode wird vor dem apply-Aufruf des zugeordneten Syntax-Objekts
80         aufgerufen um eventuelle globalen Vorbereitungen fŸr die Tag-Ersetzung
81         durchzufŸhren
82      */

83     public void prepareApply()
84     {
85     }
86
87     public TKListIterator getListIterator()
88     {
89 // if (domData == null)
90
return listIterator;
91 //
92
// return new DOMListIterator((DOMModel)domData);
93

94     }
95
96     public void setListIterator(TKListIterator iterator)
97     {
98         listIterator = iterator;
99     }
100
101     /**
102         Die Methode wird vor dem apply-Aufruf des Listen-Sub-Syntax-Objekts
103         aufgerufen um eventuelle globalen Vorbereitungen fŸr die Tag-Ersetzung
104         durchzufŸhren, bzw. um die in der Šu§eren Syntax definierten, und in
105         td Ÿbergebenene Ersetzungsdaten zu Ÿbernehmen
106      */

107     public void setMergedApply( TKTemplateData td )
108     {
109         lookup = td;
110         /* wer hatte das rausgenohmen und wieso ? ohne funktioniert die 1.5 nicht (Bug 789) */
111         variables = (( variables == null || variables.size() == 0 )
112             ? td.variables
113             : TKHashtable.merge( variables, td.variables )
114         );
115     }
116
117     /**
118         Erzeugt eine neue Hashtabelle aus der alten und der Uebergebenen, wobei
119         im Unterschied zu prepareMergedApply() auf jeden Fall ein neuer Scope
120         erzeugt wird, d.h. die uebergebene Tabelle nur kopiert wird und nicht evtl.
121         die alte ersetzt. Vorhandene Eintraege in der alten bleiben erhalten
122         (siehe TKHashtable.merge());
123      */

124     public void merge ( TKTemplateData td )
125     {
126         if (variables == null) variables = new TKHashtable();
127
128         if ((td != null) && (td.variables != null))
129             variables.merge (td.variables);
130     }
131
132     public void setVariable( Object JavaDoc key, Object JavaDoc value )
133     {
134         if( (parent == null) || (parent.variables != variables) ) {
135             variables.put( key, value );
136         }
137         if( parent != null ) {
138             parent.setVariable( key, value );
139         }
140     }
141
142     public void mergeVariables(TKHashtable merger)
143     {
144         variables.merge(merger);
145     }
146
147     public void concatVariables(TKHashtable merger)
148     {
149         variables.concat(merger);
150     }
151
152     public void removeVariable(String JavaDoc key)
153     {
154         variables.remove(key);
155     }
156
157     public Object JavaDoc getVariable(Object JavaDoc key)
158     {
159         Object JavaDoc back = variables.get(key);
160         if (back == null && lookup != null)
161             back = lookup.getVariable(key);
162 // if (back == null && domData != null)
163
// back = ((DOMModel)domData).getVariable((String) key);
164
return back;
165     }
166
167     public void setLocalVariable( Object JavaDoc key, Object JavaDoc value )
168     {
169         variables.put( key, value );
170     }
171
172     public void extendVariable( String JavaDoc key, Object JavaDoc value )
173     {
174         variables.extend( key, value );
175     }
176
177
178     /**
179     in nested lists, there is sometimes the neccessarity to pass some data from
180     the implementation of the outer iterator to the implementation of the inner
181     iterator. this can be done by the enumeration context. the implementation
182     ensures, that a enumerationContext which is set by a call of the apply-method
183     of the outer iterator is available to all corresponding apply-calls of the
184     inner iterator.
185     */

186
187     public void setEnumerationContext( Object JavaDoc key, Object JavaDoc value )
188     {
189         enumerationContext.put( key, value );
190     }
191
192     /**
193     @see setEnumerationContext
194     */

195
196     public Object JavaDoc getEnumerationContext(Object JavaDoc key )
197     {
198         Object JavaDoc result;
199         return ((result = enumerationContext.get( key )) == null)
200             ? ( parent == null ? null : parent.getEnumerationContext( key ) )
201             : result;
202     }
203
204 }
205
206
Popular Tags