commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@multitask.com.au
Subject Re: cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml XPathSource.java
Date Mon, 03 Jun 2002 02:02:40 GMT

Go James, this is looking cool.
--
dIon Gillard, Multitask Consulting
Work:      http://www.multitask.com.au
Developers: http://adslgateway.multitask.com.au/developers


                                                                                         
                         
                    jstrachan@apac                                                       
                         
                    he.org               To:     jakarta-commons-sandbox-cvs@apache.org  
                         
                                         cc:                                             
                         
                    06/03/02 03:29       Subject:     cvs commit:                        
                         
                    AM                    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml

                    Please respond        XPathSource.java                               
                         
                    to "Jakarta                                                          
                         
                    Commons                                                              
                         
                    Developers                                                           
                         
                    List"                                                                
                         
                                                                                         
                         
                                                                                         
                         




jstrachan    2002/06/02 10:29:02

  Modified:    jelly    build.xml
               jelly/src/java/org/apache/commons/jelly/tags/ant
                        TaskTag.java DataTypeTag.java AntTagLibrary.java
               jelly/xdocs todo.xml
               jelly/src/test/org/apache/commons/jelly run_all.jelly
               jelly/src/java/org/apache/commons/jelly/tags/xml
                        XPathSource.java
  Added:       jelly/src/test/org/apache/commons/jelly/ant
                        filescanner.jelly show_properties.jelly
                        example_tasks.jelly
               jelly/src/java/org/apache/commons/jelly/tags/ant
                        FileScannerTag.java FileScanner.java
                        FileIterator.java TaskSource.java
  Removed:     jelly/src/test/org/apache/commons/jelly
                        show_ant_properties.jelly example_ant_tasks.jelly
  Log:
  Added a new <fileScanner> tag which creates a new FileScanner bean of the
given variable name, using Ant <fileset> elements.

  This allows files to be scanned (iterated over) using the standard
<j:forEach> tag via

  <fileScanner var="scanner">
    <fileset dir="foo" includes="**/*.xml"/>
  </fileScanner>
  <j:forEach var="file" items="${scanner.iterator()}">
           ...

  This mechanism is particularly useful for finding files to process,
performing recursive builds and so forth.
  It allows a nice mix of Ant tasks/datatypes and Jelly tags.

  Revision  Changes    Path
  1.1
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/filescanner.jelly


  Index: filescanner.jelly
  ===================================================================
  <?xml version="1.0"?>
<j:jelly xmlns:j="jelly:core" xmlns="jelly:ant">

  <fileScanner var="scanner">
    <fileset dir="src/taglibs" includes="**/build.xml"/>
  </fileScanner>

  Iterating through build files

  <j:forEach var="file" items="${scanner.iterator()}">

           <!-- here we could parse the file or process it in some way -->
           <!-- such as by calling <ant> with the given build.xml file -->

           Found <j:expr value="${file.absolutePath}"/>
  </j:forEach>
</j:jelly>


  1.1
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/show_properties.jelly


  Index: show_properties.jelly
  ===================================================================
  <?xml version="1.0"?>
<j:jelly xmlns:j="jelly:core">

  <html>
    <body>
      <h1>Ant properties</h1>

           <p>The project name is <b><j:expr value="${project.name}"/></b>
           </p>

      <table>
      <tr>
        <th>Targets</th>
      </tr>

      <j:forEach var="iter" items="${project.targets}">
        <tr>
          <td><j:expr value="${iter.key}"/></td>
        </tr>
      </j:forEach>
    </table>

    <table>
      <tr>
        <th>Property Name</th>
        <th>Property Value</th>
      </tr>

      <j:forEach var="iter" items="${project.getProperties()}">
        <tr>
          <td><j:expr value="${iter.key}"/></td>
          <td><j:expr value="${iter.value}"/></td>
        </tr>
      </j:forEach>
    </table>

  </body>

  </html>

  </j:jelly>


  1.1
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/ant/example_tasks.jelly


  Index: example_tasks.jelly
  ===================================================================
  <?xml version="1.0"?>
<j:jelly xmlns:j="jelly:core" xmlns="jelly:ant">
  Lets start by calling the echo task

  <!-- this example attempts to invoke some Ant tasks -->
  <echo message="Invoking the echo task from inside Jelly; the Maven
repository is ${lib.repo}"/>

  <!-- lets try invoke a program -->
  <java classname="org.apache.commons.jelly.Jelly" fork="yes">
    <classpath refid="test.classpath"/>
    <arg value="src/test/org/apache/commons/jelly/show_args.jelly"/>
    <arg value="one"/>
    <arg value="two"/>
    <arg value="three"/>
  </java>

  We should be back to the Jelly script again now...
</j:jelly>


  1.33      +9 -2      jakarta-commons-sandbox/jelly/build.xml

  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/build.xml,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- build.xml           30 May 2002 08:13:50 -0000          1.32
  +++ build.xml           2 Jun 2002 17:29:02 -0000           1.33
  @@ -213,14 +213,21 @@
      <target name="demo.ant" depends="compile"
         description="Runs demo which displays Ant properties">

  -        <jelly file
="src/test/org/apache/commons/jelly/show_ant_properties.jelly" output
="target/ant.html"/>
  +        <jelly file
="src/test/org/apache/commons/jelly/ant/show_properties.jelly" output
="target/ant.html"/>

      </target>

      <target name="demo.ant.task" depends="compile"
         description="Runs demo which invokes Ant tasks">

  -        <jelly file
="src/test/org/apache/commons/jelly/example_ant_tasks.jelly"/>
  +        <jelly file
="src/test/org/apache/commons/jelly/ant/example_tasks.jelly"/>
  +
  +   </target>
  +
  +   <target name="demo.ant.files" depends="compile"
  +      description="Runs Ant demo which scans files">
  +
  +        <jelly file
="src/test/org/apache/commons/jelly/ant/filescanner.jelly"/>

      </target>




  1.4       +7 -1
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskTag.java


  Index: TaskTag.java
  ===================================================================
  RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskTag.java,v

  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TaskTag.java        31 May 2002 11:32:21 -0000          1.3
  +++ TaskTag.java        2 Jun 2002 17:29:02 -0000           1.4
  @@ -76,7 +76,7 @@
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.6 $
    */
  -public class TaskTag extends DynaBeanTagSupport {
  +public class TaskTag extends DynaBeanTagSupport implements TaskSource {

       /** the Ant task */
       private Task task;
  @@ -98,6 +98,12 @@
           getBody().run(context, output);

           task.execute();
  +    }
  +
  +    // TaskSource interface
  +
//-------------------------------------------------------------------------

  +    public Object getTaskObject() {
  +        return task;
       }

       // Properties



  1.4       +17 -2
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/DataTypeTag.java


  Index: DataTypeTag.java
  ===================================================================
  RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/DataTypeTag.java,v

  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DataTypeTag.java         31 May 2002 11:32:21 -0000          1.3
  +++ DataTypeTag.java         2 Jun 2002 17:29:02 -0000           1.4
  @@ -61,6 +61,7 @@
    */
   package org.apache.commons.jelly.tags.ant;

  +import java.io.File;
   import java.lang.reflect.Method;

   import org.apache.commons.beanutils.ConvertingWrapDynaBean;
  @@ -98,16 +99,30 @@
           this.dataType = dataType;
           setDynaBean( new ConvertingWrapDynaBean(dataType) );
       }
  +
  +    // DynaTag interface
  +
//-------------------------------------------------------------------------

  +    public void setAttribute(String name, Object value) {
  +        if ( name.equals( "dir" ) ) {
  +            // ### this is a hack - we should install some standard
converters
  +            // ### for Reference and File types
  +            if ( value instanceof String ) {
  +                value = new File( (String) value );
  +            }
  +        }
  +        super.setAttribute(name, value);
  +    }
  +

       // Tag interface

//-------------------------------------------------------------------------

       public void doTag(XMLOutput output) throws Exception {
  -        TaskTag tag = (TaskTag) findAncestorWithClass( TaskTag.class );
  +        TaskSource tag = (TaskSource) findAncestorWithClass(
TaskSource.class );
           if ( tag == null ) {
               throw new JellyException( "You should only use Ant DataType
tags within an Ant Task" );
           }

  -        Task task = tag.getTask();
  +        Object task = tag.getTaskObject();
           Object dataType = getDataType();

           // now we need to configure the task with the data type



  1.3       +12 -0
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagLibrary.java


  Index: AntTagLibrary.java
  ===================================================================
  RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagLibrary.java,v

  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AntTagLibrary.java       30 May 2002 12:15:25 -0000          1.2
  +++ AntTagLibrary.java       2 Jun 2002 17:29:02 -0000           1.3
  @@ -105,6 +105,14 @@
       /** Creates a new script to execute the given tag name and
attributes */
       public TagScript createTagScript(String name, Attributes attributes)
throws Exception {
           Project project = getProject();
  +
  +        // custom Ant tags
  +        if ( name.equals("fileScanner") ) {
  +            Tag tag = new FileScannerTag(new FileScanner(project));
  +            return TagScript.newInstance(tag);
  +        }
  +
  +        // is it an Ant task?
           Class type = (Class) project.getTaskDefinitions().get(name);
           if ( type != null ) {
               Task task = (Task) type.newInstance();
  @@ -113,6 +121,8 @@
               Tag tag = new TaskTag( task );
               return TagScript.newInstance(tag);
           }
  +
  +        // an Ant DataType?
           Object dataType = null;
           type = (Class) project.getDataTypeDefinitions().get(name);
           if ( type != null ) {
  @@ -126,6 +136,8 @@
               tag.getDynaBean().set( "project", project );
               return TagScript.newInstance(tag);
           }
  +
  +        // assume its an Ant property object (classpath, arg etc).
           Tag tag = new TaskPropertyTag( name );
           return TagScript.newInstance(tag);
       }



  1.1
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/FileScannerTag.java


  Index: FileScannerTag.java
  ===================================================================
  /*
   * $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IfTag.java,v

1.6 2002/05/17 15:18:08 jstrachan Exp $
   * $Revision: 1.6 $
   * $Date: 2002/05/17 15:18:08 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: IfTag.java,v 1.6 2002/05/17 15:18:08 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.ant;

  import org.apache.commons.beanutils.ConvertingWrapDynaBean;
  import org.apache.commons.beanutils.DynaBean;

  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;

  /**
   * A tag which creates a new FileScanner bean instance that can be used
to
   * iterate over fileSets
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.6 $
   */
  public class FileScannerTag extends TagSupport implements TaskSource {

      /** The file walker that gets created */
      private FileScanner fileScanner;

      /** The DynaBean wrapping the FileScanner */
      private DynaBean dynaBean;

      /** the variable exported */
      private String var;

      public FileScannerTag(FileScanner fileScanner) {
          this.fileScanner = fileScanner;
          this.dynaBean = new ConvertingWrapDynaBean(fileScanner);
      }

      // Tag interface

//-------------------------------------------------------------------------

      public void doTag(XMLOutput output) throws Exception {
          // run the body first to configure the task via nested
          getBody().run(context, output);

          // output the fileScanner
          if ( var == null ) {
              throw new MissingAttributeException( "var" );
          }
          context.setVariable( var, fileScanner );
      }

      // TaskSource interface

//-------------------------------------------------------------------------

      public Object getTaskObject() {
          return fileScanner;
      }

      public DynaBean getDynaBean() {
          return dynaBean;
      }

      // Properties

//-------------------------------------------------------------------------


      /**
       * @return the Ant task
       */
      public FileScanner getFileScanner() {
          return fileScanner;
      }

      /** Sets the name of the variable exported by this tag */
      public void setVar(String var) {
          this.var = var;
      }

  }



  1.1
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/FileScanner.java


  Index: FileScanner.java
  ===================================================================
  /*
   * $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IfTag.java,v

1.6 2002/05/17 15:18:08 jstrachan Exp $
   * $Revision: 1.6 $
   * $Date: 2002/05/17 15:18:08 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: IfTag.java,v 1.6 2002/05/17 15:18:08 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.ant;

  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;

  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.types.FileSet;

  /**
   * <p><code>FileScanner</code> is a bean which allows the iteration
   * over a number of files from a colleciton of FileSet instances.
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.4 $
   */
  public class FileScanner {

      /** FileSets */
      private List filesets = new ArrayList();

      /** The Ant project */
      private Project project;

      public FileScanner(Project project) {
          this.project = project;
      }

      public Iterator iterator() {
          return new FileIterator(project, filesets.iterator());
      }

      // Properties

//-------------------------------------------------------------------------

      /**
       * Adds a set of files (nested fileset attribute).
       */
      public void addFileset(FileSet set) {
          filesets.add(set);
      }

  }





  1.1
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/FileIterator.java


  Index: FileIterator.java
  ===================================================================
  /*
   * $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IfTag.java,v

1.6 2002/05/17 15:18:08 jstrachan Exp $
   * $Revision: 1.6 $
   * $Date: 2002/05/17 15:18:08 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: IfTag.java,v 1.6 2002/05/17 15:18:08 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.ant;

  import java.io.File;
  import java.util.Iterator;
  import java.util.NoSuchElementException;

  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.DirectoryScanner;
  import org.apache.tools.ant.types.FileSet;
  import org.apache.tools.ant.types.FilterSet;

  /**
   * <p><code>FileIterator</code> is an iterator over a
   * over a number of files from a colleciton of FileSet instances.
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.4 $
   */
  public class FileIterator implements Iterator {

      /** The iterator over the FileSet objects */
      private Iterator fileSetIterator;

      /** The Ant project */
      private Project project;

      /** The directory scanner */
      private DirectoryScanner ds;

      /** The file names in the current FileSet scan */
      private String[] files;

      /** The current index into the file name array */
      private int fileIndex = -1;

      /** The next File object we'll iterate over */
      private File nextFile;

      /** Have we set a next object? */
      private boolean nextObjectSet = false;

      public FileIterator(Project project, Iterator fileSetIterator) {
          this.project = project;
          this.fileSetIterator = fileSetIterator;
      }

      // Iterator interface

//-------------------------------------------------------------------------

      /** @return true if there is another object that matches the given
predicate */
      public boolean hasNext() {
          if ( nextObjectSet ) {
              return true;
          }
          else {
              return setNextObject();
          }
      }

      /** @return the next object which matches the given predicate */
      public Object next() {
          if ( !nextObjectSet ) {
              if (!setNextObject()) {
                  throw new NoSuchElementException();
              }
          }
          nextObjectSet = false;
          return nextFile;
      }

      /**
       * throws UnsupportedOperationException
       */
      public void remove() {
          throw new UnsupportedOperationException();
      }

      // Implementation methods

//-------------------------------------------------------------------------

      /**
       * Set nextObject to the next object. If there are no more
       * objects then return false. Otherwise, return true.
       */
      private boolean setNextObject() {
          while (true) {
              while (ds == null) {
                  if ( ! fileSetIterator.hasNext() ) {
                      return false;
                  }
                  FileSet fs = (FileSet) fileSetIterator.next();
                  ds = fs.getDirectoryScanner(project);
                  ds.scan();
                  files = ds.getIncludedFiles();
                  if ( files.length > 0 ) {
                      fileIndex = -1;
                      break;
                  }
                  else {
                      ds = null;
                  }
              }

              if ( ds != null && files != null ) {
                  if ( ++fileIndex < files.length ) {
                      nextFile = new File( ds.getBasedir(),
files[fileIndex] );
                      nextObjectSet = true;
                      return true;
                  }
                  else {
                      ds = null;
                  }
              }
          }
      }
  }





  1.1
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskSource.java


  Index: TaskSource.java
  ===================================================================
  /*
   * $Header:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IfTag.java,v

1.6 2002/05/17 15:18:08 jstrachan Exp $
   * $Revision: 1.6 $
   * $Date: 2002/05/17 15:18:08 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: IfTag.java,v 1.6 2002/05/17 15:18:08 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.ant;

  import org.apache.commons.beanutils.DynaBean;

  /**
   * A tag which provides an Ant Task object on which to set Ant DataTypes
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.6 $
   */
  public interface TaskSource {

      /**
       * @return the task object which may be an Ant Task.
       */
      public Object getTaskObject();

      /**
       * @return a DynaBean wrapper around the Task object
       */
      public DynaBean getDynaBean();
  }



  1.6       +0 -4      jakarta-commons-sandbox/jelly/xdocs/todo.xml

  Index: todo.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/xdocs/todo.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- todo.xml       2 Jun 2002 05:15:41 -0000           1.5
  +++ todo.xml       2 Jun 2002 17:29:02 -0000           1.6
  @@ -15,10 +15,6 @@
         <ul>
           <li>support the use of ${foo.bar} expressions within attribute
values (as is common with Ant)
                     as well as inside element text also.</li>
  -        <li>write an Ant &lt;fileWalker&gt; tag that takes one or more
Ant &lt;fileSet&gt; elements
  -                  and outputs an Iterator to a variable that can then be
used inside a &lt;j:forEach&gt;
  -                  tag to perform processing for each file in an Ant
fileSet.
  -                  It'd be handy for recursive builds!</li>
           <li>autogenerate tag library documentation, in a kinda javadoc
style, showing all tag libraries,
                               their tags and descriptions of their
tags</li>
           <li>Develop a http tag library, probably based on
commons-httpclient, that can be used for scripting web services</li>



  1.4       +1 -1
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/run_all.jelly


  Index: run_all.jelly
  ===================================================================
  RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/run_all.jelly,v

  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- run_all.jelly       30 May 2002 16:47:17 -0000          1.3
  +++ run_all.jelly       2 Jun 2002 17:29:02 -0000           1.4
  @@ -1,6 +1,6 @@
   <?xml version="1.0"?>
<j:jelly xmlns:j="jelly:core">

  <!-- try an absolute path -->
     <j:include uri
="/src/test/org/apache/commons/jelly/hello_world.jelly"/>


  <!-- include other relative scripts... -->
  -  <j:include uri="example2.jelly"/>
  <j:include uri="jsl/example.jelly"/>
  +  <j:include uri="example2.jelly"/>
  <j:include uri="jsl/example.jelly"/>
  <j:include uri="ant/filescanner.jelly"/>

     <!-- now lets try pass in a variable to a child script -->
  <j:set var="foo">bar</j:set>
  <j:include uri="testFindVariable.jelly"/>

  <!-- loading all dynamic tags libraries -->
     <j:include uri="define/babelfishTaglib.jelly"/>




  1.2       +7 -5
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XPathSource.java


  Index: XPathSource.java
  ===================================================================
  RCS file:
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XPathSource.java,v

  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XPathSource.java         25 May 2002 18:27:21 -0000          1.1
  +++ XPathSource.java         2 Jun 2002 17:29:02 -0000           1.2
  @@ -66,11 +66,13 @@
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;

  -/** An abstract base class useful for implementation inheritence
  -  *
  -  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.5 $
  -  */
  +/**
  + * A tag which is capable of producing a source of XPath context objects
  + * such as &lt;x:forEach&gt;
  + *
  + * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  + * @version $Revision: 1.5 $
  + */
   public interface XPathSource {

       public Object getXPathSource();




--
To unsubscribe, e-mail:   <
mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <
mailto:commons-dev-help@jakarta.apache.org>






--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message