cziegeler    02/01/16 02:39:23

  Modified:    .        build.xml
               src/webapp cocoon.xconf
  Added:       src/java/org/apache/cocoon/components/hsqldb hsqldb.xconf
               tools/src XConfTool.java
  Log:
  Added new XConfTool which dynamically adds blocks to the cocoon.xconf. This 
is similar to the sitemap tool, but less sophisticated...for now
  
  Revision  Changes    Path
  1.140     +10 -1     xml-cocoon2/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/build.xml,v
  retrieving revision 1.139
  retrieving revision 1.140
  diff -u -r1.139 -r1.140
  --- build.xml 16 Jan 2002 03:36:49 -0000      1.139
  +++ build.xml 16 Jan 2002 10:39:22 -0000      1.140
  @@ -633,7 +633,8 @@
   
           <exclude name="**/Jaxen*"                    unless="jaxen.present"/>
   
  -        <exclude name="**/components/hsqldb/ServerImpl.java"       
unless="hsqldb.present"/>
  +        <exclude name="**/components/hsqldb/ServerImpl.java" 
unless="hsqldb.present"/>
  +        <exclude name="**/hsqldb.xconf"                      
unless="hsqldb.present"/>
   
           <exclude name="**/components/search/*"                 
unless="lucene.present"/>
           <exclude name="**/generation/SearchGenerator.java"     
unless="lucene.present"/>
  @@ -941,11 +942,19 @@
         <!-- A task to change the sitemap. It is used to add optional 
components -->
         <taskdef name="SitemapTool" classname="SitemapTool" 
             classpath="${tools.dir}/anttasks"/>
  +      <!-- A task to change the xconf. It is used to add optional components 
-->
  +      <taskdef name="XConfTool" classname="XConfTool" 
  +          classpath="${tools.dir}/anttasks"/>
   
         <!-- Invoke the SitemapTool to add optional entries -->
         <SitemapTool directory="${build.src}"
                      extension="sitemap"
                      sitemap="${build.war}/sitemap.xmap"/>
  +
  +      <!-- Invoke the XConfTool to add optional entries -->
  +      <XConfTool directory="${build.src}"
  +                 extension="xconf"
  +                 configuration="${build.war}/cocoon.xconf"/>
     </target>
   
     <!-- =================================================================== 
-->
  
  
  
  1.1                  
xml-cocoon2/src/java/org/apache/cocoon/components/hsqldb/hsqldb.xconf
  
  Index: hsqldb.xconf
  ===================================================================
  <!-- HSQLDB Server for samples:
      Comment this section out if you don't care about the samples.
          port   : number      port where the server is listening
          silent : true/false  display all queries
          trace  : true/false  display JDBC trace messages
    -->
    <hsqldb-server class="org.apache.cocoon.components.hsqldb.ServerImpl"
                   logger="core.hsqldb-server"
                   pool-max="1" pool-min="1">
       <parameter name="port" value="9002"/>
       <parameter name="silent" value="true"/>
       <parameter name="trace" value="false"/>
    </hsqldb-server>
  
  
  
  1.9       +0 -14     xml-cocoon2/src/webapp/cocoon.xconf
  
  Index: cocoon.xconf
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/webapp/cocoon.xconf,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- cocoon.xconf      15 Jan 2002 16:48:50 -0000      1.8
  +++ cocoon.xconf      16 Jan 2002 10:39:22 -0000      1.9
  @@ -25,20 +25,6 @@
     -->
     <parser logger="core.parser"/>
   
  -  <!-- HSQLDB Server for samples:
  -    Comment this section out if you don't care about the samples.
  -        port   : number      port where the server is listening
  -        silent : true/false  display all queries
  -        trace  : true/false  display JDBC trace messages
  -  -->
  -  <hsqldb-server class="org.apache.cocoon.components.hsqldb.ServerImpl"
  -                 logger="core.hsqldb-server"
  -                 pool-max="1" pool-min="1">
  -     <parameter name="port" value="9002"/>
  -     <parameter name="silent" value="true"/>
  -     <parameter name="trace" value="false"/>
  -  </hsqldb-server>
  -
     <!-- Storing:
       maxobjects: Indicates how many objects will be hold in the cache.
                   When the number of maxobjects has been reached. The
  
  
  
  1.1                  xml-cocoon2/tools/src/XConfTool.java
  
  Index: XConfTool.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   
*****************************************************************************/
  import java.io.*;
  import java.util.*;
  import org.apache.tools.ant.*;
  import org.apache.tools.ant.taskdefs.*;
  import org.apache.tools.ant.types.*;
  
  /**
   * Add components to the cocoon.xconf
   * This is only a ugly first shot
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/01/16 10:39:22 $
   */
  
  public final class XConfTool extends Task {
  
      private String configuration;
      private String directory;
      private String extension;
  
      public void setConfiguration(String configuration) {
          this.configuration = configuration;
      }
  
      public void setDirectory(String directory) {
          this.directory = directory;
      }
  
      public void setExtension(String extension) {
          this.extension = extension;
      }
  
      public void execute() throws BuildException {
          if (this.configuration == null) {
              throw new BuildException("configuration attribute is required", 
location);
          }
  
          if (this.extension == null) {
              throw new BuildException("extension attribute is required", 
location);
          }
          if (this.directory == null) {
              throw new BuildException("directory attribute is required", 
location);
          }
  
          try {
              // process recursive
              this.process(new File(this.directory), this.extension, 
this.configuration);
          } catch (IOException ioe) {
              throw new BuildException("IOException: " + ioe);
          }
      }
  
      /**
       * Scan recursive
       */
      private void process(final File   directoryFile,
                           final String ext,
                           final String configurationLocation)
      throws IOException, BuildException {
  
          final File[] files = directoryFile.listFiles();
  
          for(int i = 0; i < files.length; i++) {
  
              if (files[i].isDirectory() == true) {
                  this.process(files[i], ext, configurationLocation);
              } else {
  
                  if (files[i].getName().endsWith("."+ext) == true) {
                      System.out.println("Reading: " + 
files[i].getAbsolutePath());
                      final String newComponent = 
this.load(files[i].getAbsolutePath());
  
                      this.add(configurationLocation,
                               newComponent);
                  }
              }
          }
      }
  
      /**
       * Add entry to sitemap
       */
      private void add(final String configurationLocation,
                       final String newComponent)
      throws IOException {
          final String data = load( configurationLocation );
  
          // first search if component already present:
          if ( data.indexOf( newComponent ) == -1 ) {
              int pos = data.indexOf( "<cocoon" );
              if (pos != -1) {
                  pos = data.indexOf( ">", pos);
  
                  if (pos != -1) {
                      StringBuffer buffer = new StringBuffer( data.substring( 
0, pos+1 ) )
                                  .append( "\n\n" )
                                  .append( newComponent )
                                  .append( data.substring( pos+1 ) );
                      this.save( configurationLocation, buffer.toString() );
                  }
              }
          }
  
      }
  
      /**
       * Load a file and return the content as a string.
       */
      public String load( String filename )
      throws IOException {
          FileInputStream fis;
  
          fis = new FileInputStream( filename );
          int available;
          byte[] data = null;
          byte[] tempData;
          byte[] copyData;
          do
          {
              available = 1024;
              tempData = new byte[available];
              available = fis.read( tempData, 0, available );
              if ( available > 0 )
              {
                  copyData = new byte[( data == null ? 0 : data.length ) + 
available];
                  if ( data != null )
                  {
                      System.arraycopy( data, 0, copyData, 0, data.length );
                  }
                  System.arraycopy( tempData, 0, copyData, ( data == null ? 0 : 
data.length ), available );
                  data = copyData;
              }
          } while ( available > 0 );
          fis.close();
  
          return ( data != null ? new String( data ) : "" );
      }
  
      /**
       * Save the string to a file
       */
      public void save( String filename, String data )
      throws IOException
      {
          FileWriter fw = new FileWriter( filename );
          fw.write( data );
          fw.close();
      }
  
  }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to