cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: xml-cocoon2/src/org/apache/cocoon/serialization fop.sitemap
Date Thu, 22 Nov 2001 15:30:54 GMT
cziegeler    01/11/22 07:30:54

  Modified:    .        build.xml
  Added:       bin/anttasks SitemapTool.class
               bin/src  SitemapTool.java
               src/org/apache/cocoon/generation tidy.sitemap
               src/org/apache/cocoon/serialization fop.sitemap
  Log:
  A new SitemapTool which replaces st.java.
  The SitemapTool is an ant task which can recursivly crawl
  through a directory tree and process all files with a given extension
  (I use the ending .sitemap).
  Each file can contain definitions which are then added to the sitemap,
  like:
  
  label:content|category:generators|componentName:html|componentClass:org.apache.cocoon.generation.HTMLGenerator
  
  With the use of the additional compilation (copying of java source code
  and .sitemap files) this makes the maintaining of the build system
  much easier.
  
  The next step will be to completly use this for all optional packages.
  Currently as a demonstration this is only done for tidy and fop.
  
  Revision  Changes    Path
  1.98      +13 -41    xml-cocoon2/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/build.xml,v
  retrieving revision 1.97
  retrieving revision 1.98
  diff -u -r1.97 -r1.98
  --- build.xml	2001/11/22 12:59:13	1.97
  +++ build.xml	2001/11/22 15:30:54	1.98
  @@ -140,8 +140,11 @@
   
     <!-- A simple task to test for a class -->
     <taskdef name="ClassAvailable" classname="ClassAvailable" classpath="./bin/anttasks"/>
  +  <!-- A task to change the sitemap. It is used to add optional components -->
  +  <taskdef name="SitemapTool" classname="SitemapTool" classpath="./bin/anttasks"/>
   
   
  +
     <!--
       Give user a chance to override without editing this file
       (and without typing -D each time he compiles it)
  @@ -442,6 +445,11 @@
       <mkdir dir="${build.dest}"/>
       <copy todir="${build.src}" filtering="on">
         <fileset dir="${src.dir}">
  +        <exclude name="**/HTMLGenerator.java"  unless="tidy.present"/>
  +        <exclude name="**/tidy.sitemap"        unless="tidy.present"/>
  +        <exclude name="**/FOP*"                unless="fop.present"/>
  +        <exclude name="**/renderer/*"          unless="fop.present"/>
  +        <exclude name="**/fop.sitemap"         unless="fop.present"/>
           <exclude name="**/http/RequestWrapper*.java"/>
           <exclude name="**/Ora*.java" unless="ora.driver.present"/>
           <exclude name="**/Ifx*.java" unless="ifx.driver.present"/>
  @@ -557,10 +565,7 @@
         <exclude name="**/SVG*.java"           unless="svg.present"/>
         <exclude name="**/Javascript*"         unless="rhino.present"/>
         <exclude name="**/Jstyle*"             unless="jstyle.present"/>
  -      <exclude name="**/FOP*"                unless="fop.present"/>
  -      <exclude name="**/renderer/*"          unless="fop.present"/>
         <exclude name="**/Php*"                unless="php.present"/>
  -      <exclude name="**/HTMLGenerator.java"  unless="tidy.present"/>
         <exclude name="**/J2eeDataSource.java" unless="j2ee.present"/>
         <exclude name="**/xpath/XPathProcessorImpl*" unless="xpath.present"/>
         <exclude name="**/Jaxen*"              unless="jaxen.present"/>
  @@ -793,30 +798,6 @@
     </target>
   
     <!-- =================================================================== -->
  -  <!-- Prepares the webapp sitemap if fop is available                     -->
  -  <!-- =================================================================== -->
  -  <target name="prepare-webapp-fop" depends="copy-webapp" if="fop.present">
  -    <java classname="st">
  -        <arg line="-i ${build.war}/sitemap.xmap -o ${build.war}/sitemap.xmap -m application/pdf
        -a serializers fo2pdf org.apache.cocoon.serialization.FOPSerializer"/>
  -        <classpath>
  -          <pathelement location="${bin.dir}"/>
  -        </classpath>
  -    </java>
  -    <java classname="st">
  -        <arg line="-i ${build.war}/sitemap.xmap -o ${build.war}/sitemap.xmap -m application/postscript
         -a serializers fo2ps  org.apache.cocoon.serialization.FOPSerializer"/>
  -        <classpath>
  -          <pathelement location="${bin.dir}"/>
  -        </classpath>
  -    </java>
  -    <java classname="st">
  -        <arg line="-i ${build.war}/sitemap.xmap -o ${build.war}/sitemap.xmap -m 'application/vnd.hp-PCL'
-a serializers fo2pcl org.apache.cocoon.serialization.FOPSerializer"/>
  -        <classpath>
  -          <pathelement location="${bin.dir}"/>
  -        </classpath>
  -    </java>
  -  </target>
  -
  -  <!-- =================================================================== -->
     <!-- Prepares the webapp sitemap if JFOR is available                  -->
     <!-- =================================================================== -->
     <target name="prepare-webapp-jfor" depends="copy-webapp" if="jfor.present">
  @@ -829,18 +810,6 @@
     </target>
   
     <!-- =================================================================== -->
  -  <!-- Prepares the webapp sitemap if jtidy is available                     -->
  -  <!-- =================================================================== -->
  -  <target name="prepare-webapp-tidy" depends="copy-webapp" if="tidy.present">
  -    <java classname="st">
  -        <arg line="-i ${build.war}/sitemap.xmap -o ${build.war}/sitemap.xmap -l content
-a generators html org.apache.cocoon.generation.HTMLGenerator"/>
  -        <classpath>
  -          <pathelement location="${bin.dir}"/>
  -        </classpath>
  -    </java>
  -  </target>
  -
  -  <!-- =================================================================== -->
     <!-- Prepares the webapp sitemap if jndi is available                   -->
     <!-- =================================================================== -->
     <target name="prepare-webapp-naming" depends="copy-webapp" if="naming.present">
  @@ -881,8 +850,11 @@
     <!-- =================================================================== -->
     <!-- Prepares the webapp directories                                     -->
     <!-- =================================================================== -->
  -  <target name="prepare-webapp" depends="copy-webapp, prepare-webapp-php, prepare-webapp-xt,
prepare-webapp-fop, prepare-webapp-tidy, prepare-webapp-naming, prepare-webapp-xmldb, prepare-webapp-jfor">
  -      <!-- Simply do nothing, just invoke all dependencies -->
  +  <target name="prepare-webapp" depends="copy-webapp, prepare-webapp-php, prepare-webapp-xt,
prepare-webapp-naming, prepare-webapp-xmldb, prepare-webapp-jfor">
  +      <!-- Invoke the SitemapTool to add optional entries -->
  +      <SitemapTool directory="${build.src}"
  +                   extension="sitemap"
  +                   sitemap="${build.war}/sitemap.xmap"/>
     </target>
   
     <!-- =================================================================== -->
  
  
  
  1.1                  xml-cocoon2/bin/anttasks/SitemapTool.class
  
  	<<Binary file>>
  
  
  1.1                  xml-cocoon2/bin/src/SitemapTool.java
  
  Index: SitemapTool.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 java.util.zip.*;
  import org.apache.tools.ant.*;
  import org.apache.tools.ant.taskdefs.*;
  import org.apache.tools.ant.types.*;
  
  /**
   * Add components to the sitemap
   *
   * @author Carsten Ziegeler <a href="mailto:cziegeler@apache.org">cziegeler@apache.org</a>
   */
  
  public final class SitemapTool extends Task {
  
      private String sitemap;
      private String directory;
      private String label;
      private String mimeType;
      private String componentClass;
      private String category;
      private String componentName;
      private String configuration;
      private String extension;
  
      public void setSitemap(String sitemap) {
          this.sitemap = sitemap;
      }
  
      public void setDirectory(String directory) {
          this.directory = directory;
      }
  
      public void setExtension(String extension) {
          this.extension = extension;
      }
  
      public void setLabel(String label) {
          this.label = label;
      }
  
      public void setMimeType(String mimeType) {
          this.mimeType = mimeType;
      }
  
      public void setComponentClass(String componentClass) {
          this.componentClass = componentClass;
      }
  
      public void setCategory(String category) {
          this.category = category;
      }
  
      public void setComponentName(String componentName) {
          this.componentName = componentName;
      }
  
      public void setConfiguration(String configuration) {
          // optional
          this.configuration = configuration;
      }
  
      public void execute() throws BuildException {
          if (this.sitemap == null) {
              throw new BuildException("sitemap attribute is required", location);
          }
  
          if (this.directory != null && this.extension == null) {
              throw new BuildException("extension attribute is required", location);
          }
          if (this.directory == null && this.extension != null) {
              throw new BuildException("directory attribute is required", location);
          }
  
          try {
              if (this.directory != null && this.extension != null) {
                  // process recursive
                   this.process(new File(this.directory), this.extension);
              } else {
                  if (this.category == null) {
                      throw new BuildException("category attribute is required", location);
                  }
                  if (this.componentName == null) {
                      throw new BuildException("componentName attribute is required", location);
                  }
                  if (this.componentClass == null) {
                      throw new BuildException("componentClass attribute is required", location);
                  }
                  this.add(this.category,
                       this.componentName,
                       this.componentClass,
                       this.configuration,
                       this.label,
                       this.mimeType);
              }
          } catch (IOException ioe) {
              throw new BuildException("IOException: " + ioe);
          }
      }
  
      /**
       * Scan recursive
       */
      private void process(final File directory,
                           final String extension)
      throws IOException, BuildException {
          final File[] files = directory.listFiles();
          for(int i = 0; i < files.length; i++) {
              if (files[i].isDirectory() == true) {
                  this.process(files[i], extension);
              } else {
                  if (files[i].getName().endsWith("."+extension)) {
                      System.out.println("Reading: " + files[i].getAbsolutePath());
                      final String data = this.load(files[i].getAbsolutePath());
                      final StringTokenizer st = new StringTokenizer(data);
                      while (st.hasMoreElements() == true) {
                          final String line = (String)st.nextElement();
                          final StringTokenizer prop = new StringTokenizer(line, "|");
                          String category = null;
                          String componentName = null;
                          String className = null;
                          String configuration = null;
                          String label = null;
                          String mimeType = null;
                          while (prop.hasMoreElements() == true) {
                              final String property = (String)prop.nextElement();
                              final int pos = property.indexOf(":");
                              final String propName = property.substring(0, pos);
                              final String propVal  = property.substring(pos+1);
                              if     (propName.equals("category")) category = propVal;
                              else if (propName.equals("componentName")) componentName = propVal;
                              else if (propName.equals("componentClass")) className = propVal;
                              else if (propName.equals("configuration")) configuration = propVal;
                              else if (propName.equals("label")) label = propVal;
                              else if (propName.equals("mimeType")) mimeType = propVal;
                              else throw new BuildException("Unknown property " + propName
+ " in file " + files[i].getAbsolutePath());
                          }
                          if (category == null) {
                              throw new BuildException("category property is required in file
" + files[i].getAbsolutePath(), location);
                          }
                          if (componentName == null) {
                              throw new BuildException("componentName property is required
in file " + files[i].getAbsolutePath(), location);
                          }
                          if (className == null) {
                              throw new BuildException("componentClass property is required
in file " + files[i].getAbsolutePath(), location);
                          }
                          this.add(category,
                                   componentName,
                                   className,
                                   configuration,
                                   label,
                                   mimeType);
                      }
                  }
              }
          }
      }
  
      /**
       * Add entry to sitemap
       */
      private void add(String category,
                       String componentName,
                       String className,
                       String configuration,
                       String label,
                       String mimeType)
      throws IOException {
          final String data = load( this.sitemap );
  
          final String searchString = new StringBuffer( "</map:" )
                                          .append( category )
                                          .append( ">" ).toString();
          final int pos = data.indexOf( searchString );
          int categoryStartPos = data.indexOf(new StringBuffer( "<map:" )
                                              .append( category )
                                              .append( ">" ).toString() );
  
          if ( categoryStartPos == -1 )
              categoryStartPos = data.indexOf(new StringBuffer( "<map:" )
                                              .append( category )
                                              .append( " " ).toString() );
  
          if ( categoryStartPos != -1 && categoryStartPos < pos && pos
!= -1 ) {
              // the category exists, now search if a component
              // with the name already exists
              int componentPos = data.substring( categoryStartPos, pos ).indexOf(
                      new StringBuffer( "name=\"" )
                                .append( componentName )
                                .append( "\"" ).toString() );
              if ( componentPos == -1 ) {
                  StringBuffer buffer = new StringBuffer( data.substring( 0, pos ) )
                              .append( "<map:" ).append( category.substring( 0, category.length()
- 1 ) )
                              .append( " name=\"" ).append( componentName ).append( "\" src=\""
).append( className ).append( "\"" );
  
                  if ( null != mimeType && mimeType.length() > 0) {
                       buffer.append( " mime-type=\"" ).append( mimeType ).append( "\"" );
                  }
                  if ( null != label && label.length() > 0) {
                       buffer.append( " label=\"" ).append( label ).append( "\"" );
                  }
                  if ( null != configuration ) {
                      buffer.append( ">\n" ).append( configuration ).append( "\n" )
                          .append( "</map:" ).append( category.substring( 0, category.length()
- 1 ) ).append( ">\n" );
                  } else {
                      buffer.append( "/>\n" );
                  }
                  buffer.append( data.substring( pos ) ).toString();
                  this.save( this.sitemap, buffer.toString() );
              }
          }
  
      }
  
      /**
       * Load the sitemap
       */
      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 sitemap
       */
      public void save( String filename, String data )
      throws IOException
      {
          FileWriter fw = new FileWriter( filename );
          fw.write( data );
          fw.close();
      }
  
  }
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/generation/tidy.sitemap
  
  Index: tidy.sitemap
  ===================================================================
  label:content|category:generators|componentName:html|componentClass:org.apache.cocoon.generation.HTMLGenerator
  
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/serialization/fop.sitemap
  
  Index: fop.sitemap
  ===================================================================
  mimeType:application/pdf|category:serializers|componentName:fo2pdf|componentClass:org.apache.cocoon.serialization.FOPSerializer
  mimeType:application/postscript|category:serializers|componentName:fo2ps|componentClass:org.apache.cocoon.serialization.FOPSerializer
  mimeType:application/vnd.hp-PCL|category:serializers|componentName:fo2pcl|componentClass:org.apache.cocoon.serialization.FOPSerializer
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message