1 package de.webman.generator; 2 3 import com.teamkonzept.lib.*; 4 import org.apache.log4j.Category; 5 import de.webman.template.jsp.*; 6 import de.webman.util.log4j.WebmanCategory; 7 import com.teamkonzept.web.*; 8 import com.teamkonzept.web.templates.*; 9 import com.teamkonzept.webman.*; 10 import java.io.*; 12 import java.util.*; 13 import java.text.DateFormat ; 14 import org.w3c.dom.*; 15 import de.webman.util.legacy.Legacy; 16 17 22 public class GenDocument implements TKSortable, com.teamkonzept.lib.templates.TemplateTypes { 23 24 27 private GeneratorContext context; 28 29 30 private static WebmanCategory cat = (WebmanCategory)WebmanCategory.getInstance(GenDocument.class.getName()); 31 32 34 private GenNode anchor; 35 36 37 private String docName; 38 39 40 private String templateName; 41 42 43 private String externUrl; 44 45 46 private TKHashtable contents; 47 48 49 private TKHashtable references; 50 51 52 private TKHashtable realRefUrls; 53 54 55 private TKHashtable realRefDocs; 56 57 58 private TKHashtable realRefNodes; 59 60 61 private boolean registered = false; 62 63 public GenDocument( GeneratorContext context, GenNode anchor, String shortName, String templateName, 64 String externUrl, TKHashtable contents, TKHashtable references ) 65 { 66 this.context = context != null ? context : GeneratorContext.setup (); 67 68 this.anchor = anchor; 69 this.docName = shortName; 70 this.templateName = templateName; 71 72 this.externUrl = externUrl; 73 this.contents = contents; 74 this.references = references; 75 77 this.realRefUrls = null; 78 this.realRefDocs = null; 79 this.realRefNodes = null; 80 } 81 82 86 public String getDocumentName() 87 { 88 return docName; 89 } 90 91 94 public String getTemplateName() 95 { 96 return templateName; 97 } 98 99 102 public String getExternURL() 103 { 104 return externUrl; 105 } 106 107 110 public GenNode getAnchor() 111 { 112 return anchor; 113 } 114 115 119 public TKHashtable getContents() 120 { 121 return contents; 122 } 123 124 public TKHashtable getReferences() 125 { 126 return references; 127 } 128 129 public int cmp( TKSortable otherObject ) 130 { 131 if (!(otherObject instanceof GenDocument)) 133 { 134 return 0; 135 } 136 GenDocument other = (GenDocument) otherObject; 137 138 SiteContent myDataCont = (SiteContent) contents.get("DATA"); 139 SiteContent otherDataCont = (SiteContent) other.contents.get("DATA"); 140 141 if( myDataCont == null ) { 142 return ( otherDataCont == null ? 0 : 1 ); 143 } 144 else if( otherDataCont == null ) 145 { 146 return -1; 147 } 148 return myDataCont.cmp( otherDataCont ); 149 } 150 151 public void registerContents(boolean onlyStructureContents) 152 { 153 registered = true; 154 155 Enumeration e = contents.elements(); 156 while( e.hasMoreElements() ) { 157 Object cont = e.nextElement(); 158 if( cont instanceof TKVector ) { 159 Enumeration f = ((TKVector) cont).elements(); 160 while( f.hasMoreElements() ) 161 ((SiteContent)f.nextElement()).registerDoc( this, onlyStructureContents ); 162 } 163 else { 164 ((SiteContent)cont).registerDoc( this, onlyStructureContents ); 165 } 166 } 167 } 168 169 178 public void addRealReference( TKVector refUrls, TKVector refDocs, TKVector refNodes, GenNode destNode, SiteReference ref ) 179 { 180 int insertPos = -1; 181 cat.debug( "add Reference "+destNode.getPath() ); 182 if( ref.getDestinationContentSource() != null ) { 183 GenDocument destCont = destNode.getDocument( ref.getDestinationContentSource() ); 184 185 187 if( destCont == null ) { 188 throw new Error ("could not find content-source-document '"+ref.getDestinationContentSource()+"' for "+ref.path()+" in node "+ 189 destNode.getPath() ); 190 191 } 192 193 if (ref.getComponentType() == SiteReference.COMPONENT_TYPE_FREE) { 194 refDocs.addElement( destCont ); 195 insertPos = -1; 196 } else { 197 insertPos = 0; 198 int docListSize = refDocs.size(); 199 boolean done = false; 200 while( insertPos < docListSize && !done ) { 201 GenDocument currDoc = (GenDocument) refDocs.get(insertPos); 202 if( destCont.cmp( currDoc ) < 0 ) { 203 refDocs.insertElementAt( destCont, insertPos ); 204 done = true; 205 } 206 else { 207 insertPos++; 208 } 209 } 210 if( !done ) { 211 refDocs.addElement( destCont ); 212 insertPos = -1; 213 } 214 } 215 } 216 217 GenDocument destRef = destNode.getDocument( ref.getDestinationShortName() ); 218 219 if( insertPos == -1 ) { 221 refUrls.addElement ((destRef.externUrl != null ? destRef.externUrl 222 : anchor.makePathRelativeTo (destNode)+ref.getDestinationShortName())); 223 refNodes.addElement( destNode ); 224 } 225 else { 226 refUrls.insertElementAt ((destRef.externUrl != null ? destRef.externUrl 227 : anchor.makePathRelativeTo (destNode)+ref.getDestinationShortName() ), insertPos); 228 refNodes.insertElementAt( destNode, insertPos ); 229 } 230 } 232 233 244 public void addRealReference( String ownUrl, TKVector refUrls, TKVector refDocs, TKVector refNodes, 245 SiteNode destNode, SiteReference ref, SiteContent primContent ) 246 { 247 int primaryId = primContent != null ? primContent.getInstanceId() : -1; 248 249 GenNode gn = destNode.makeGenNode (primContent); 250 cat.debug("registerReal : " + gn); 251 if (gn == null) { 252 cat.warn("could not make genNode from siteNode for "+ref.path()+ 253 " in node "+destNode.path() ); 254 } 255 256 int insertPos = -1; 257 if( ref.getDestinationContentSource() != null ) { 258 259 SiteDocument sd = destNode.getDocument( ref.getDestinationContentSource() ); 260 if (sd == null) { 261 cat.warn("could not find referenced document '"+ref.getDestinationShortName() + 262 "' for "+ref.getPath()+" in node "+destNode.getPath() ); 263 } 264 265 if (context.siteNodes.isReducedBuild()) sd.complete(); 266 267 GenDocument destCont = sd != null ? sd.getGenDocument( primContent, gn ) : null; 268 269 if (destCont == null) { 270 cat.warn("could not find gen content-source-document '"+ref.getDestinationContentSource()+ 271 "' for "+ref.getPath()+" in node "+destNode.getPath() ); 272 return; 273 } 274 275 if (ref.getComponentType() == SiteReference.COMPONENT_TYPE_FREE) { 276 refDocs.addElement( destCont ); 277 insertPos = -1; 278 } else { 279 insertPos = 0; 280 int docListSize = refDocs.size(); 281 boolean done = false; 282 while( insertPos < docListSize && !done ) { 283 GenDocument currDoc = (GenDocument) refDocs.get(insertPos); 284 cat.debug("cmp "+destCont.anchor.getPath()+destCont.docName+" with "+currDoc.anchor.getPath()+ currDoc.docName ); 285 if( destCont.cmp( currDoc ) <= 0 ) { 286 refDocs.insertElementAt( destCont, insertPos ); 287 done = true; 288 } 289 else { 290 insertPos++; 291 } 292 } 293 294 if( !done ) { 295 refDocs.addElement( destCont ); 296 insertPos = -1; 297 } 298 } 299 } 300 301 SiteDocument destRef = destNode.getDocument( ref.getDestinationShortName() ); 302 if (destRef == null) { 303 cat.warn("destRef ist null !" ); 304 throw new Error ("could not find referenced document '"+ref.getDestinationShortName()+ 305 "' for "+ref.getPath()+" in node "+destNode.getPath() ); 306 } 307 308 310 String docId = "null"; 311 if (destRef.getURL() == null) { 312 313 TKConverter urlConv = TKConverter.getConverter ("URL"); 314 docId = new String (urlConv.stringToBytes (destRef.getShortName()),0); 315 } 316 317 if( insertPos == -1 ) { 318 319 refUrls.addElement ((destRef.getURL() != null ? destRef.getURL() 320 : ownUrl+"?TK_EV[CE_PREVIEW]=1"+ 321 "&TK_PAR[SNODE]="+destNode.getId()+ 322 "&TK_PAR[PID]="+primaryId+ 323 "&TK_PAR[DOCNAME]="+docId+ 324 "&TK_PAR[CHECKER]=1")); 325 refNodes.addElement( gn ); 326 } else { 327 refUrls.insertElementAt ((destRef.getURL() != null ? destRef.getURL() 328 : ownUrl+"?TK_EV[CE_PREVIEW]=1"+ 329 "&TK_PAR[SNODE]="+destNode.getId()+ 330 "&TK_PAR[PID]="+primaryId+ 331 "&TK_PAR[DOCNAME]="+docId+ 332 "&TK_PAR[CHECKER]=1"),insertPos); 333 refNodes.insertElementAt( gn, insertPos ); 334 } 335 } 336 337 340 public void registerReferences() 341 { 342 try 343 { 344 registered = true; 345 346 int size = references.size(); 347 if( size == 0 ) return; 348 349 TKVector refsToDelete = new TKVector(); 350 351 realRefUrls = new TKHashtable( size ); 352 realRefDocs = new TKHashtable( size ); 353 realRefNodes = new TKHashtable( size ); 354 Enumeration e = references.keys(); 356 while( e.hasMoreElements() ) 357 { 358 String intName = (String ) e.nextElement(); 359 cat.debug("register : " + intName); 360 SiteReference ref = (SiteReference) references.get(intName); 361 TKVector currUrls = new TKVector(); 362 realRefUrls.put( intName, currUrls ); 363 TKVector currDocs = null; 364 if( ref.getDestinationContentSource() != null ) { 365 currDocs = new TKVector(); 366 realRefDocs.put( intName, currDocs ); 367 } 368 369 TKVector currNodes = new TKVector(); 370 realRefNodes.put( intName, currNodes ); 371 372 378 if ((ref.getIntegrationType() == SiteReference.INTEGRATION_TYPE_SINGLE) && 379 (ref.getSelectionType() == null)) { 380 if (ref.getDestinationDocuments().length == 0) 381 { 382 cat.error("No destination for reference component: " + intName + " in document: " + anchor.getPath() + getDocumentName() + " found !"); 384 continue; 385 } 386 SiteNode refAnchor = (SiteNode) ref.getDestinationDocuments()[0].getAnchor(); 387 GenNode refNode = (refAnchor == anchor.getSiteNode()) 388 ? anchor 389 : (GenNode)refAnchor.getGenNodes().get(0); 390 addRealReference( currUrls, currDocs, currNodes, refNode, ref ); 391 } else { 392 TKVector allNodes = new TKVector(); 393 for( int i=0; i<ref.getDestinationDocuments().length; i++ ) { 394 allNodes.concat( ref.getDestinationDocuments()[i].getAnchor().getGenNodes() ); 395 } 396 Enumeration f = allNodes.elements(); 397 while( f.hasMoreElements() ) { 398 GenNode node3 = (GenNode)f.nextElement(); 399 addRealReference( currUrls, currDocs, currNodes, node3, ref ); 400 } 401 402 if( ref.getSelectionType() != null ) 403 TKWMReferenceSelectorReg.reduceReferences( 404 ref.getSelectionType(), 405 ref.getSelectionData(), 406 currUrls, 407 currDocs, 408 currNodes, 409 this.anchor 410 ); 411 if( ref.getIntegrationType() == SiteReference.INTEGRATION_TYPE_SINGLE ) { 412 int remainSize = currUrls.size(); 413 if( remainSize == 0 ) refsToDelete.addElement( intName ); 414 else { 415 for( int i=remainSize-1; i>0; i-- ) { 416 currUrls.removeElementAt(i); 417 if( currDocs!=null ) currDocs.removeElementAt(i); 418 currNodes.removeElementAt(i); 419 } 420 } 421 } 422 } 423 } 424 e = refsToDelete.elements(); 425 while( e.hasMoreElements() ) { 426 references.remove( e.nextElement() ); 427 }; 428 429 e = references.keys(); 430 while( e.hasMoreElements() ) { 431 String intName = (String ) e.nextElement(); 432 SiteReference ref = (SiteReference) references.get(intName); 433 Enumeration f = ((TKVector) realRefDocs.get( intName )).elements(); 434 while( f.hasMoreElements() ) { 435 ((GenDocument)f.nextElement()).registerContents( ref.getComponentType() == SiteReference.COMPONENT_TYPE_FREE); 436 } 437 } 438 } 439 catch (Throwable t) 440 { 441 t.printStackTrace(System.out); 442 cat.error("Unknown in registerReferences" + t.getMessage(), t); 443 } 444 445 } 446 447 452 public void makeReferences(String ownUrl, SiteContent primContent) 453 { 454 int size = references.size(); 455 if( size == 0 ) return; 456 457 TKVector refsToDelete = new TKVector(); 458 459 realRefUrls = new TKHashtable( size ); 460 realRefDocs = new TKHashtable( size ); 461 realRefNodes = new TKHashtable( size ); 462 463 Enumeration e = references.keys(); 464 while( e.hasMoreElements() ) { 465 String intName = (String ) e.nextElement(); 466 467 SiteReference ref = (SiteReference) references.get(intName); 468 TKVector currUrls = new TKVector(); 469 realRefUrls.put( intName, currUrls ); 470 TKVector currDocs = null; 471 472 if (ref.getDestinationContentSource() != null) { 473 474 currDocs = new TKVector(); 475 realRefDocs.put (intName,currDocs); 476 } 477 478 TKVector currNodes = new TKVector(); 479 realRefNodes.put( intName, currNodes ); 480 481 485 490 if ((ref.getIntegrationType() == SiteReference.INTEGRATION_TYPE_SINGLE ) && 491 (ref.getSelectionType() == null)) { 492 if (ref.getDestinationDocuments().length == 0) 493 { 494 cat.error("No destination for reference component: " + intName + " found !"); 496 continue; 497 } 498 499 SiteNode refAnchor = (SiteNode) ref.getDestinationDocuments()[0].getAnchor(); 500 501 if (refAnchor == anchor.getSiteNode()) { 502 addRealReference( ownUrl, currUrls, currDocs, currNodes, refAnchor, ref, primContent ); 503 504 } else if (refAnchor.getType() == SiteNode.NODE_TYPE_GROUP) { 505 506 TKVector primConts = null; 507 508 if( refAnchor.getPrimaryContentSelectionKey() != null ) 509 primConts = context.integrations.getSelection( refAnchor.getPrimaryContentSelectionKey() ); 510 else if (refAnchor.getPrimaryContentNode() != null) 511 primConts = refAnchor.getPrimaryContentNode().getContents(); 512 513 if (primConts == null) continue; 514 515 Enumeration ee = primConts.elements(); 516 if (ee.hasMoreElements()) { 517 518 SiteContent sc = (SiteContent) ee.nextElement(); 519 if (sc != null) addRealReference( ownUrl, currUrls, currDocs, currNodes, refAnchor, ref, sc ); 520 } 521 } else { 522 addRealReference( ownUrl, currUrls, currDocs, currNodes, refAnchor, ref, null ); 523 } 524 } else { 525 for( int i=0; i<ref.getDestinationDocuments().length; i++ ) { 526 if (ref.getDestinationDocuments()[i] != null) 527 { 528 SiteNode refAnchor = (SiteNode) ref.getDestinationDocuments()[i].getAnchor(); 529 530 if (refAnchor.getType() == SiteNode.NODE_TYPE_GROUP) { 531 532 TKVector primConts = null; 533 534 if( refAnchor.getPrimaryContentSelectionKey() != null ) 535 primConts = context.integrations.getSelection( refAnchor.getPrimaryContentSelectionKey() ); 536 else if (refAnchor.getPrimaryContentNode() != null) 537 primConts = refAnchor.getPrimaryContentNode().getContents(); 538 539 if (primConts == null) continue; 540 541 Enumeration ee = primConts.elements(); 542 while (ee.hasMoreElements()) 543 { 544 SiteContent sc = (SiteContent) ee.nextElement(); 545 if (sc != null) addRealReference( ownUrl, currUrls, currDocs, currNodes, refAnchor, ref, sc ); 546 } 547 } else { 548 addRealReference( ownUrl, currUrls, currDocs, currNodes, refAnchor, ref, null ); 549 } 550 } 551 } 552 553 if( ref.getSelectionType() != null ) 554 TKWMReferenceSelectorReg.reduceReferences( 555 ref.getSelectionType(), 556 ref.getSelectionData(), 557 currUrls, 558 currDocs, 559 currNodes, 560 this.anchor 561 ); 562 563 if( ref.getIntegrationType() == SiteReference.INTEGRATION_TYPE_SINGLE ) { 564 int remainSize = currUrls.size(); 565 if( remainSize == 0 ) refsToDelete.addElement( intName ); 566 else { 567 for( int i=remainSize-1; i>0; i-- ) { 568 currUrls.removeElementAt(i); 569 if( currDocs!=null ) currDocs.removeElementAt(i); 570 currNodes.removeElementAt(i); 571 } 572 } 573 } 574 } 575 } 576 577 e = refsToDelete.elements(); 578 while( e.hasMoreElements() ) { 579 references.remove( e.nextElement() ); 580 }; 581 } 582 584 public void prepareGeneration() 585 { 586 cat.debug("prepare document " + anchor.getPath() + "/" +docName); 587 registerContents(false); 588 registerReferences(); 589 cat.debug("document prepared'"+docName); 590 } 591 592 public void deregisterContents (boolean onlyStructureContents) 593 { 594 Enumeration e = contents.elements(); 595 while( e.hasMoreElements() ) { 596 Object cont = e.nextElement(); 597 if( cont instanceof TKVector ) { 598 Enumeration f = ((TKVector) cont).elements(); 599 while( f.hasMoreElements() ) 600 ((SiteContent)f.nextElement()).deregisterDoc( this, onlyStructureContents ); 601 } 602 else { 603 ((SiteContent)cont).deregisterDoc( this, onlyStructureContents ); 604 } 605 } 606 } 607 608 public void deregisterReferences() 609 { 610 Enumeration e = references.keys(); 611 while( e.hasMoreElements() ) { 612 String intName = (String ) e.nextElement(); 613 SiteReference ref = (SiteReference) references.get(intName); 614 615 Enumeration f = ((TKVector) realRefDocs.get( intName )).elements(); 616 while( f.hasMoreElements() ) { 617 ((GenDocument)f.nextElement()).deregisterContents( ref.getComponentType() == SiteReference.COMPONENT_TYPE_FREE); 618 } 619 } 620 } 621 622 public void cleanupGeneration() 623 { 624 if (!registered) return; 625 626 deregisterContents(false); 627 deregisterReferences(); 628 } 629 630 public TKVector sortContents( TKVector contents ) 631 { 632 TKVector result = contents.sort(); 633 return result; 634 } 635 636 642 public void generateDOMContents( Element domAnchor, DOMTemplateData domData, boolean onlyStructureContents ) 643 { 644 String node = anchor.getPath(); 645 domAnchor.setAttribute( "DOCUMENT", node+docName ); 647 domAnchor.setAttribute( "NODE_PATH", node ); 648 domAnchor.setAttribute( "NODE", anchor.getNodeName() ); 649 domAnchor.setAttribute( "LEVEL", Integer.toString(anchor.depth()-1) ); 650 Enumeration e = contents.keys(); 651 while( e.hasMoreElements() ) 652 { 653 String intName = (String ) e.nextElement(); 654 Object cont = contents.get(intName); 655 boolean isListInt = cont instanceof TKVector; 656 657 SiteContent firstCont = (isListInt 658 ? (SiteContent)((TKVector) cont).get(0) 659 : (SiteContent)cont 660 ); 661 if (firstCont != null && (firstCont.isStructureContent() || !onlyStructureContents)) 662 { 663 Element currentElement = domData.getContentElement(intName, domAnchor); 665 666 if( isListInt ) 667 { 668 domAnchor.setAttribute( intName, Integer.toString(((TKVector)cont).size()) ); 669 TKVector sortContents = sortContents( (TKVector)cont ); 670 671 for (int i = 0; i < sortContents.size(); i++) 672 { 673 SiteContent content = ((SiteContent)((TKVector)cont).elementAt(i)); 675 Element contentElement = domData.getContentElement("content", currentElement); 676 677 681 context.push(); if ((content != null) && (!onlyStructureContents || content.isStructureContent())) 684 { 685 domAnchor.setAttribute( intName+".IDX", String.valueOf(i+1) ); content.fillBasicDOM( domData.getDocument(), contentElement ); 688 } 689 context.pop(); } 691 } 692 else { 693 context.push(); 697 if (firstCont != null) 698 { 699 if (!onlyStructureContents || firstCont.isStructureContent()) 701 { 702 String cName = firstCont.isStructureContent() ? "site" :firstCont.getShortName(); 703 if (cName != null && cName.length() != 0) 704 { 705 try 706 { 707 708 Integer.parseInt(cName.substring(0,1)); 709 cName = 'A' + cName; 710 } 711 catch(NumberFormatException nfe) 712 { 713 cat.debug("Content Kennung ist eine Nummer"); 714 } 715 } 716 717 Element contentElement = domData.getContentElement("content", currentElement); 718 firstCont.fillBasicDOM( domData.getDocument(), contentElement ); 719 } 720 } 721 722 context.pop(); 723 } 724 } 725 } 726 } 727 728 733 public void generateContents( TemplateBasic t, String prefix, boolean onlyStructureContents ) 734 { 735 if (t.getType().equals(JSP_TEMPLATE)) 736 { 737 generateDOMContents(t.getDOMData().getRoot(), t.getDOMData(), onlyStructureContents); 738 } 739 else 740 { 741 String node = anchor.getPath(); 742 743 t.set( prefix+"DOCUMENT", node+docName ); 745 t.set( prefix+"NODE_PATH", node ); 746 t.set( prefix+"NODE", anchor.getNodeName() ); 747 t.set( prefix+"LEVEL", Integer.toString(anchor.depth()-1) ); 748 749 Enumeration e = contents.keys(); 750 while( e.hasMoreElements() ) 751 { 752 String intName = (String ) e.nextElement(); 753 Object cont = contents.get(intName); 754 boolean isListInt = cont instanceof TKVector; 755 SiteContent firstCont = (isListInt 756 ? (SiteContent)((TKVector) cont).get(0) 757 : (SiteContent)cont 758 ); 759 760 if( isListInt ) 761 { 762 t.set( prefix+intName, Integer.toString(((TKVector)cont).size()) ); 763 TKVector sortContents = sortContents( (TKVector)cont ); 764 TKHTMLTemplate htmlTemplate = (TKHTMLTemplate)t; 765 htmlTemplate.setListIterator( 766 new GenContentIterator( 767 context, sortContents, prefix+intName, 768 htmlTemplate.getListIterator(), 769 onlyStructureContents, false, false 770 ) 771 ); 772 } 773 else { 774 if (firstCont != null) 775 { 776 context.push(); 778 firstCont.fillNameIntoTemplate(t, prefix+intName ); 779 780 if (!onlyStructureContents || firstCont.isStructureContent()) 781 firstCont.fillIntoTemplate( t, prefix+intName ); 782 context.pop(); 783 } 784 } 785 } 786 } 787 } 788 789 public void generateReferences( TemplateBasic t, DOMTemplateData domData, String tmplBase, 790 boolean isPreview, String ownUrl, String rootDir ) 791 { 792 Enumeration e = references.keys(); 793 while( e.hasMoreElements() ) { 794 String intName = (String ) e.nextElement(); 795 SiteReference ref = (SiteReference) references.get(intName); 796 TKVector refUrls = (TKVector) realRefUrls.get( intName ); 797 TKVector refDocs = (TKVector) realRefDocs.get( intName ); 798 TKVector refNodes = (TKVector) realRefNodes.get( intName ); 799 800 if( ref.getIntegrationType() == SiteReference.INTEGRATION_TYPE_SINGLE ) { 801 if( refUrls.size() > 0 ) { 802 context.genDocuments.fillReferenceIntoTemplate( 803 t, 804 domData, 805 (String ) refUrls.get(0), 806 (refNodes == null ? null : (GenNode) refNodes.get(0)), 807 anchor, 808 (refDocs == null ? null : (GenDocument) refDocs.get(0)), 809 intName, ref, tmplBase, ownUrl, rootDir, isPreview 810 ); 811 } 812 } 813 else { 814 if (t.getType().equals(JSP_TEMPLATE)) 815 { 816 for (int i = 0; i < refUrls.size(); i++) 817 { 818 context.genDocuments.fillReferenceIntoTemplate( 819 t, domData, 820 (String ) refUrls.get(i), 821 (refNodes == null ? null : (GenNode) refNodes.get(i)), 822 anchor, 823 (refDocs == null ? null : (GenDocument) refDocs.get(i)), 824 intName, ref, tmplBase, ownUrl, rootDir, isPreview 825 ); 826 } 827 } 828 else 829 { 830 if (refUrls != null) 831 { 832 t.set( intName, Integer.toString(refUrls.size()) ); 833 ((TKHTMLTemplate)t).setListIterator( 834 new GenReferenceIterator( 835 context, anchor, ref, refUrls, refNodes, refDocs, 836 tmplBase, intName, ownUrl, rootDir, isPreview, 837 ((TKHTMLTemplate)t).getListIterator() 838 ) 839 ); 840 } 841 } 842 } 843 } 844 } 845 846 public void generateToPrintStream ( PrintStream out, String tmplBase, 847 TKHashtable data, boolean isPreview, String ownUrl, String rootDir) 848 throws Exception  849 { 850 TemplateBasic t = TemplateUtils.getTemplate(templateName, tmplBase, false); 851 852 DOMTemplateData domData = t.getDOMData(); 853 Date timestamp = new Date(); 854 855 856 t.set( "SECONDS", String.valueOf( timestamp.getTime() ) ); t.set( "DATE", DateFormat.getDateInstance(DateFormat.SHORT).format(timestamp)); 858 t.set( "TIME", DateFormat.getTimeInstance(DateFormat.SHORT).format(timestamp)); 859 860 if (data != null) t.set (data); 861 862 synchronized (context) 863 { 864 generateContents(t, "", false); 865 generateReferences(t, domData, tmplBase, isPreview, ownUrl, rootDir); 866 } 867 if (t.getType() != JSP_TEMPLATE) 868 { 869 if (isPreview) t.set( "DISPLACEMENT",""); 870 else t.set( "DISPLACEMENT","<TKK_DISPLACEMENT[ANSI]>"); 871 } 872 t.doTagSubstitution(); 873 t.printTemplate( out ); 874 875 cleanupGeneration(); 876 } 877 878 886 public void generate( File baseDir, String rootDir, String tmplBase, PrintStream genFileLogStream ) 887 throws Exception  888 { 889 cat.info(new Date().toString() + ": start doc generation : " + baseDir + " / " + docName, WebmanCategory.ALL); 892 GeneratorContext.setCurrentDocument(this); 894 895 897 File outFile = new File( baseDir, docName ); 898 String path = outFile.getAbsolutePath(); 899 900 Boolean expanded = (Boolean ) context.genDocuments.getDocumentExpanded(path); 901 902 if (expanded != null && expanded.booleanValue()) 903 { 904 if (genFileLogStream != null) 905 genFileLogStream.println (path); 906 return; 907 } 908 909 if (expanded != null && !expanded.booleanValue()) 910 { 911 context.genDocuments.putExpandedGenDoc (path,new Boolean (true)); 912 return; 913 } 914 915 context.genDocuments.putExpandedGenDoc (path,new Boolean (false)); 916 917 FileOutputStream f = new FileOutputStream( outFile ); 918 PrintStream out = null; 919 try 920 { 921 out = new PrintStream(f); 922 923 generateToPrintStream (out,tmplBase,null,false,null,rootDir); 924 } 925 finally 926 { 927 out.close(); 928 } 929 930 context.genDocuments.putExpandedGenDoc(path,new Boolean (true)); 931 if (genFileLogStream != null) 932 genFileLogStream.println (path); 933 935 940 } 941 942 public void generatePreview(PrintStream out, String rootDir, String tmplBase, String ownUrl ) 943 throws Exception  944 { 945 TKHashtable data = new TKHashtable(); 946 data.put ("PREVIEW",Boolean.TRUE); 947 948 File sourceDir = new File( rootDir ); 949 if( anchor.getSiteNode().getParent() != null ) 950 sourceDir = new File( sourceDir, anchor.getSubPathDir()); 951 952 File outFile = new File( sourceDir, docName ); 953 String path = outFile.getAbsolutePath(); 954 955 Object cached = context.genDocuments.getDocumentExpanded(path); 956 if (cached != null) { 957 if (cached instanceof Boolean ) { 958 if (!((Boolean ) cached).booleanValue()) 959 { 960 context.genDocuments.putExpandedGenDoc (path,new Boolean (true)); 961 } 962 } else out.print ((String ) cached); 963 964 } else { 965 context.genDocuments.putExpandedGenDoc(path,new Boolean (false)); 966 generateToPrintStream (out,tmplBase,data,true, ownUrl,rootDir); 967 } 968 } 969 } 970
| Popular Tags
|