001: package de.webman.generator;
002:
003: import com.teamkonzept.lib.*;
004: import java.io.*;
005: import java.util.LinkedList;
006:
007: import org.apache.log4j.Category;
008:
009: /**
010:
011: Diese Klasse haelt alle Status Informationen
012: eines Previews, damit mehrere Previews threadsicher
013: ablaufen koennen
014: * @author $Author: alex $
015: * @version $Revision: 1.6 $
016: */
017: public class GeneratorContext {
018:
019: /** Logging Category */
020: private static Category cat = Category
021: .getInstance(GeneratorContext.class);
022:
023: /**
024: * cache für bereits geladene content forms
025: **/
026: public ContentFormStatics contentForms;
027:
028: public SiteContentStatics siteContents;
029: public SiteContentIntegrationStatics integrations;
030: public ContentCallStatics contentCalls;
031: public SiteContentNodeStatics contentNodes;
032: public ReferenceTypeStatics referenceTypes;
033: public SiteNodeStatics siteNodes;
034: public GenNodeStatics genNodes;
035: public GenDocumentStatics genDocuments;
036: public SiteReferenceStatics siteReferences;
037:
038: /**
039: * zum Auffinden von Zyklen bei referenzen. cycleLookup is used as a
040: * stack (contains TKHashtable denoting the current scope)
041: */
042: private LinkedList cycleLookup = new LinkedList();
043:
044: private static TKHashtable lookup = null;
045:
046: private static boolean share = false;
047: private static boolean sharingSetup = false;
048: private static Thread initialThread = Thread.currentThread();
049:
050: /** aktuell generiertes Dokument */
051: private static GenDocument currentDocument;
052:
053: /** wird inkrementell generiert ? */
054: private static boolean isIncremental = false;
055:
056: /** wird der Workflow beachtet ? */
057: private boolean ignoreWorkflow = false;
058:
059: /**
060: Indicates, if the site tree generation is used for the generator (default)
061: or preview. In the latter case, all content is generated, else only
062: the content which status is marked 'generate' in the database
063: VERSION_STATUS attributes. From now on only important for the references,
064: Workflow is managed by ignoreWorkflow
065: */
066: private static boolean isPreviewMode;
067:
068: public GeneratorContext() {
069: contentForms = new ContentFormStatics(this );
070: siteContents = new SiteContentStatics(this );
071: integrations = new SiteContentIntegrationStatics(this );
072: contentCalls = new ContentCallStatics(this );
073: contentNodes = new SiteContentNodeStatics(this );
074: referenceTypes = new ReferenceTypeStatics(this );
075: siteNodes = new SiteNodeStatics(this );
076: genNodes = new GenNodeStatics(this );
077: genDocuments = new GenDocumentStatics(this );
078: siteReferences = new SiteReferenceStatics(this );
079: }
080:
081: /**
082: * @return ob der der Generator im Preview Modus betrieben wird
083: */
084: public static boolean isPreviewMode() {
085: return isPreviewMode;
086: }
087:
088: public static void setPreviewMode(boolean mode) {
089: isPreviewMode = mode;
090: }
091:
092: public boolean isWorkflowIgnored() {
093: return ignoreWorkflow;
094: }
095:
096: public void setWorkflowIgnored(boolean ignore) {
097: ignoreWorkflow = ignore;
098: }
099:
100: public static boolean isShared() {
101: return share;
102: }
103:
104: public static synchronized GeneratorContext setup(Thread myThread) {
105: if (share)
106: myThread = initialThread;
107:
108: if (myThread == null)
109: myThread = Thread.currentThread();
110: if (lookup == null)
111: lookup = new TKHashtable();
112:
113: GeneratorContext statics = (GeneratorContext) lookup
114: .get(myThread);
115: if (statics != null)
116: return statics;
117:
118: statics = new GeneratorContext();
119: lookup.put(myThread, statics);
120:
121: return statics;
122: }
123:
124: public static GeneratorContext setup() {
125: return setup(Thread.currentThread());
126: }
127:
128: static {
129: setupSharing();
130: }
131:
132: public synchronized static void setupSharing() {
133: if (sharingSetup)
134: return;
135: try {
136: PropertyManager man = PropertyManager
137: .getPropertyManager("GENERATION");
138: String preview = man.getValue("PREVIEW_SHARE", "");
139: share = preview.equalsIgnoreCase("TRUE");
140: sharingSetup = true;
141: } catch (Exception e) {
142: cat.info("No Preview Property Set");
143: }
144: }
145:
146: public static void cleanup() {
147: cleanup(Thread.currentThread());
148: }
149:
150: public static void cleanup(Thread myThread) {
151: if (share)
152: return;
153: if (myThread == null)
154: myThread = Thread.currentThread();
155: if (lookup != null)
156: lookup.remove(myThread);
157: }
158:
159: public Object getCycle(Integer instanceID) {
160: if (cycleLookup.size() != 0) {
161: int sm = cycleLookup.size();
162: for (int sc = 0; sc < sm; sc++) {
163: TKHashtable clt = (TKHashtable) cycleLookup.get(sc);
164: Object o = clt.get(instanceID);
165:
166: if (o != null)
167: return o;
168: }
169: }
170: return null;
171: }
172:
173: public void setCycle(Integer instanceID) {
174: TKHashtable clt = currentCycleScope();
175: clt.put(instanceID, "1");
176: }
177:
178: public void clearCycle() {
179: cat.debug("Cycle cleared");
180: cycleLookup.clear();
181: }
182:
183: /**
184: * Referenz wird weiter verschachtelt
185: */
186: public void push() {
187: pushCycleScope();
188: }
189:
190: /**
191: * Referenz ist beendet
192: */
193: public void pop() {
194: popCycleScope();
195: }
196:
197: /* ----------------------------------------------------------------------
198: functions for the cycle detection stack
199: ---------------------------------------------------------------------- */
200: private TKHashtable currentCycleScope() {
201: TKHashtable clt = null;
202:
203: if (cycleLookup.size() == 0) {
204: // lazy initialization
205: clt = new TKHashtable();
206: cycleLookup.addFirst(clt);
207: } else
208: clt = (TKHashtable) cycleLookup.getFirst();
209:
210: return clt;
211: }
212:
213: private void pushCycleScope() {
214: TKHashtable clt = new TKHashtable();
215: cycleLookup.addFirst(clt);
216: }
217:
218: private void popCycleScope() {
219: if (cycleLookup.size() > 0)
220: cycleLookup.removeFirst();
221: }
222:
223: /**
224: * getter fuer isIncremental
225: * @return ob inkrementell generiert wird
226: */
227: public static boolean isIncremental() {
228: return isIncremental;
229: }
230:
231: /**
232: * Setzen der inkr. Generierung
233: * @param incremental boolscher Wert fuer inkr. Generierung
234: */
235: public static void setIncremental(boolean incremental) {
236: isIncremental = incremental;
237: }
238:
239: /**
240: * @return das aktuell generierte Dokument, null falls nicht vorhanden
241: */
242: public static GenDocument getCurrentDocument() {
243: return currentDocument;
244: }
245:
246: /**
247: * @param document das aktuell generierte Dokument
248: */
249: public static void setCurrentDocument(GenDocument document) {
250: currentDocument = document;
251: }
252: }
|