KickJava   Java API By Example, From Geeks To Geeks.

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


1 package de.webman.generator;
2
3 import com.teamkonzept.lib.*;
4
5 import java.util.*;
6
7 /**
8     Statische Daten und Methoden von ContentCall
9     * @author $Author: alex $
10     * @version $Revision: 1.4 $
11  */

12 public class ContentCallStatics
13 {
14
15     /**
16         ist das setup schon gelaufen ??
17     */

18     private boolean setUpDone = false;
19     
20     /**
21         Verweis zurück auf den aktuellen statischen Kontext des laufenden Threads
22     */

23     private GeneratorContext context;
24
25     /**
26         Liefert zu jeder Content-Id eine Liste (TKVector) von ContentCall
27      */

28     private TKHashtable index;
29     
30     /**
31         Liefert zu jeder Kombination (instance-Id / Dokument) einen
32         ContentCall, soweit bereits vorhanden
33     */

34     private TKHashtable contentCall;
35
36     public ContentCallStatics (GeneratorContext context)
37     {
38         this.context = context != null ? context : GeneratorContext.setup ();
39         this.index = null;
40         this.contentCall = null;
41     }
42     
43     public void addCall (ContentCall call)
44     {
45         if (call == null) return;
46         if (call.getContent() == null) return;
47
48         Integer JavaDoc instanceId = new Integer JavaDoc (call.getContent().getInstanceId());
49         TKVector list = (TKVector) index.get (instanceId);
50         
51         if (list == null)
52         {
53             list = new TKVector ();
54             index.put (instanceId, list);
55         }
56         
57         list.addElement (call);
58     }
59     
60     public void addCall (
61                 SiteContent content,
62                 SiteDocument doc,
63                 SiteContentIntegration integration,
64                 SiteContentNode node,
65                 int primId,
66                 boolean isPrim,
67                 boolean isRef,
68                 boolean isStructure)
69     {
70         String JavaDoc key = content.getInstanceId() + " " + doc.getAnchor().getId() + " " + doc.getIndex() + " " + primId;
71         ContentCall call = (ContentCall) contentCall.get (key);
72         if (call != null)
73         {
74             if (!isRef) call.setPerReference(false);
75             if (!isStructure) call.setStructureContent(false);
76             
77             if (!isPrim && !call.isPerReference() && !call.isStructureContent())
78                 call.setPrimaryContent(false);
79             return;
80         }
81         
82         call = new ContentCall (context, content,doc,integration,node,primId,isPrim,isRef,isStructure);
83         addCall (call);
84         contentCall.put (key,call);
85     }
86     
87     public TKVector getCalls (Integer JavaDoc instanceId)
88     {
89         return (TKVector) index.get (instanceId);
90     }
91     
92     public void setupDocument (
93         SiteDocument contentSource,
94         SiteDocument refSource,
95         SiteContent primContent)
96     {
97         if (contentSource == null) return;
98         
99         boolean isRef = refSource != null;
100         if (refSource == null) refSource = contentSource;
101         
102         int primId = primContent != null ? primContent.getInstanceId() : -1;
103         
104         Enumeration e = contentSource.getContents().elements();
105         while (e.hasMoreElements())
106         {
107             SiteContentIntegration ci = (SiteContentIntegration) e.nextElement();
108             if (ci == null) continue;
109                     
110             TKVector conts = ci.getContents();
111             if (conts == null)
112             {
113                 if (primContent != null)
114                     addCall (primContent, refSource, ci, ci.getContentNode(), primId, true, isRef, false);
115             } else
116             {
117                 Enumeration ee = conts.elements();
118                 while (ee.hasMoreElements())
119                 {
120                     SiteContent sc = (SiteContent) ee.nextElement();
121                     if (sc != null) addCall (sc,refSource,ci, ci.getContentNode(), primId, false, isRef, false);
122                 }
123             }
124         }
125                 
126         e = contentSource.getStructureContents().elements();
127         while (e.hasMoreElements())
128         {
129             SiteContent sc = (SiteContent) e.nextElement();
130             if (sc == null) continue;
131             addCall (sc,refSource,null,null,primId,false,isRef,true);
132         }
133         
134         if (isRef) return;
135         
136         e = refSource.getReferences().elements();
137         while (e.hasMoreElements())
138         {
139             SiteReference sr = (SiteReference) e.nextElement();
140             if (sr == null) continue;
141             if (sr.getDestinationContentSource() == null) continue;
142                     
143             for (int i = 0; i < sr.getDestinationDocuments().length; i++)
144             {
145                 SiteDocument rsd = sr.getDestinationDocuments()[i];
146                 if (rsd == null) continue;
147                         
148                 SiteNode rsn = rsd.getAnchor();
149                 if (rsn == null) continue;
150                         
151                 SiteDocument anotherContentSource =
152                     (SiteDocument) rsn.getDocumentNameHash().get (sr.getDestinationContentSource());
153                     
154                 if ((refSource != anotherContentSource) &&
155                     (anotherContentSource != null))
156                     setupDocument (anotherContentSource,refSource,primContent);
157             }
158         }
159     }
160     
161     /**
162         baut einmal alle Aufrufe von Contents in Dokumenten zusammen,
163         wird beim Preview benutzt, um die Indexseiten zusammenzubauen
164     */

165     public void setup ()
166     {
167         if (setUpDone)
168             return;
169         index = new TKHashtable();
170         contentCall = new TKHashtable();
171
172         Enumeration allSiteNodes = context.siteNodes.getAllNodes();
173         while( allSiteNodes.hasMoreElements() )
174         {
175             Integer JavaDoc id = (Integer JavaDoc) allSiteNodes.nextElement();
176             
177             SiteNode siteNode = (SiteNode) context.siteNodes.getNode(id.intValue());
178
179             if (siteNode == null) continue;
180             
181             if (siteNode.getType() == SiteNode.NODE_TYPE_GROUP)
182             {
183                 TKVector primConts = null;
184             
185                 if( siteNode.getPrimaryContentSelectionKey() != null )
186                     primConts = context.integrations.getSelection( siteNode.getPrimaryContentSelectionKey() );
187                 else if (siteNode.getPrimaryContentNode() != null)
188                     primConts = siteNode.getPrimaryContentNode().getContents();
189                     
190                 if (primConts == null) continue;
191
192                 Enumeration primContents = primConts.elements();
193                 while (primContents.hasMoreElements())
194                 {
195                     SiteContent siteContent = (SiteContent) primContents.nextElement();
196                     if (siteContent == null) continue;
197                 
198                     Enumeration siteDocuments = siteNode.getDocuments().elements();
199                     while( siteDocuments.hasMoreElements() )
200                     {
201                         SiteDocument siteDocument = (SiteDocument) siteDocuments.nextElement();
202                         if (siteDocument != null) setupDocument (siteDocument, null, siteContent);
203                     }
204                 }
205             } else
206             {
207                 Enumeration siteDocuments = siteNode.getDocuments().elements();
208                 while( siteDocuments.hasMoreElements() )
209                 {
210                     SiteDocument siteDocument = (SiteDocument) siteDocuments.nextElement();
211                     if (siteDocument != null) setupDocument (siteDocument, null, null);
212                 }
213             }
214         }
215         setUpDone = true;
216     }
217 }
218
219
Popular Tags