KickJava   Java API By Example, From Geeks To Geeks.

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


1 package de.webman.generator;
2
3 import com.teamkonzept.lib.*;
4 import com.teamkonzept.lib.templates.TemplateTypes;
5 import com.teamkonzept.web.*;
6
7 import com.oroinc.text.regex.*;
8 import org.w3c.dom.*;
9 import de.webman.util.legacy.Legacy;
10
11 /**
12  * Statische Daten und Methoden von GenDocument
13  * @author $Author: alex $
14  * @version $Revision: 1.6 $
15  */

16 public class GenDocumentStatics implements TemplateTypes
17 {
18
19     /**
20         Verweis zurück auf den aktuellen statischen Kontext des laufenden Threads
21     */

22     private GeneratorContext context;
23
24     /** Hash mit schon generierten Dokumenten */
25     private TKHashtable genDocumentHash = new TKHashtable();
26     private TKHashtable expandedGenDocs = new TKHashtable();
27
28     private static boolean initialized = false;
29     static protected final String JavaDoc PAT_PRE_TAG = "TKK[_:]";
30     public static Pattern patPostCompileTKTag;
31
32
33     public GenDocumentStatics (GeneratorContext context)
34     {
35         this.context = context != null ? context : GeneratorContext.setup ();
36         /** alex raus -> sollte keine Nebenwirkungen haben
37         this.genDocumentHash = null;
38         this.expandedGenDocs = null;*/

39     }
40     
41     public void putExpandedGenDoc(String JavaDoc path, Object JavaDoc value)
42     {
43         expandedGenDocs.put(path, value);
44     }
45     
46     /**
47         leider konnte ich hier kein Boolean zureuckgeben, da im Preview auch Strings
48         reingeschrieben werden !
49     */

50     public Object JavaDoc getDocumentExpanded(String JavaDoc path)
51     {
52         return expandedGenDocs.get(path);
53     }
54     
55     public void putGeneratedDocument(String JavaDoc id, GenDocument value)
56     {
57         genDocumentHash.put(id, value);
58     }
59     
60     /**
61         Standard Setter
62     */

63     public GenDocument getGeneratedDocument(String JavaDoc id)
64     {
65         return (GenDocument)genDocumentHash.get(id);
66     }
67     
68     public final void fillReferenceIntoTemplate(
69         TemplateBasic t,
70         DOMTemplateData domData,
71         String JavaDoc url,
72         GenNode destNode,
73         GenNode srcNode,
74         GenDocument destDoc,
75         String JavaDoc integrationName,
76         SiteReference ref,
77         String JavaDoc tmplBase,
78         String JavaDoc ownUrl,
79         String JavaDoc rootDir,
80         boolean isPreview
81     )
82     {
83         if (t.getType().equals(JSP_TEMPLATE))
84         {
85             Element el = null;
86             el = domData.getReferenceElement(integrationName);
87             el.setAttribute("REF", url);
88             if (destNode != null)
89             {
90                 el.setAttribute("REF_NODE_PATH", destNode.getPath() );
91                 el.setAttribute("REF_NODE", destNode.getNodeName() );
92                 el.setAttribute("REF_DESCRIPTION", destNode.getDescription() );
93             }
94             int sepIdx = url.lastIndexOf( '/' );
95             el.setAttribute( "REF_PATH", ( sepIdx > 0 ? url.substring( 0, sepIdx ) : "." ) );
96             if (sepIdx > 0) el.setAttribute( "REF_DOC", url.substring( sepIdx+1 ) );
97             if( destDoc != null )
98             {
99                 /*
100                     nicht zu handlen in DOM zur Zeit - alex
101                 t.set (integrationName+".REF_INCLUDE",
102                     new GenDocumentHandle
103                         (context,isPreview,false,ownUrl,destNode,srcNode,
104                         ref.destShortName,tmplBase,rootDir));
105
106                 t.set (integrationName+".REF_DISPLACE",
107                     new GenDocumentHandle
108                         (context,isPreview,true,ownUrl,destNode,srcNode,
109                         ref.destShortName,tmplBase,rootDir));
110                 */

111                 if( ref.getComponentType() == SiteReference.COMPONENT_TYPE_FREE )
112                     destDoc.generateDOMContents( el, domData, true );
113
114                 else destDoc.generateDOMContents( el, domData, false );
115             }
116         }
117         else
118         {
119             t.set( integrationName+".REF", url );
120             if (destNode != null)
121             {
122                 t.set( integrationName+".REF_NODE_PATH", destNode.getPath() );
123                 t.set( integrationName+".REF_NODE", destNode.getNodeName() );
124                 t.set( integrationName+".REF_DESCRIPTION", destNode.getDescription() );
125             }
126             int sepIdx = url.lastIndexOf( '/' );
127             t.set( integrationName+".REF_PATH", ( sepIdx > 0 ? url.substring( 0, sepIdx ) : "." ) );
128             if (sepIdx > 0) t.set( integrationName+".REF_DOC", url.substring( sepIdx+1 ) );
129         
130             if( destDoc != null )
131             {
132                 t.set (integrationName+".REF_INCLUDE",
133                     new GenDocumentHandle
134                         (context,isPreview,false,ownUrl,destNode,srcNode,
135                         ref.getDestinationShortName(),tmplBase,rootDir));
136
137                 t.set (integrationName+".REF_DISPLACE",
138                     new GenDocumentHandle
139                         (context,isPreview,true,ownUrl,destNode,srcNode,
140                         ref.getDestinationShortName(),tmplBase,rootDir));
141                 
142                 if( ref.getComponentType() == SiteReference.COMPONENT_TYPE_FREE )
143                     destDoc.generateContents( t, integrationName+".", true );
144                 else
145                     destDoc.generateContents( t, integrationName+".", false );
146             }
147         }
148     }
149
150     static void initStatic() {
151
152         if( initialized ) return;
153         PatternCompiler compiler = TKReg.getCompiler();
154         try
155         {
156             patPostCompileTKTag =
157                 compiler.compile("</?"+PAT_PRE_TAG, Perl5Compiler.CASE_INSENSITIVE_MASK);
158
159         } catch(MalformedPatternException e)
160         {
161             patPostCompileTKTag = null;
162         }
163         initialized = true;
164     }
165
166     static {
167         initStatic();
168     }
169 }
Popular Tags