KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > generator > SiteNodeStatics


1 package de.webman.generator;
2
3 import com.teamkonzept.db.*;
4 import com.teamkonzept.lib.*;
5 import com.teamkonzept.webman.db.*;
6 import de.webman.generator.db.queries.*;
7
8 import java.sql.*;
9 import java.util.*;
10 import org.apache.log4j.Category;
11
12 /**
13     * Diese Klasse baut den Tree aus SiteNodes auf und ruft alle weiteren Informationen
14     * ab
15     * @author $Author: alex $
16     * @version $Revision: 1.5 $
17 */

18 public class SiteNodeStatics
19 {
20
21     /**
22         Verweis zurück auf den aktuellen statischen Kontext des laufenden Threads
23     */

24     GeneratorContext context;
25
26     /** alle SiteNodes */
27     private TKHashtable nodeHash;
28     
29     /** Wurzel des Sitetrees */
30     private SiteNode root;
31
32     /** Log4J Kategory */
33     private static Category cat = Category.getInstance(SiteNodeStatics.class.getName());
34     
35     // singh 1 1999.04.08
36
// Bedeutung dieser Variablen ???
37
private boolean reducedBuild;
38     private boolean indexBuild;
39     
40     // Argumente fuer partielles Generieren
41
private int subtreeId;
42     private String JavaDoc subtreePath;
43     private String JavaDoc includeSubtreePath;
44     private SiteNode subtreeNode;
45
46     public SiteNodeStatics (GeneratorContext context) {
47
48         this.context = context != null ? context : GeneratorContext.setup ();
49
50         this.nodeHash = null;
51         this.root = null;
52         this.reducedBuild = false;
53         this.indexBuild = false;
54
55         this.subtreeId = -1;
56         this.subtreePath = null;
57         this.includeSubtreePath = null;
58         this.subtreeNode = null;
59     }
60
61     public boolean isReducedBuild()
62     {
63         return reducedBuild;
64     }
65     
66     public boolean isIndexBuild()
67     {
68         return indexBuild;
69     }
70     
71     public void setReducedBuild(boolean isReduced)
72     {
73         reducedBuild = isReduced;
74     }
75     
76     public void setIndexBuild(boolean isIndex)
77     {
78         indexBuild = isIndex;
79     }
80     
81     public String JavaDoc getIncludeSubtreePath()
82     {
83         return includeSubtreePath;
84     }
85     
86     public void setIncludeSubtreePath(String JavaDoc subPath)
87     {
88         includeSubtreePath = subPath;
89     }
90     
91     public String JavaDoc getSubtreePath()
92     {
93         return subtreePath;
94     }
95     
96     public void setSubtreePath(String JavaDoc path)
97     {
98         subtreePath = path;
99     }
100     
101     public SiteNode getSubtreeNode()
102     {
103         return subtreeNode;
104     }
105     
106     public void setSubtreeNode(SiteNode node)
107     {
108         subtreeNode = node;
109     }
110     
111     public int getSubtreeId()
112     {
113         return subtreeId;
114     }
115     
116     public void setSubtreeId(int id)
117     {
118         subtreeId = id;
119     }
120     
121     /**
122     Checks - in case of subtree generation - if the the corresponding SiteNode 'subtreeNode'
123     was found.
124     @return subtree node was found, else false.
125     */

126     public boolean subTreeUnmatched () {
127
128         return ((subtreePath != null) || (subtreeId >= 0)) && (subtreeNode == null);
129     }
130
131     /**
132         zentrale Methode, sucht alle Informationen zusammen, die
133         zur Generierung gebraucht werden
134     */

135     public SiteNode buildSiteTree()
136     {
137         SiteNode root;
138         cat.info("start build Site-Structure");
139         
140         // alle verwendeten Contents einlesen
141
context.contentNodes.getContents();
142         cat.debug("got Contents");
143         
144         context.integrations.initSelection();
145         
146         // alle Dokumenttypen lesen
147
context.referenceTypes.getTypes();
148         
149         // Sitetree einlesen und als Baum von SiteNodes speichern
150
// noch in eine Methode auslagern
151
try
152         {
153             TKQuery q = TKWebmanDBManager.newQuery(GenSiteTree.class);
154             q.execute();
155             ResultSet rs = q.fetchResultSet();
156             if( !rs.next() ) return null;
157
158             nodeHash = new TKHashtable();
159
160             root = new SiteNode( context, rs, null );
161             SiteNode last = root;
162             nodeHash.put( new Integer JavaDoc( root.getId() ), root );
163             while( rs.next() ) {
164                 last = new SiteNode( context, rs, last );
165
166                 // singh + 1999.06.25
167
if ((subtreeNode != null) && (last.getParent().getId() == subtreeNode.getParent().getId()) &&
168                     (last.getId() != subtreeNode.getId())) break;
169
170                 if (!subTreeUnmatched ())
171                     nodeHash.put( new Integer JavaDoc( last.getId() ), last );
172             }
173             if (subTreeUnmatched ()) return null;
174
175             // singh + 1999.06.25
176
// Aufraeumen ...
177
SiteNode node = subtreeNode;
178             while (node != null) {
179
180                 SiteNode parent = node.getParent();
181                 if (parent == null) break;
182
183                 parent.getChilds().removeAllElements();
184                 parent.getChilds().addElement(node);
185                 nodeHash.put( new Integer JavaDoc( parent.getId() ), parent );
186
187                 node = parent;
188             }
189             
190             // rekursives Erzeugen aller SiteDocuments
191
root.readDocuments();
192             cat.debug("got documents");
193             
194             if (indexBuild)
195             {
196                 // fuer preview
197
root.getContentIntegrations();
198                 cat.debug("got integrations");
199                 root.doContentSelections();
200                 cat.debug("did selections");
201                 return root;
202             }
203             // rekursives Erzeugen aller SiteReferences
204
root.readReferences();
205             cat.debug("got refs");
206             
207             // Auslesen aller Sitestrukturparameter
208
root.readStructureContents();
209             cat.debug("got structure contents");
210             
211             // Auslesen aller Contentzuordnungen in den Dokumenten
212
root.getContentIntegrations();
213             
214             cat.debug("got integrations");
215             
216             // vererbte Dokumente erzeugen
217
root.assignInheritableDocuments();
218
219             cat.debug("got inheritance");
220             cat.debug("Reduced Build : " + reducedBuild);
221             if (reducedBuild) return root;
222
223             // Auswerten der Referenzen
224
root.expandReferences();
225             cat.debug("refs expanded");
226             
227             // Aufloesen der Referenzen mit Contentzugriff
228
root.findReferenceContentDocuments();
229             cat.debug("got referenced contents");
230
231             // loest die Content Selektoren auf ???
232
root.doContentSelections();
233             cat.debug("Site-Structure finished");
234         }
235         catch( SQLException e )
236         {
237             throw new TKSQLError( e.getMessage(), e );
238         }
239         finally
240         {
241             try
242             {
243                 if (TKDBManager.getDBVendor() == QueryConstants.ORACLE)
244                     TKDBManager.closeConnection();
245             }
246             catch (Exception JavaDoc e)
247             {
248                 cat.error("Oracle spezial", e);
249             }
250         }
251         return root;
252     }
253
254     /**
255         Baut im Falle eines indexBuild den SiteTree so aus
256         wie es einem reducedBuild entspricht, falls dieser
257         gewünscht ist, ansonsten kompletter Ausbau.
258
259         Diese Funktion wird z.B. beim Aufruf eines Previews
260         (setzt u.U. reducedBuild auf true) aus der Index-Funktion
261         (setzt u.U. indexBuild auf true) vor dem Preview gebraucht.
262
263         Ist indexBuild nicht gesetzt ist der SiteTree bereits so
264         aufgebaut, wie es der Preview braucht ...
265
266     */

267     public void completeSiteTree(SiteNode root)
268     {
269         try {
270             if (!indexBuild) return;
271
272             root.readReferences();
273             root.readStructureContents();
274             root.assignInheritableDocuments();
275             
276             if (reducedBuild) return;
277
278             root.expandReferences();
279             root.findReferenceContentDocuments();
280             root.doContentSelections();
281         }
282         catch( SQLException e )
283         {
284             throw new TKSQLError( e.getMessage(), e );
285         }
286
287     }
288
289     public SiteNode getRoot()
290     {
291         return root;
292     }
293     
294     public void setRoot(SiteNode node)
295     {
296         root = node;
297     }
298     
299     public Enumeration getAllNodes()
300     {
301         return nodeHash.keys();
302     }
303     
304     public SiteNode getNode( int nodeId )
305     {
306         return (SiteNode) nodeHash.get( new Integer JavaDoc( nodeId ) );
307     }
308 }
309
Popular Tags