cziegeler    2004/05/03 02:00:29

  Modified:    tools/src/anttasks SitemapTask.java DocumentCache.java
               src/documentation/templates sitemap-component.xml
  Log:
  Finish first version - merge already existing docs into the generated docs
  
  Revision  Changes    Path
  1.6       +37 -2     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SitemapTask.java  1 May 2004 18:06:12 -0000       1.5
  +++ SitemapTask.java  3 May 2004 09:00:28 -0000       1.6
  @@ -39,6 +39,12 @@
   import com.thoughtworks.qdox.model.JavaClass;
   
   /**
  + * Generate documentation for sitemap components based on javadoc tags
  + * in the source of the component.
  + * 
  + * This is the first, experimental version - the code is a little bit
  + * hacky but straight forward :)
  + * 
    * @since 2.1.5
    * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
    * @version CVS $Revision$ $Date$
  @@ -356,7 +362,7 @@
               final File componentsDir = new File(parentDir, this.type+'s');
               componentsDir.mkdir();
               
  -            final File docFile = new File(componentsDir, this.name + 
"-generated.xml");
  +            final File docFile = new File(componentsDir, this.name + "-" + 
this.type +".xml");
   
               final String doc = this.getDocumentation();
               if ( doc == null ) {
  @@ -422,8 +428,37 @@
               }
               setValue(body, "[EMAIL PROTECTED]'Info']/table/tr[3]/td[2]", 
cacheInfo);
               
  +            // merge with old doc
  +            this.merge(body, docFile);
  +            
               // finally write the doc
               DocumentCache.writeDocument(docFile, template, null);            
  +        }
  +        
  +        /**
  +         * Merge the sections of the old document with the new generated one.
  +         * All sections (s1) of the old document are added to the generated 
one
  +         * if not a section with the same title exists.
  +         */
  +        private void merge(Node body, File docFile) throws 
TransformerException {            
  +            final Document mergeDocument;
  +            try {
  +                mergeDocument = DocumentCache.getDocument(docFile, null);
  +            } catch (Exception ignore) {
  +                return;
  +            }
  +            NodeList sections = XPathAPI.selectNodeList(mergeDocument, 
"/document/body/s1");
  +            if ( sections != null ) {
  +                for(int i=0; i<sections.getLength(); i++) {
  +                    final Element current = (Element)sections.item(i);
  +                    final String title = current.getAttribute("title");
  +
  +                    // is this section not in the template?
  +                    if (XPathAPI.selectSingleNode(body, "[EMAIL 
PROTECTED]'"+title+"']") == null ) {
  +                        
body.appendChild(body.getOwnerDocument().importNode(current, true));
  +                    }
  +                }
  +            }
           }
           
           /**
  
  
  
  1.5       +7 -3      cocoon-2.1/tools/src/anttasks/DocumentCache.java
  
  Index: DocumentCache.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/tools/src/anttasks/DocumentCache.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DocumentCache.java        1 May 2004 18:06:12 -0000       1.4
  +++ DocumentCache.java        3 May 2004 09:00:28 -0000       1.5
  @@ -79,12 +79,16 @@
           final String fileName = file.toURL().toExternalForm();
           Document document = (Document)fileCache.get(fileName);
           if ( document != null ) {
  -            task.log("Using file from cache: " + fileName, 
Project.MSG_DEBUG);
  +            if ( task != null ) {
  +                task.log("Using file from cache: " + fileName, 
Project.MSG_DEBUG);
  +            }
               fileCache.remove(fileName);
           } else {
               try {
                   // load xml
  -                task.log("Reading: " + fileName, Project.MSG_DEBUG);
  +                if ( task != null ) {
  +                    task.log("Reading: " + fileName, Project.MSG_DEBUG);
  +                }
                   document = builder.parse(fileName);
               } catch (IOException e) {
                   throw new BuildException("IOException: "+e);
  
  
  
  1.2       +3 -0      
cocoon-2.1/src/documentation/templates/sitemap-component.xml
  
  Index: sitemap-component.xml
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/documentation/templates/sitemap-component.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sitemap-component.xml     1 May 2004 18:06:12 -0000       1.1
  +++ sitemap-component.xml     3 May 2004 09:00:29 -0000       1.2
  @@ -20,6 +20,9 @@
       <title></title>
       <version></version>
       <type>Reference</type>
  +    <authors>
  +      <person name="The Cocoon Community" email="[email protected]"/>
  +    </authors>
     </header>
     <body>
       <s1 title="Description">
  
  
  

Reply via email to