cziegeler    2004/05/01 09:12:05

  Modified:    tools/src/anttasks ManifestToolTask.java SitemapTask.java
                        XConfToolTask.java DocumentCache.java
                        PoolSetterTask.java
  Log:
  Clean up code
  
  Revision  Changes    Path
  1.5       +3 -4      cocoon-2.1/tools/src/anttasks/ManifestToolTask.java
  
  Index: ManifestToolTask.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/tools/src/anttasks/ManifestToolTask.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ManifestToolTask.java     30 Apr 2004 07:20:33 -0000      1.4
  +++ ManifestToolTask.java     1 May 2004 16:12:05 -0000       1.5
  @@ -52,7 +52,7 @@
   
           try {
               // process recursive
  -            this.process(this.getProject().resolveFile(this.directory), 
this.manifest);
  +            this.process(this.getProject().resolveFile(this.directory));
           } catch (IOException ioe) {
               throw new BuildException("IOException: " + ioe);
           }
  @@ -61,8 +61,7 @@
       /**
        * Scan recursive
        */
  -    private void process(final File directoryFile,
  -                         final String manifest)
  +    private void process(final File directoryFile)
       throws IOException, BuildException {
   
           System.out.println("Writing: " + manifest);
  
  
  
  1.3       +18 -22    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SitemapTask.java  1 May 2004 10:49:41 -0000       1.2
  +++ SitemapTask.java  1 May 2004 16:12:05 -0000       1.3
  @@ -61,10 +61,7 @@
       /** Pooling grow (optional) */
       public static final String POOL_GROW_TAG = 
"cocoon.sitemap.component.pooling.grow";
       
  -    private static final String LINE_SEPARATOR = 
"\n";//System.getProperty("line.separator");
  -    
  -    /** The sitemap namespace. TODO - this has to be configurable for newer 
versions! */
  -    private static final String SITEMAP_NS = 
"http://apache.org/cocoon/sitemap/1.0";;
  +    private static final String LINE_SEPARATOR = "\n";
       
       /** The sitemap */
       private File sitemap;
  @@ -72,9 +69,6 @@
       /** The doc dir */
       private File docDir;
       
  -    /** The components */
  -    private List components = new ArrayList();
  -    
       public void setSitemap( final File sitemap ) {
           this.sitemap = sitemap;
       }
  @@ -94,16 +88,16 @@
           validate();
   
           // this does the hard work :)
  -        super.execute();
  +        super.execute();        
   
           try {
               
  -            this.collectInfo();
  +            final List components = this.collectInfo();
               if ( this.sitemap != null ) {
  -                this.processSitemap();
  +                this.processSitemap(components);
               }
               if ( this.docDir != null ) {
  -                this.processDocDir();
  +                this.processDocDir(components);
               }
               
           } catch ( final BuildException e ) {
  @@ -132,8 +126,10 @@
       /**
        * Collect the component infos
        */
  -    private void collectInfo() {
  +    private List collectInfo() {
           log("Collection sitemap components info");
  +        final List components = new ArrayList();
  +        
           final Iterator it = super.allClasses.iterator();
           
           while ( it.hasNext() ) {
  @@ -145,25 +141,25 @@
                   final SitemapComponent comp = new SitemapComponent( 
javaClass );
   
                   log("Found component: " + comp, Project.MSG_DEBUG);
  -                this.components.add(comp);
  +                components.add(comp);
               }
           }
  +        return components;
       }
   
       /**
        * Add components to sitemap
       */
  -    private void processSitemap() 
  +    private void processSitemap(List components) 
       throws Exception {
           log("Adding sitemap components");
  -        final String fileName = this.sitemap.toURL().toExternalForm();
           Document document;
           
  -        document = DocumentCache.getDocument(fileName, this);
  +        document = DocumentCache.getDocument(this.sitemap, this);
           
           boolean changed = false;
   
  -        Iterator iter = this.components.iterator();
  +        Iterator iter = components.iterator();
           while ( iter.hasNext() ) {
               SitemapComponent component = (SitemapComponent)iter.next();
               final String type = component.getType();
  @@ -192,17 +188,17 @@
           if ( changed ) {
               DocumentCache.writeDocument(this.sitemap, document, this);
           }
  -        DocumentCache.storeDocument(fileName, document, this);
  +        DocumentCache.storeDocument(this.sitemap, document, this);
       }
       
       /**
        * Add components to sitemap
       */
  -    private void processDocDir() 
  +    private void processDocDir(List components) 
       throws Exception {
           log("Generating documentation");
   
  -        Iterator iter = this.components.iterator();
  +        Iterator iter = components.iterator();
           while ( iter.hasNext() ) {
               final SitemapComponent component = (SitemapComponent)iter.next();
               
  @@ -261,7 +257,7 @@
                   buffer = new StringBuffer();
               }
               indent(parent, 3);
  -            node = doc.createElementNS(SITEMAP_NS, "map:" + this.type);
  +            node = doc.createElement("map:" + this.type);
               ((Element)node).setAttribute("name", this.name);
               ((Element)node).setAttribute("src", 
this.javaClass.getFullyQualifiedName());
               
  
  
  
  1.25      +15 -16    cocoon-2.1/tools/src/anttasks/XConfToolTask.java
  
  Index: XConfToolTask.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/tools/src/anttasks/XConfToolTask.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- XConfToolTask.java        30 Apr 2004 07:20:34 -0000      1.24
  +++ XConfToolTask.java        1 May 2004 16:12:05 -0000       1.25
  @@ -93,8 +93,8 @@
        *
        * @param xmlCatalog the XMLCatalog instance to use to look up DTDs
        */
  -    public void addConfiguredXMLCatalog(XMLCatalog xmlCatalog) {
  -      this.xmlCatalog.addConfiguredXMLCatalog(xmlCatalog);
  +    public void addConfiguredXMLCatalog(XMLCatalog newXMLCatalog) {
  +        this.xmlCatalog.addConfiguredXMLCatalog(newXMLCatalog);
       }
   
       /**
  @@ -121,8 +121,7 @@
               throw new BuildException("file attribute is required", 
this.getLocation());
           }
           try {
  -            final String fileName = this.file.toURL().toExternalForm();
  -            Document document = DocumentCache.getDocument(fileName, this);
  +            Document document = DocumentCache.getDocument(this.file, this);
               
               if (this.srcdir == null) {
                   this.srcdir = this.getProject().resolveFile(".");
  @@ -186,7 +185,7 @@
               } else {
                   log("No Changes: " + this.file, Project.MSG_DEBUG);
               }
  -            DocumentCache.storeDocument(fileName, document, this);
  +            DocumentCache.storeDocument(this.file, document, this);
           } catch (TransformerException e) {
               throw new BuildException("TransformerException: "+e);
           } catch (SAXException e) {
  @@ -208,16 +207,16 @@
        * 
        * @param configuration Orginal document
        * @param component Patch document
  -     * @param file Patch file
  +     * @param patchFile Patch file
        *
        * @return True, if the document was successfully patched
        */
       private boolean patch(final Document configuration,
  -                          final File file)
  -                          throws TransformerException, IOException, 
DOMException, SAXException {
  +                           final File patchFile)
  +                           throws TransformerException, IOException, 
DOMException, SAXException {
   
  -        Document component = 
DocumentCache.getDocument(file.toURL().toExternalForm(), this);
  -        String filename = file.toString();
  +        Document component = DocumentCache.getDocument(patchFile, this);
  +        String filename = patchFile.toString();
                               
           // Check to see if Document is an xconf-tool document
           Element elem = component.getDocumentElement();
  @@ -391,13 +390,13 @@
       }
   
       /** Returns the file name (excluding directories and extension). */
  -    private String basename(String file) {
  -        int start = file.lastIndexOf(FSEP)+1; // last '/'
  -        int end = file.lastIndexOf(".");  // last '.'
  +    private String basename(String fileName) {
  +        int start = fileName.lastIndexOf(FSEP)+1; // last '/'
  +        int end = fileName.lastIndexOf(".");  // last '.'
   
           if (end == 0) {
  -            end = file.length();
  +            end = fileName.length();
           }
  -        return file.substring(start, end);
  +        return fileName.substring(start, end);
       }
   }
  
  
  
  1.3       +8 -5      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DocumentCache.java        1 May 2004 10:49:41 -0000       1.2
  +++ DocumentCache.java        1 May 2004 16:12:05 -0000       1.3
  @@ -72,8 +72,9 @@
           }  
       }
   
  -    public static Document getDocument(String fileName, Task task) 
  -    throws SAXException {
  +    public static Document getDocument(File file, Task task) 
  +    throws SAXException, IOException {
  +        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);
  @@ -90,8 +91,10 @@
           return document;
       }
       
  -    public static void storeDocument(String fileName, Document document, 
Task task) {  
  -        task.log("Storing file in cache: " + fileName, Project.MSG_DEBUG);
  +    public static void storeDocument(File file, Document document, Task 
task) 
  +    throws IOException {  
  +        task.log("Storing file in cache: " + file, Project.MSG_DEBUG);
  +        final String fileName = file.toURL().toExternalForm();
           fileCache.put(fileName, document);
       }
   
  
  
  
  1.3       +3 -4      cocoon-2.1/tools/src/anttasks/PoolSetterTask.java
  
  Index: PoolSetterTask.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/tools/src/anttasks/PoolSetterTask.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PoolSetterTask.java       1 May 2004 13:20:09 -0000       1.2
  +++ PoolSetterTask.java       1 May 2004 16:12:05 -0000       1.3
  @@ -80,8 +80,7 @@
   
           try {
               // load xml
  -            final String fileName = this.file.toURL().toExternalForm();
  -            final Document configuration = 
DocumentCache.getDocument(fileName, this);
  +            final Document configuration = 
DocumentCache.getDocument(this.file, this);
   
               // process recursive
               boolean changed = false;
  @@ -112,7 +111,7 @@
                   // save xml
                   DocumentCache.writeDocument(this.file, configuration, this);
               }
  -            DocumentCache.storeDocument(fileName, configuration, this);
  +            DocumentCache.storeDocument(this.file, configuration, this);
          } catch (TransformerException e) {
               throw new BuildException("TransformerException: " + e);
           } catch (SAXException e) {
  
  
  

Reply via email to