01: package de.webman.generator;
02:
03: import com.teamkonzept.web.*;
04: import com.teamkonzept.lib.*;
05:
06: /**
07: * @author $Author: alex $
08: * @version $Revision: 1.7 $
09: */
10: public class GenContentIterator implements TKListIterator {
11:
12: /**
13: * Verweis zurück auf den aktuellen statischen Kontext des laufenden Threads
14: */
15: private GeneratorContext context;
16:
17: private TKVector entries;
18: private int entryCount;
19:
20: /**
21: * the scope in the template when the iterator is created
22: */
23: private String listName;
24: private TKListIterator oldIterator;
25: private boolean onlyStructureContents;
26: private boolean fromReference;
27:
28: /** wird nur Name generiert, oder auch der Inhalt ? */
29: private boolean onlyName;
30:
31: public GenContentIterator(GeneratorContext context,
32: TKVector entries, String listName,
33: TKListIterator oldIterator, boolean onlyStructureContents,
34: boolean _fromReference, boolean _onlyName) {
35: this .context = context != null ? context : GeneratorContext
36: .setup();
37:
38: this .entries = entries;
39: this .listName = listName;
40: this .oldIterator = oldIterator;
41: this .entryCount = entries.size();
42: this .onlyStructureContents = onlyStructureContents;
43: fromReference = _fromReference;
44: onlyName = _onlyName;
45: }
46:
47: /**
48: * generiere den Content für einen spezifischen Listeneintrag aus dem
49: * Iterator. (wende die jeweilige apply methode an)
50: * @param t das aktuelle template objekt
51: * @param i die listen position, die generiert werden soll
52: * @param currListName der aktuelle scope. Nur wenn der aktuelle Scope
53: * mit dem scope übereinstimmt, indem der Empfänger instanziiert wurde,
54: * werden die contents auch tatsächlich generiert.
55: * @return konnten die contents generiert werden? (?) */
56: public boolean apply(TKTemplate t, int i, String currListName) {
57: if (currListName.equalsIgnoreCase(listName)) {
58: if (i >= entryCount)
59: return false;
60: SiteContent content = ((SiteContent) entries.get(i));
61:
62: if (content != null)
63: content.fillNameIntoTemplate((TKHTMLTemplate) t,
64: listName);
65: // if (!fromReference)
66: // context.clearCycle();
67: // if (fromReference)
68: context.push();
69:
70: if (!ReferenceCycleDetector.isCycle(new Integer(content
71: .getInstanceId()))
72: && !onlyName) {
73: if ((content != null)
74: && (!onlyStructureContents || content
75: .isStructureContent())) {
76: t.set("SCOPE", currListName);
77: t.set(currListName + ".IDX", String.valueOf(i + 1));
78: if (i % 2 == 1)
79: t.set(currListName + ".ODD", Boolean.TRUE);
80: content.fillIntoTemplate((TKHTMLTemplate) t,
81: listName);
82: }
83: }
84:
85: //if (fromReference)
86: context.pop();
87:
88: return true;
89: } else if (oldIterator != null) {
90: return oldIterator.apply(t, i, currListName);
91: }
92: return false;
93: }
94: }
|