Source Code Cross Referenced for GenDocument.java in  » Content-Management-System » webman » de » webman » generator » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » webman » de.webman.generator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package de.webman.generator;
0002:
0003:        import com.teamkonzept.lib.*;
0004:        import org.apache.log4j.Category;
0005:        import de.webman.template.jsp.*;
0006:        import de.webman.util.log4j.WebmanCategory;
0007:        import com.teamkonzept.web.*;
0008:        import com.teamkonzept.web.templates.*;
0009:        import com.teamkonzept.webman.*; // import com.sitraka.jprobe.profiler.api.*;
0010:        import java.io.*;
0011:        import java.util.*;
0012:        import java.text.DateFormat;
0013:        import org.w3c.dom.*;
0014:        import de.webman.util.legacy.Legacy;
0015:
0016:        /**
0017:         *	repraesentiert ein zu generierendes Dokument
0018:         * @author  $Author: alex $
0019:         * @version $Revision: 1.30 $
0020:         */
0021:        public class GenDocument implements  TKSortable,
0022:                com.teamkonzept.lib.templates.TemplateTypes {
0023:
0024:            /**
0025:            	Verweis zurück auf den aktuellen statischen Kontext des laufenden Threads
0026:             */
0027:            private GeneratorContext context;
0028:
0029:            /** Logging Category */
0030:            private static WebmanCategory cat = (WebmanCategory) WebmanCategory
0031:                    .getInstance(GenDocument.class.getName());
0032:
0033:            // JPHeapAPI heapAPI = null;
0034:            /** Knoten an dem das Dokument hängt */
0035:            private GenNode anchor;
0036:
0037:            /** Name des Dokuments */
0038:            private String docName;
0039:
0040:            /** Template fuer Dokument */
0041:            private String templateName;
0042:
0043:            /** URL des Dokuments, falls es ein externes Dokument ist */
0044:            private String externUrl;
0045:
0046:            /** Hashtable von Integrationsnamen der Inhalte (SiteContent) */
0047:            private TKHashtable contents;
0048:
0049:            /** Hashtable von Integrationsnamen der Referenzen (SiteReferences) */
0050:            private TKHashtable references;
0051:
0052:            /** Hashtable von Vektoren von Referenz-URL */
0053:            private TKHashtable realRefUrls;
0054:
0055:            /** Hashtable von Vektoren von Referenz-Dokumenten (GenDocument) */
0056:            private TKHashtable realRefDocs;
0057:
0058:            /** Hashtable von Vectoren von Referenz-Zielknoten (GenNode) */
0059:            private TKHashtable realRefNodes;
0060:
0061:            /** schon registriert ? */
0062:            private boolean registered = false;
0063:
0064:            public GenDocument(GeneratorContext context, GenNode anchor,
0065:                    String shortName, String templateName, String externUrl,
0066:                    TKHashtable contents, TKHashtable references) {
0067:                this .context = context != null ? context : GeneratorContext
0068:                        .setup();
0069:
0070:                this .anchor = anchor;
0071:                this .docName = shortName;
0072:                this .templateName = templateName;
0073:
0074:                this .externUrl = externUrl;
0075:                this .contents = contents;
0076:                this .references = references;
0077:                // heapAPI = JPHeapAPI.getInstance();
0078:
0079:                this .realRefUrls = null;
0080:                this .realRefDocs = null;
0081:                this .realRefNodes = null;
0082:            }
0083:
0084:            /**
0085:             *  gibt den Namen des Dokuments zurueck
0086:             * @return den Namen
0087:             */
0088:            public String getDocumentName() {
0089:                return docName;
0090:            }
0091:
0092:            /**
0093:             * @return Name des zugewiesenen Templates
0094:             */
0095:            public String getTemplateName() {
0096:                return templateName;
0097:            }
0098:
0099:            /**
0100:             * @return die externe URL
0101:             */
0102:            public String getExternURL() {
0103:                return externUrl;
0104:            }
0105:
0106:            /**
0107:             * @return den GenNode, an dem dieses Dokument haengt
0108:             */
0109:            public GenNode getAnchor() {
0110:                return anchor;
0111:            }
0112:
0113:            /**
0114:             * ...
0115:             @return ...
0116:             **/
0117:            public TKHashtable getContents() {
0118:                return contents;
0119:            }
0120:
0121:            public TKHashtable getReferences() {
0122:                return references;
0123:            }
0124:
0125:            public int cmp(TKSortable otherObject) {
0126:                // Gruppen auf Gruppen wird hier abgefangen, es wird einfach nicht sortiert !
0127:                if (!(otherObject instanceof  GenDocument)) {
0128:                    return 0;
0129:                }
0130:                GenDocument other = (GenDocument) otherObject;
0131:
0132:                SiteContent myDataCont = (SiteContent) contents.get("DATA");
0133:                SiteContent otherDataCont = (SiteContent) other.contents
0134:                        .get("DATA");
0135:
0136:                if (myDataCont == null) {
0137:                    return (otherDataCont == null ? 0 : 1);
0138:                } else if (otherDataCont == null) {
0139:                    return -1;
0140:                }
0141:                return myDataCont.cmp(otherDataCont);
0142:            }
0143:
0144:            public void registerContents(boolean onlyStructureContents) {
0145:                registered = true;
0146:
0147:                Enumeration e = contents.elements();
0148:                while (e.hasMoreElements()) {
0149:                    Object cont = e.nextElement();
0150:                    if (cont instanceof  TKVector) {
0151:                        Enumeration f = ((TKVector) cont).elements();
0152:                        while (f.hasMoreElements())
0153:                            ((SiteContent) f.nextElement()).registerDoc(this ,
0154:                                    onlyStructureContents);
0155:                    } else {
0156:                        ((SiteContent) cont).registerDoc(this ,
0157:                                onlyStructureContents);
0158:                    }
0159:                }
0160:            }
0161:
0162:            /**
0163:             * used by generator (registerReferences)
0164:             * generiert Referenzen fuer Generator ??
0165:             * @param refUrls referencing urls (?)
0166:             * @param refDocs referenced document (?)
0167:             * @param refNodes referenced nodes (?)
0168:             * @param destNode destination node (?)
0169:             * @param ref the site reference (?)
0170:             */
0171:            public void addRealReference(TKVector refUrls, TKVector refDocs,
0172:                    TKVector refNodes, GenNode destNode, SiteReference ref) {
0173:                int insertPos = -1;
0174:                cat.debug("add Reference " + destNode.getPath());
0175:                if (ref.getDestinationContentSource() != null) {
0176:                    GenDocument destCont = destNode.getDocument(ref
0177:                            .getDestinationContentSource());
0178:
0179:                    // cat.debug( " with value of doc "+destCont.anchor.getPath()+destCont.docName );
0180:
0181:                    if (destCont == null) {
0182:                        throw new Error(
0183:                                "could not find content-source-document '"
0184:                                        + ref.getDestinationContentSource()
0185:                                        + "' for " + ref.path() + " in node "
0186:                                        + destNode.getPath());
0187:
0188:                    }
0189:
0190:                    if (ref.getComponentType() == SiteReference.COMPONENT_TYPE_FREE) {
0191:                        refDocs.addElement(destCont);
0192:                        insertPos = -1;
0193:                    } else {
0194:                        insertPos = 0;
0195:                        int docListSize = refDocs.size();
0196:                        boolean done = false;
0197:                        while (insertPos < docListSize && !done) {
0198:                            GenDocument currDoc = (GenDocument) refDocs
0199:                                    .get(insertPos);
0200:                            if (destCont.cmp(currDoc) < 0) {
0201:                                refDocs.insertElementAt(destCont, insertPos);
0202:                                done = true;
0203:                            } else {
0204:                                insertPos++;
0205:                            }
0206:                        }
0207:                        if (!done) {
0208:                            refDocs.addElement(destCont);
0209:                            insertPos = -1;
0210:                        }
0211:                    }
0212:                }
0213:
0214:                GenDocument destRef = destNode.getDocument(ref
0215:                        .getDestinationShortName());
0216:
0217:                // singh + 1999.03.11
0218:                if (insertPos == -1) {
0219:                    refUrls
0220:                            .addElement((destRef.externUrl != null ? destRef.externUrl
0221:                                    : anchor.makePathRelativeTo(destNode)
0222:                                            + ref.getDestinationShortName()));
0223:                    refNodes.addElement(destNode);
0224:                } else {
0225:                    refUrls.insertElementAt(
0226:                            (destRef.externUrl != null ? destRef.externUrl
0227:                                    : anchor.makePathRelativeTo(destNode)
0228:                                            + ref.getDestinationShortName()),
0229:                            insertPos);
0230:                    refNodes.insertElementAt(destNode, insertPos);
0231:                }
0232:                // singh - 1999.03.11
0233:            }
0234:
0235:            /**
0236:            	used by preview (makeReferences)
0237:            	generiert Referenzen fuer Preview ??
0238:            	@param ownUrl
0239:            	@param refUrls
0240:            	@param refDocs
0241:            	@param refNodes
0242:            	@param destNode
0243:            	@param ref
0244:            	@param primContent
0245:             */
0246:            public void addRealReference(String ownUrl, TKVector refUrls,
0247:                    TKVector refDocs, TKVector refNodes, SiteNode destNode,
0248:                    SiteReference ref, SiteContent primContent) {
0249:                int primaryId = primContent != null ? primContent
0250:                        .getInstanceId() : -1;
0251:
0252:                GenNode gn = destNode.makeGenNode(primContent);
0253:                cat.debug("registerReal : " + gn);
0254:                if (gn == null) {
0255:                    cat.warn("could not make genNode from siteNode for "
0256:                            + ref.path() + " in node " + destNode.path());
0257:                }
0258:
0259:                int insertPos = -1;
0260:                if (ref.getDestinationContentSource() != null) {
0261:
0262:                    SiteDocument sd = destNode.getDocument(ref
0263:                            .getDestinationContentSource());
0264:                    if (sd == null) {
0265:                        cat.warn("could not find referenced document '"
0266:                                + ref.getDestinationShortName() + "' for "
0267:                                + ref.getPath() + " in node "
0268:                                + destNode.getPath());
0269:                    }
0270:
0271:                    if (context.siteNodes.isReducedBuild())
0272:                        sd.complete();
0273:
0274:                    GenDocument destCont = sd != null ? sd.getGenDocument(
0275:                            primContent, gn) : null;
0276:
0277:                    if (destCont == null) {
0278:                        cat.warn("could not find gen content-source-document '"
0279:                                + ref.getDestinationContentSource() + "' for "
0280:                                + ref.getPath() + " in node "
0281:                                + destNode.getPath());
0282:                        return;
0283:                    }
0284:
0285:                    if (ref.getComponentType() == SiteReference.COMPONENT_TYPE_FREE) {
0286:                        refDocs.addElement(destCont);
0287:                        insertPos = -1;
0288:                    } else {
0289:                        insertPos = 0;
0290:                        int docListSize = refDocs.size();
0291:                        boolean done = false;
0292:                        while (insertPos < docListSize && !done) {
0293:                            GenDocument currDoc = (GenDocument) refDocs
0294:                                    .get(insertPos);
0295:                            cat.debug("cmp " + destCont.anchor.getPath()
0296:                                    + destCont.docName + " with "
0297:                                    + currDoc.anchor.getPath()
0298:                                    + currDoc.docName);
0299:                            if (destCont.cmp(currDoc) <= 0) {
0300:                                refDocs.insertElementAt(destCont, insertPos);
0301:                                done = true;
0302:                            } else {
0303:                                insertPos++;
0304:                            }
0305:                        }
0306:
0307:                        if (!done) {
0308:                            refDocs.addElement(destCont);
0309:                            insertPos = -1;
0310:                        }
0311:                    }
0312:                }
0313:
0314:                SiteDocument destRef = destNode.getDocument(ref
0315:                        .getDestinationShortName());
0316:                if (destRef == null) {
0317:                    cat.warn("destRef ist null !");
0318:                    throw new Error("could not find referenced document '"
0319:                            + ref.getDestinationShortName() + "' for "
0320:                            + ref.getPath() + " in node " + destNode.getPath());
0321:                }
0322:
0323:                // destRef.complete() hier nicht noetig ???
0324:
0325:                String docId = "null";
0326:                if (destRef.getURL() == null) {
0327:
0328:                    TKConverter urlConv = TKConverter.getConverter("URL");
0329:                    docId = new String(urlConv.stringToBytes(destRef
0330:                            .getShortName()), 0);
0331:                }
0332:
0333:                if (insertPos == -1) {
0334:
0335:                    refUrls.addElement((destRef.getURL() != null ? destRef
0336:                            .getURL() : ownUrl + "?TK_EV[CE_PREVIEW]=1"
0337:                            + "&TK_PAR[SNODE]=" + destNode.getId()
0338:                            + "&TK_PAR[PID]=" + primaryId + "&TK_PAR[DOCNAME]="
0339:                            + docId + "&TK_PAR[CHECKER]=1"));
0340:                    refNodes.addElement(gn);
0341:                } else {
0342:                    refUrls.insertElementAt((destRef.getURL() != null ? destRef
0343:                            .getURL() : ownUrl + "?TK_EV[CE_PREVIEW]=1"
0344:                            + "&TK_PAR[SNODE]=" + destNode.getId()
0345:                            + "&TK_PAR[PID]=" + primaryId + "&TK_PAR[DOCNAME]="
0346:                            + docId + "&TK_PAR[CHECKER]=1"), insertPos);
0347:                    refNodes.insertElementAt(gn, insertPos);
0348:                }
0349:            }
0350:
0351:            /**
0352:            	used by generator
0353:             */
0354:            public void registerReferences() {
0355:                try {
0356:                    registered = true;
0357:
0358:                    int size = references.size();
0359:                    if (size == 0)
0360:                        return;
0361:
0362:                    TKVector refsToDelete = new TKVector();
0363:
0364:                    realRefUrls = new TKHashtable(size);
0365:                    realRefDocs = new TKHashtable(size);
0366:                    realRefNodes = new TKHashtable(size);
0367:                    //%%ANDI: hier muss noch die zweite Stufe der Ref-Selection-Klasse eingebaut werden
0368:                    Enumeration e = references.keys();
0369:                    while (e.hasMoreElements()) {
0370:                        String intName = (String) e.nextElement();
0371:                        cat.debug("register : " + intName);
0372:                        SiteReference ref = (SiteReference) references
0373:                                .get(intName);
0374:                        TKVector currUrls = new TKVector();
0375:                        realRefUrls.put(intName, currUrls);
0376:                        TKVector currDocs = null;
0377:                        if (ref.getDestinationContentSource() != null) {
0378:                            currDocs = new TKVector();
0379:                            realRefDocs.put(intName, currDocs);
0380:                        }
0381:
0382:                        TKVector currNodes = new TKVector();
0383:                        realRefNodes.put(intName, currNodes);
0384:
0385:                        // Hier muß darauf geachtet werden, daß Referenzen auf das eigene Dokument, z.B. bei
0386:                        // Framesets, erhalten bleiben. Dies ist möglicherweise dann der Fall, wenn es sich
0387:                        // um einen INTEGRATION_TYPE_SINGLE handelt und keine Selektionsklasse angegeben ist.
0388:                        // In diesem Fall wird der refNode über den anchor des genDocuments ermittelt und
0389:                        // nicht über die (Ziel-) siteNodes der Referenz ... (singh)
0390:
0391:                        if ((ref.getIntegrationType() == SiteReference.INTEGRATION_TYPE_SINGLE)
0392:                                && (ref.getSelectionType() == null)) {
0393:                            if (ref.getDestinationDocuments().length == 0) {
0394:                                // Single Referenz nicht gefunden - Fehlermeldung und weiter !
0395:                                cat
0396:                                        .error("No destination for reference component: "
0397:                                                + intName
0398:                                                + " in document: "
0399:                                                + anchor.getPath()
0400:                                                + getDocumentName()
0401:                                                + " found !");
0402:                                continue;
0403:                            }
0404:                            SiteNode refAnchor = (SiteNode) ref
0405:                                    .getDestinationDocuments()[0].getAnchor();
0406:                            GenNode refNode = (refAnchor == anchor
0407:                                    .getSiteNode()) ? anchor
0408:                                    : (GenNode) refAnchor.getGenNodes().get(0);
0409:                            addRealReference(currUrls, currDocs, currNodes,
0410:                                    refNode, ref);
0411:                        } else {
0412:                            TKVector allNodes = new TKVector();
0413:                            for (int i = 0; i < ref.getDestinationDocuments().length; i++) {
0414:                                allNodes
0415:                                        .concat(ref.getDestinationDocuments()[i]
0416:                                                .getAnchor().getGenNodes());
0417:                            }
0418:                            Enumeration f = allNodes.elements();
0419:                            while (f.hasMoreElements()) {
0420:                                GenNode node3 = (GenNode) f.nextElement();
0421:                                addRealReference(currUrls, currDocs, currNodes,
0422:                                        node3, ref);
0423:                            }
0424:
0425:                            if (ref.getSelectionType() != null)
0426:                                TKWMReferenceSelectorReg.reduceReferences(ref
0427:                                        .getSelectionType(), ref
0428:                                        .getSelectionData(), currUrls,
0429:                                        currDocs, currNodes, this .anchor);
0430:                            if (ref.getIntegrationType() == SiteReference.INTEGRATION_TYPE_SINGLE) {
0431:                                int remainSize = currUrls.size();
0432:                                if (remainSize == 0)
0433:                                    refsToDelete.addElement(intName);
0434:                                else {
0435:                                    for (int i = remainSize - 1; i > 0; i--) {
0436:                                        currUrls.removeElementAt(i);
0437:                                        if (currDocs != null)
0438:                                            currDocs.removeElementAt(i);
0439:                                        currNodes.removeElementAt(i);
0440:                                    }
0441:                                }
0442:                            }
0443:                        }
0444:                    }
0445:                    e = refsToDelete.elements();
0446:                    while (e.hasMoreElements()) {
0447:                        references.remove(e.nextElement());
0448:                    }
0449:                    ;
0450:
0451:                    e = references.keys();
0452:                    while (e.hasMoreElements()) {
0453:                        String intName = (String) e.nextElement();
0454:                        SiteReference ref = (SiteReference) references
0455:                                .get(intName);
0456:                        Enumeration f = ((TKVector) realRefDocs.get(intName))
0457:                                .elements();
0458:                        while (f.hasMoreElements()) {
0459:                            ((GenDocument) f.nextElement())
0460:                                    .registerContents(ref.getComponentType() == SiteReference.COMPONENT_TYPE_FREE);
0461:                        }
0462:                    }
0463:                } catch (Throwable t) {
0464:                    t.printStackTrace(System.out);
0465:                    cat.error("Unknown in registerReferences" + t.getMessage(),
0466:                            t);
0467:                }
0468:
0469:            }
0470:
0471:            /**
0472:            	used by preview
0473:            	@param ownUrl URL des WebmanServlets
0474:            	@param primContent primaerer Content fuer den der Preview durchgefuehrt werden soll
0475:             */
0476:            public void makeReferences(String ownUrl, SiteContent primContent) {
0477:                int size = references.size();
0478:                if (size == 0)
0479:                    return;
0480:
0481:                TKVector refsToDelete = new TKVector();
0482:
0483:                realRefUrls = new TKHashtable(size);
0484:                realRefDocs = new TKHashtable(size);
0485:                realRefNodes = new TKHashtable(size);
0486:
0487:                Enumeration e = references.keys();
0488:                while (e.hasMoreElements()) {
0489:                    String intName = (String) e.nextElement();
0490:
0491:                    SiteReference ref = (SiteReference) references.get(intName);
0492:                    TKVector currUrls = new TKVector();
0493:                    realRefUrls.put(intName, currUrls);
0494:                    TKVector currDocs = null;
0495:
0496:                    if (ref.getDestinationContentSource() != null) {
0497:
0498:                        currDocs = new TKVector();
0499:                        realRefDocs.put(intName, currDocs);
0500:                    }
0501:
0502:                    TKVector currNodes = new TKVector();
0503:                    realRefNodes.put(intName, currNodes);
0504:
0505:                    // Hier gilt das gleiche wie schon bei registerReferences() bezüglich der
0506:                    // Behandlung von Referenzen auf das eigene Dokument (z.B. Framesets), siehe dort
0507:                    // (singh)
0508:
0509:                    // Im Gegensatz zu registerReferences() gibt es hier keine genNodes, sie werden
0510:                    // jeweils durch die Kombination (siteNode,primaryContents) repräsentiert und bei
0511:                    // Bedarf von einer siteNode-basierten Version von addRealReference() on-demand,
0512:                    // nicht rekursiv erzeugt (singh)
0513:
0514:                    if ((ref.getIntegrationType() == SiteReference.INTEGRATION_TYPE_SINGLE)
0515:                            && (ref.getSelectionType() == null)) {
0516:                        if (ref.getDestinationDocuments().length == 0) {
0517:                            // Single Referenz nicht gefunden - Fehlermeldung und weiter !
0518:                            cat
0519:                                    .error("No destination for reference component: "
0520:                                            + intName + " found !");
0521:                            continue;
0522:                        }
0523:
0524:                        SiteNode refAnchor = (SiteNode) ref
0525:                                .getDestinationDocuments()[0].getAnchor();
0526:
0527:                        if (refAnchor == anchor.getSiteNode()) {
0528:                            addRealReference(ownUrl, currUrls, currDocs,
0529:                                    currNodes, refAnchor, ref, primContent);
0530:
0531:                        } else if (refAnchor.getType() == SiteNode.NODE_TYPE_GROUP) {
0532:
0533:                            TKVector primConts = null;
0534:
0535:                            if (refAnchor.getPrimaryContentSelectionKey() != null)
0536:                                primConts = context.integrations
0537:                                        .getSelection(refAnchor
0538:                                                .getPrimaryContentSelectionKey());
0539:                            else if (refAnchor.getPrimaryContentNode() != null)
0540:                                primConts = refAnchor.getPrimaryContentNode()
0541:                                        .getContents();
0542:
0543:                            if (primConts == null)
0544:                                continue;
0545:
0546:                            Enumeration ee = primConts.elements();
0547:                            if (ee.hasMoreElements()) {
0548:
0549:                                SiteContent sc = (SiteContent) ee.nextElement();
0550:                                if (sc != null)
0551:                                    addRealReference(ownUrl, currUrls,
0552:                                            currDocs, currNodes, refAnchor,
0553:                                            ref, sc);
0554:                            }
0555:                        } else {
0556:                            addRealReference(ownUrl, currUrls, currDocs,
0557:                                    currNodes, refAnchor, ref, null);
0558:                        }
0559:                    } else {
0560:                        for (int i = 0; i < ref.getDestinationDocuments().length; i++) {
0561:                            if (ref.getDestinationDocuments()[i] != null) {
0562:                                SiteNode refAnchor = (SiteNode) ref
0563:                                        .getDestinationDocuments()[i]
0564:                                        .getAnchor();
0565:
0566:                                if (refAnchor.getType() == SiteNode.NODE_TYPE_GROUP) {
0567:
0568:                                    TKVector primConts = null;
0569:
0570:                                    if (refAnchor
0571:                                            .getPrimaryContentSelectionKey() != null)
0572:                                        primConts = context.integrations
0573:                                                .getSelection(refAnchor
0574:                                                        .getPrimaryContentSelectionKey());
0575:                                    else if (refAnchor.getPrimaryContentNode() != null)
0576:                                        primConts = refAnchor
0577:                                                .getPrimaryContentNode()
0578:                                                .getContents();
0579:
0580:                                    if (primConts == null)
0581:                                        continue;
0582:
0583:                                    Enumeration ee = primConts.elements();
0584:                                    while (ee.hasMoreElements()) {
0585:                                        SiteContent sc = (SiteContent) ee
0586:                                                .nextElement();
0587:                                        if (sc != null)
0588:                                            addRealReference(ownUrl, currUrls,
0589:                                                    currDocs, currNodes,
0590:                                                    refAnchor, ref, sc);
0591:                                    }
0592:                                } else {
0593:                                    addRealReference(ownUrl, currUrls,
0594:                                            currDocs, currNodes, refAnchor,
0595:                                            ref, null);
0596:                                }
0597:                            }
0598:                        }
0599:
0600:                        if (ref.getSelectionType() != null)
0601:                            TKWMReferenceSelectorReg.reduceReferences(ref
0602:                                    .getSelectionType(),
0603:                                    ref.getSelectionData(), currUrls, currDocs,
0604:                                    currNodes, this .anchor);
0605:
0606:                        if (ref.getIntegrationType() == SiteReference.INTEGRATION_TYPE_SINGLE) {
0607:                            int remainSize = currUrls.size();
0608:                            if (remainSize == 0)
0609:                                refsToDelete.addElement(intName);
0610:                            else {
0611:                                for (int i = remainSize - 1; i > 0; i--) {
0612:                                    currUrls.removeElementAt(i);
0613:                                    if (currDocs != null)
0614:                                        currDocs.removeElementAt(i);
0615:                                    currNodes.removeElementAt(i);
0616:                                }
0617:                            }
0618:                        }
0619:                    }
0620:                }
0621:
0622:                e = refsToDelete.elements();
0623:                while (e.hasMoreElements()) {
0624:                    references.remove(e.nextElement());
0625:                }
0626:                ;
0627:            }
0628:
0629:            // singh - 1999.04.06
0630:
0631:            public void prepareGeneration() {
0632:                cat.debug("prepare document " + anchor.getPath() + "/"
0633:                        + docName);
0634:                registerContents(false);
0635:                registerReferences();
0636:                cat.debug("document prepared'" + docName);
0637:            }
0638:
0639:            public void deregisterContents(boolean onlyStructureContents) {
0640:                Enumeration e = contents.elements();
0641:                while (e.hasMoreElements()) {
0642:                    Object cont = e.nextElement();
0643:                    if (cont instanceof  TKVector) {
0644:                        Enumeration f = ((TKVector) cont).elements();
0645:                        while (f.hasMoreElements())
0646:                            ((SiteContent) f.nextElement()).deregisterDoc(this ,
0647:                                    onlyStructureContents);
0648:                    } else {
0649:                        ((SiteContent) cont).deregisterDoc(this ,
0650:                                onlyStructureContents);
0651:                    }
0652:                }
0653:            }
0654:
0655:            public void deregisterReferences() {
0656:                Enumeration e = references.keys();
0657:                while (e.hasMoreElements()) {
0658:                    String intName = (String) e.nextElement();
0659:                    SiteReference ref = (SiteReference) references.get(intName);
0660:
0661:                    Enumeration f = ((TKVector) realRefDocs.get(intName))
0662:                            .elements();
0663:                    while (f.hasMoreElements()) {
0664:                        ((GenDocument) f.nextElement())
0665:                                .deregisterContents(ref.getComponentType() == SiteReference.COMPONENT_TYPE_FREE);
0666:                    }
0667:                }
0668:            }
0669:
0670:            public void cleanupGeneration() {
0671:                if (!registered)
0672:                    return;
0673:
0674:                deregisterContents(false);
0675:                deregisterReferences();
0676:            }
0677:
0678:            public TKVector sortContents(TKVector contents) {
0679:                TKVector result = contents.sort();
0680:                return result;
0681:            }
0682:
0683:            /**
0684:             * hier für direkten Einsprung aus der Referenzgenerierung
0685:             * @param domAnchor (?)
0686:             * @param domData (?)
0687:             * @param onlyStructureContents (?)
0688:             */
0689:            public void generateDOMContents(Element domAnchor,
0690:                    DOMTemplateData domData, boolean onlyStructureContents) {
0691:                String node = anchor.getPath();
0692:                // ist der DOMAnchor der richtige Ort für diese Attribute ? -alex
0693:                domAnchor.setAttribute("DOCUMENT", node + docName);
0694:                domAnchor.setAttribute("NODE_PATH", node);
0695:                domAnchor.setAttribute("NODE", anchor.getNodeName());
0696:                domAnchor.setAttribute("LEVEL", Integer
0697:                        .toString(anchor.depth() - 1));
0698:                Enumeration e = contents.keys();
0699:                while (e.hasMoreElements()) {
0700:                    String intName = (String) e.nextElement();
0701:                    Object cont = contents.get(intName);
0702:                    boolean isListInt = cont instanceof  TKVector;
0703:
0704:                    SiteContent firstCont = (isListInt ? (SiteContent) ((TKVector) cont)
0705:                            .get(0)
0706:                            : (SiteContent) cont);
0707:                    if (firstCont != null
0708:                            && (firstCont.isStructureContent() || !onlyStructureContents)) {
0709:                        // create only one top element for grouped references; buf request #809 --gck
0710:                        Element currentElement = domData.getContentElement(
0711:                                intName, domAnchor);
0712:
0713:                        if (isListInt) {
0714:                            domAnchor.setAttribute(intName, Integer
0715:                                    .toString(((TKVector) cont).size()));
0716:                            TKVector sortContents = sortContents((TKVector) cont);
0717:
0718:                            for (int i = 0; i < sortContents.size(); i++) {
0719:                                //Element currentElement = domData.getContentElement(intName, domAnchor); // --gck
0720:                                SiteContent content = ((SiteContent) ((TKVector) cont)
0721:                                        .elementAt(i));
0722:                                Element contentElement = domData
0723:                                        .getContentElement("content",
0724:                                                currentElement);
0725:
0726:                                /*
0727:                                if (content != null) // hat das jetzt eine Bedeutung im DOM Fall ? nein ! -alex
0728:                                	content.fillNameIntoTemplate(t, prefix+intName );
0729:                                 */
0730:                                context.push(); // -gck
0731:                                // context.clearCycle();
0732:                                if ((content != null)
0733:                                        && (!onlyStructureContents || content
0734:                                                .isStructureContent())) {
0735:                                    domAnchor.setAttribute(intName + ".IDX",
0736:                                            String.valueOf(i + 1)); // ?
0737:                                    // ??if( i % 2 == 1 ) t.set( currListName+".ODD", Boolean.TRUE );
0738:                                    content.fillBasicDOM(domData.getDocument(),
0739:                                            contentElement);
0740:                                }
0741:                                context.pop(); // -gck
0742:                            }
0743:                        } else {
0744:                            //Element currentElement = domData.getContentElement(intName, domAnchor); // --gck
0745:                            // context.clearCycle();
0746:                            context.push();// -gck
0747:
0748:                            if (firstCont != null) {
0749:                                //firstCont.fillNameIntoTemplate(t, prefix+intName );
0750:                                if (!onlyStructureContents
0751:                                        || firstCont.isStructureContent()) {
0752:                                    String cName = firstCont
0753:                                            .isStructureContent() ? "site"
0754:                                            : firstCont.getShortName();
0755:                                    if (cName != null && cName.length() != 0) {
0756:                                        try {
0757:
0758:                                            Integer.parseInt(cName.substring(0,
0759:                                                    1));
0760:                                            cName = 'A' + cName;
0761:                                        } catch (NumberFormatException nfe) {
0762:                                            cat
0763:                                                    .debug("Content Kennung ist eine Nummer");
0764:                                        }
0765:                                    }
0766:
0767:                                    Element contentElement = domData
0768:                                            .getContentElement("content",
0769:                                                    currentElement);
0770:                                    firstCont.fillBasicDOM(domData
0771:                                            .getDocument(), contentElement);
0772:                                }
0773:                            }
0774:
0775:                            context.pop();
0776:                        }
0777:                    }
0778:                }
0779:            }
0780:
0781:            /**
0782:            	@param t Template
0783:            	hier wird getrennt nach alten Templates und DOM Implementierung
0784:            	Grund ist die unterschiedliche Behandlung der Datenstrukturen
0785:             */
0786:            public void generateContents(TemplateBasic t, String prefix,
0787:                    boolean onlyStructureContents) {
0788:                if (t.getType().equals(JSP_TEMPLATE)) {
0789:                    generateDOMContents(t.getDOMData().getRoot(), t
0790:                            .getDOMData(), onlyStructureContents);
0791:                } else {
0792:                    String node = anchor.getPath();
0793:
0794:                    // das raus hier ?
0795:                    t.set(prefix + "DOCUMENT", node + docName);
0796:                    t.set(prefix + "NODE_PATH", node);
0797:                    t.set(prefix + "NODE", anchor.getNodeName());
0798:                    t.set(prefix + "LEVEL", Integer
0799:                            .toString(anchor.depth() - 1));
0800:
0801:                    Enumeration e = contents.keys();
0802:                    while (e.hasMoreElements()) {
0803:                        String intName = (String) e.nextElement();
0804:                        Object cont = contents.get(intName);
0805:                        boolean isListInt = cont instanceof  TKVector;
0806:                        SiteContent firstCont = (isListInt ? (SiteContent) ((TKVector) cont)
0807:                                .get(0)
0808:                                : (SiteContent) cont);
0809:
0810:                        if (isListInt) {
0811:                            t.set(prefix + intName, Integer
0812:                                    .toString(((TKVector) cont).size()));
0813:                            TKVector sortContents = sortContents((TKVector) cont);
0814:                            TKHTMLTemplate htmlTemplate = (TKHTMLTemplate) t;
0815:                            htmlTemplate
0816:                                    .setListIterator(new GenContentIterator(
0817:                                            context, sortContents, prefix
0818:                                                    + intName, htmlTemplate
0819:                                                    .getListIterator(),
0820:                                            onlyStructureContents, false, false));
0821:                        } else {
0822:                            if (firstCont != null) {
0823:                                //context.clearCycle();
0824:                                context.push();
0825:                                firstCont.fillNameIntoTemplate(t, prefix
0826:                                        + intName);
0827:
0828:                                if (!onlyStructureContents
0829:                                        || firstCont.isStructureContent())
0830:                                    firstCont.fillIntoTemplate(t, prefix
0831:                                            + intName);
0832:                                context.pop();
0833:                            }
0834:                        }
0835:                    }
0836:                }
0837:            }
0838:
0839:            public void generateReferences(TemplateBasic t,
0840:                    DOMTemplateData domData, String tmplBase,
0841:                    boolean isPreview, String ownUrl, String rootDir) {
0842:                Enumeration e = references.keys();
0843:                while (e.hasMoreElements()) {
0844:                    String intName = (String) e.nextElement();
0845:                    SiteReference ref = (SiteReference) references.get(intName);
0846:                    TKVector refUrls = (TKVector) realRefUrls.get(intName);
0847:                    TKVector refDocs = (TKVector) realRefDocs.get(intName);
0848:                    TKVector refNodes = (TKVector) realRefNodes.get(intName);
0849:
0850:                    if (ref.getIntegrationType() == SiteReference.INTEGRATION_TYPE_SINGLE) {
0851:                        if (refUrls.size() > 0) {
0852:                            context.genDocuments.fillReferenceIntoTemplate(t,
0853:                                    domData, (String) refUrls.get(0),
0854:                                    (refNodes == null ? null
0855:                                            : (GenNode) refNodes.get(0)),
0856:                                    anchor, (refDocs == null ? null
0857:                                            : (GenDocument) refDocs.get(0)),
0858:                                    intName, ref, tmplBase, ownUrl, rootDir,
0859:                                    isPreview);
0860:                        }
0861:                    } else {
0862:                        if (t.getType().equals(JSP_TEMPLATE)) {
0863:                            for (int i = 0; i < refUrls.size(); i++) {
0864:                                context.genDocuments
0865:                                        .fillReferenceIntoTemplate(t, domData,
0866:                                                (String) refUrls.get(i),
0867:                                                (refNodes == null ? null
0868:                                                        : (GenNode) refNodes
0869:                                                                .get(i)),
0870:                                                anchor, (refDocs == null ? null
0871:                                                        : (GenDocument) refDocs
0872:                                                                .get(i)),
0873:                                                intName, ref, tmplBase, ownUrl,
0874:                                                rootDir, isPreview);
0875:                            }
0876:                        } else {
0877:                            if (refUrls != null) {
0878:                                t
0879:                                        .set(intName, Integer.toString(refUrls
0880:                                                .size()));
0881:                                ((TKHTMLTemplate) t)
0882:                                        .setListIterator(new GenReferenceIterator(
0883:                                                context, anchor, ref, refUrls,
0884:                                                refNodes, refDocs, tmplBase,
0885:                                                intName, ownUrl, rootDir,
0886:                                                isPreview, ((TKHTMLTemplate) t)
0887:                                                        .getListIterator()));
0888:                            }
0889:                        }
0890:                    }
0891:                }
0892:            }
0893:
0894:            public void generateToPrintStream(PrintStream out, String tmplBase,
0895:                    TKHashtable data, boolean isPreview, String ownUrl,
0896:                    String rootDir) throws Exception {
0897:                TemplateBasic t = TemplateUtils.getTemplate(templateName,
0898:                        tmplBase, false);
0899:
0900:                DOMTemplateData domData = t.getDOMData();
0901:                Date timestamp = new Date();
0902:
0903:                t.set("SECONDS", String.valueOf(timestamp.getTime())); // muss das sein ?
0904:                t.set("DATE", DateFormat.getDateInstance(DateFormat.SHORT)
0905:                        .format(timestamp));
0906:                t.set("TIME", DateFormat.getTimeInstance(DateFormat.SHORT)
0907:                        .format(timestamp));
0908:
0909:                if (data != null)
0910:                    t.set(data);
0911:
0912:                synchronized (context) {
0913:                    generateContents(t, "", false);
0914:                    generateReferences(t, domData, tmplBase, isPreview, ownUrl,
0915:                            rootDir);
0916:                }
0917:                if (t.getType() != JSP_TEMPLATE) {
0918:                    if (isPreview)
0919:                        t.set("DISPLACEMENT", "");
0920:                    else
0921:                        t.set("DISPLACEMENT", "<TKK_DISPLACEMENT[ANSI]>");
0922:                }
0923:                t.doTagSubstitution();
0924:                t.printTemplate(out);
0925:
0926:                cleanupGeneration();
0927:            }
0928:
0929:            /**
0930:            Generates the document by creating a file with name
0931:            <code>docName</code> in the directory <code>baseDir</code>.
0932:            @param baseDir the parent directory path of this node
0933:            @param rootDir the path to the document root
0934:            @param tmplBase the absolute path to the template directory
0935:            @param genFileLogStream a logstream to which the generated files are written
0936:             */
0937:            public void generate(File baseDir, String rootDir, String tmplBase,
0938:                    PrintStream genFileLogStream) throws Exception {
0939:                //System.gc();
0940:                // heapAPI.save("MyHeapDumpbefore");
0941:                cat.info(new Date().toString() + ": start doc generation : "
0942:                        + baseDir + " / " + docName, WebmanCategory.ALL);
0943:                // Dokument eintragen
0944:                GeneratorContext.setCurrentDocument(this );
0945:
0946:                /*System.gc();
0947:                cat.debug("Memory available before:" + Runtime.getRuntime().freeMemory());*/
0948:                File outFile = new File(baseDir, docName);
0949:                String path = outFile.getAbsolutePath();
0950:
0951:                Boolean expanded = (Boolean) context.genDocuments
0952:                        .getDocumentExpanded(path);
0953:
0954:                if (expanded != null && expanded.booleanValue()) {
0955:                    if (genFileLogStream != null)
0956:                        genFileLogStream.println(path);
0957:                    return;
0958:                }
0959:
0960:                if (expanded != null && !expanded.booleanValue()) {
0961:                    context.genDocuments.putExpandedGenDoc(path, new Boolean(
0962:                            true));
0963:                    return;
0964:                }
0965:
0966:                context.genDocuments
0967:                        .putExpandedGenDoc(path, new Boolean(false));
0968:
0969:                FileOutputStream f = new FileOutputStream(outFile);
0970:                PrintStream out = null;
0971:                try {
0972:                    out = new PrintStream(f);
0973:
0974:                    generateToPrintStream(out, tmplBase, null, false, null,
0975:                            rootDir);
0976:                } finally {
0977:                    out.close();
0978:                }
0979:
0980:                context.genDocuments.putExpandedGenDoc(path, new Boolean(true));
0981:                if (genFileLogStream != null)
0982:                    genFileLogStream.println(path);
0983:                // wieder da !
0984:
0985:                // System.gc();
0986:                // heapAPI.save("MyHeapDumpAfter");
0987:                /*S
0988:                cat.debug("Memory available after:" + Runtime.getRuntime().freeMemory());
0989:                 */
0990:            }
0991:
0992:            public void generatePreview(PrintStream out, String rootDir,
0993:                    String tmplBase, String ownUrl) throws Exception {
0994:                TKHashtable data = new TKHashtable();
0995:                data.put("PREVIEW", Boolean.TRUE);
0996:
0997:                File sourceDir = new File(rootDir);
0998:                if (anchor.getSiteNode().getParent() != null)
0999:                    sourceDir = new File(sourceDir, anchor.getSubPathDir());
1000:
1001:                File outFile = new File(sourceDir, docName);
1002:                String path = outFile.getAbsolutePath();
1003:
1004:                Object cached = context.genDocuments.getDocumentExpanded(path);
1005:                if (cached != null) {
1006:                    if (cached instanceof  Boolean) {
1007:                        if (!((Boolean) cached).booleanValue()) {
1008:                            context.genDocuments.putExpandedGenDoc(path,
1009:                                    new Boolean(true));
1010:                        }
1011:                    } else
1012:                        out.print((String) cached);
1013:
1014:                } else {
1015:                    context.genDocuments.putExpandedGenDoc(path, new Boolean(
1016:                            false));
1017:                    generateToPrintStream(out, tmplBase, data, true, ownUrl,
1018:                            rootDir);
1019:                }
1020:            }
1021:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.