cziegeler    2004/05/03 07:23:56

  Modified:    tools/src/anttasks SitemapTask.java
  Log:
  Add generated docs to index
  
  Revision  Changes    Path
  1.12      +30 -3     cocoon-2.1/tools/src/anttasks/SitemapTask.java
  
  Index: SitemapTask.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/tools/src/anttasks/SitemapTask.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SitemapTask.java  3 May 2004 13:07:26 -0000       1.11
  +++ SitemapTask.java  3 May 2004 14:23:56 -0000       1.12
  @@ -299,6 +299,33 @@
               
               // generate the doc
               component.generateDocs(template, docFile, this.getProject());
  +            
  +            // generate the index
  +            final File indexFile = new File(componentsDir, "book.xml");
  +            final Document indexDoc = DocumentCache.getDocument(indexFile, 
this);
  +            final String section;
  +            if ( this.blockName == null ) {
  +                section = "Core";
  +            } else {
  +                section = this.blockName + " Block";
  +            }
  +            Node sectionNode = XPathAPI.selectSingleNode(indexDoc, 
"/book/[EMAIL PROTECTED]'"+section+"']");
  +            if ( sectionNode == null ) {
  +                sectionNode = indexDoc.createElement("menu");
  +                ((Element)sectionNode).setAttribute("label", section);
  +                indexDoc.getDocumentElement().appendChild(sectionNode);
  +            }
  +            final String htmlName = docFile.getName().substring(0, 
docFile.getName().length()-3) + "html";
  +            Node oldEntry = XPathAPI.selectSingleNode(sectionNode, "[EMAIL 
PROTECTED]'"+htmlName+"']");
  +            Node newEntry = indexDoc.createElement("menu-item");
  +            ((Element)newEntry).setAttribute("href", htmlName);
  +            ((Element)newEntry).setAttribute("label", component.getName() + 
" " + component.getType());
  +            if ( oldEntry != null ) {
  +                oldEntry.getParentNode().replaceChild(newEntry, oldEntry);
  +            } else {
  +                sectionNode.appendChild(newEntry);
  +            }
  +            DocumentCache.writeDocument(indexFile, indexDoc, this);
           }
           
       }
  @@ -530,7 +557,7 @@
               this.merge(body, docFile);
               
               // finally write the doc
  -            DocumentCache.writeDocument(docFile, template, null);            
  +            DocumentCache.writeDocument(docFile, template, 
SitemapTask.this);            
           }
           
           /**
  @@ -541,7 +568,7 @@
           private void merge(Node body, File docFile) throws 
TransformerException {            
               final Document mergeDocument;
               try {
  -                mergeDocument = DocumentCache.getDocument(docFile, null);
  +                mergeDocument = DocumentCache.getDocument(docFile, 
SitemapTask.this);
               } catch (Exception ignore) {
                   return;
               }
  
  
  

Reply via email to