You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/02/12 22:34:35 UTC

cvs commit: jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly example2.jelly hello_world.jelly TestXMLTags.java example.jelly

jstrachan    02/02/12 13:34:35

  Modified:    jelly    TODO.txt build.xml
               jelly/src/java/org/apache/commons/jelly Context.java
                        Tag.java
               jelly/src/java/org/apache/commons/jelly/expression
                        ConstantExpression.java Expression.java
               jelly/src/java/org/apache/commons/jelly/impl
                        ScriptBlock.java TagScript.java
               jelly/src/java/org/apache/commons/jelly/parser
                        XMLParser.java
               jelly/src/java/org/apache/commons/jelly/tags/xml
                        ExprTag.java ForEachTag.java ParseTag.java
                        SetTag.java XPathExpression.java
               jelly/src/test/org/apache/commons/jelly TestXMLTags.java
                        example.jelly
  Added:       jelly/src/java/org/apache/commons/jelly Jelly.java
                        TagSupport.java
               jelly/src/java/org/apache/commons/jelly/expression
                        ExpressionFactory.java ExpressionSupport.java
               jelly/src/java/org/apache/commons/jelly/expression/beanshell
                        BeanShellExpression.java
                        BeanShellExpressionFactory.java
               jelly/src/java/org/apache/commons/jelly/tags/core
                        CoreTagLibrary.java ExprTag.java ForEachTag.java
                        JellyTag.java SetTag.java package.html
               jelly/src/test/org/apache/commons/jelly example2.jelly
                        hello_world.jelly
  Log:
  Added more examples and things to do. Also added parent relationship to Tag interface and make the body script a property of Tags so that they can modify and change their body at will (e.g. be a pre-processor or macro). Also added early version of core tags with a stub implementation of ExpressionFactory which I'll try get working with beanshell. A velocity & rhino implementation would be nice too...
  
  Revision  Changes    Path
  1.3       +13 -1     jakarta-commons-sandbox/jelly/TODO.txt
  
  Index: TODO.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/TODO.txt,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TODO.txt	11 Feb 2002 18:14:17 -0000	1.2
  +++ TODO.txt	12 Feb 2002 21:34:33 -0000	1.3
  @@ -1,6 +1,14 @@
   TO DO LIST
   ==========
   
  +* introduce a config file on the classpath that describes the default URIs -> class names.
  +
  +* make 'body' a property of a Tag; then at the compile() stage a Tag can change its body if it wishes - or expand it etc.
  +
  +* the org.apache.commons.jelly.impl package doesn't have a great name - can we think of a better one? 
  +  also some of the classes in this package could maybe do with a rename? ScriptBlock for example - should we 
  +  just call it a Block or maybe a CompositeScript?
  +		
   * add core tags from JSTL with pluggable expression engines like Velocity, beanshell, Rhino etc.
   
   * add EmptyScript to allow tags optimise if their body is empty.
  @@ -9,7 +17,11 @@
     unnecessary whitespace can be removed at compile time.
   
   * add parent Context and support for other scopes such as session, request, cookie, initParam, param etc.
  -  maybe add a Scope class for variable names which can contain a scope name and variable name
  +  maybe add a Scope class for variable names which can contain a scope name and variable name. Then things like
  +  cookie:foo or initParam:bar can be parsed at compile time into an object.	
  +
  +* add getResource() and getResourceAsStream() methods from ServletContext to Context to allow 
  +  included files to be loaded etc.	
   
   * make Ant task to run Jelly
   
  
  
  
  1.2       +17 -1     jakarta-commons-sandbox/jelly/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.xml	11 Feb 2002 00:27:40 -0000	1.1
  +++ build.xml	12 Feb 2002 21:34:33 -0000	1.2
  @@ -3,7 +3,7 @@
   
   <!--
           "Digester" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.1 2002/02/11 00:27:40 jstrachan Exp $
  +        $Id: build.xml,v 1.2 2002/02/12 21:34:33 jstrachan Exp $
   -->
   
   
  @@ -263,6 +263,22 @@
      </target>
   
   <!-- ========== Sample Program Targets ==================================== -->
  +
  +   <target name="demo.hw" depends="compile" 
  +      description="Runs the Hello World demo">
  +    <java classname="org.apache.commons.jelly.Jelly" fork="yes">
  +      <classpath refid="test.classpath"/>
  +      <arg value="src/test/org/apache/commons/jelly/hello_world.jelly"/> 
  +    </java>
  +   </target>
  +
  +   <target name="demo.1" depends="compile" 
  +      description="Runs demo #1">
  +    <java classname="org.apache.commons.jelly.Jelly" fork="yes">
  +      <classpath refid="test.classpath"/>
  +      <arg value="src/test/org/apache/commons/jelly/example2.jelly"/> 
  +    </java>
  +   </target>
   
   
   </project>
  
  
  
  1.2       +12 -5     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java
  
  Index: Context.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Context.java	11 Feb 2002 00:27:40 -0000	1.1
  +++ Context.java	12 Feb 2002 21:34:33 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java,v 1.1 2002/02/11 00:27:40 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:40 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java,v 1.2 2002/02/12 21:34:33 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/12 21:34:33 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: Context.java,v 1.1 2002/02/11 00:27:40 jstrachan Exp $
  + * $Id: Context.java,v 1.2 2002/02/12 21:34:33 jstrachan Exp $
    */
   package org.apache.commons.jelly;
   
  @@ -68,12 +68,19 @@
   /** <p><code>Context</code> represents the Jelly context.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
   public class Context {
   
       /** synchronized access to the variables in scope */
       private Map variables = new Hashtable();
  +
  +    public Context() {
  +    }
  +    
  +    public Context(Map variables) {
  +        this.variables.putAll( variables );
  +    }
       
       /** @return the value of the given variable name */
       public Object getVariable( String name ) {
  
  
  
  1.2       +18 -6     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Tag.java
  
  Index: Tag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Tag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Tag.java	11 Feb 2002 00:27:40 -0000	1.1
  +++ Tag.java	12 Feb 2002 21:34:33 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Tag.java,v 1.1 2002/02/11 00:27:40 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:40 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Tag.java,v 1.2 2002/02/12 21:34:33 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/12 21:34:33 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: Tag.java,v 1.1 2002/02/11 00:27:40 jstrachan Exp $
  + * $Id: Tag.java,v 1.2 2002/02/12 21:34:33 jstrachan Exp $
    */
   package org.apache.commons.jelly;
   
  @@ -66,12 +66,24 @@
   /** <p><code>Tag</code> represents a Jelly custom tag.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
   public interface Tag {
   
  +    /** @return the parent of this tag */
  +    public Tag getParent();
  +    
  +    /** Sets the parent of this tag */
  +    public void setParent(Tag parent);
  +
  +    /** @return the body of the tag */
  +    public Script getBody();
  +    
  +    /** Sets the body of the tag */
  +    public void setBody(Script body);    
  +    
       /** Evaluates this tag after all the tags properties have been initialized.
        */
  -    public void run(Context context, Writer writer, Script body) throws Exception;
  +    public void run(Context context, Writer writer) throws Exception;
       
   }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Jelly.java
  
  Index: Jelly.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Jelly.java,v 1.1 2002/02/12 21:34:33 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/12 21:34:33 $
   *
   * ====================================================================
   *
   * 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: Jelly.java,v 1.1 2002/02/12 21:34:33 jstrachan Exp $
   */
  package org.apache.commons.jelly;
  
  import java.io.BufferedWriter;
  import java.io.FileWriter;
  import java.io.OutputStreamWriter;
  import java.io.Writer;
  
  import org.apache.commons.jelly.parser.XMLParser;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  
  /** <p><code>Jelly</code> an application which runs a Jelly script.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class Jelly {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogSource.getInstance( Jelly.class );
  
  
      public static void main(String[] args) throws Exception {
          if ( args.length <= 0 ) {
              System.out.println( "Usage: Jelly scriptFile [outputFile]" );
              return;
          }
          String input = args[0];
          Writer writer = ( args.length > 1 ) 
              ? new FileWriter( args[1] ) 
              : new OutputStreamWriter( System.out );
          BufferedWriter output = new BufferedWriter( writer );
          
          XMLParser parser = new XMLParser();
          Script script = parser.parse( input );
      
          script = script.compile();
          
          if ( log.isDebugEnabled() ) {
              log.debug( "Compiled script: " + script );
          }
          
          Context context = new Context( System.getProperties() );        
          script.run( context, output );
          output.close();
      }    
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagSupport.java
  
  Index: TagSupport.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagSupport.java,v 1.1 2002/02/12 21:34:33 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/12 21:34:33 $
   *
   * ====================================================================
   *
   * 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: TagSupport.java,v 1.1 2002/02/12 21:34:33 jstrachan Exp $
   */
  package org.apache.commons.jelly;
  
  import java.io.StringWriter;
  import java.io.Writer;
  
  /** <p><code>TagSupport</code> an abstract base class which is useful to 
    * inherit from if developing your own tag.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public abstract class TagSupport implements Tag {
  
      /** the parent of this tag */
      private Tag parent;
      
      /** the body of the tag */
      private Script body;
  
      /** 
       * Searches up the parent hierarchy from the given tag 
       * for a Tag of the given type 
       *
       * @param from the tag to start searching from
       * @param tagClass the type of the tag to find
       * @return the tag of the given type or null if it could not be found
       */
      public static Tag findAncestorWithClass(Tag from, Class tagClass) {
          while ( from != null ) {
              if ( tagClass.isInstance( from ) ) {
                  return from;
              }
              from = from.getParent();
          }
          return null;
      }
  
      /** @return the parent of this tag */
      public Tag getParent() {
          return parent;
      }
      
      /** Sets the parent of this tag */
      public void setParent(Tag parent) {
          this.parent = parent;
      }
  
      /** @return the body of the tag */
      public Script getBody() {
          return body;
      }
      
      /** Sets the body of the tag */
      public void setBody(Script body) {
          this.body = body; 
      }
      
      // Implementation methods
      //-------------------------------------------------------------------------                
      
      /** 
       * Searches up the parent hierarchy for a Tag of the given type 
       * @return the tag of the given type or null if it could not be found
       */
      protected Tag findAncestorWithClass(Class parentClass) {
          return findAncestorWithClass( getParent(), parentClass );
      }
  
      /**
       * Evaluates the given body using a buffer and returns the String 
       * of the result.
       *
       * @return the text evaluation of the body
       */
      protected String getBodyText( Context context ) throws Exception {
          // XXX: could maybe optimise this later on by having a pool of buffers
          StringWriter writer = new StringWriter();
          body.run( context, writer );
          return writer.toString();
      }
      
  }
  
  
  
  1.2       +6 -6      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/ConstantExpression.java
  
  Index: ConstantExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/ConstantExpression.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConstantExpression.java	11 Feb 2002 00:27:41 -0000	1.1
  +++ ConstantExpression.java	12 Feb 2002 21:34:34 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/ConstantExpression.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:41 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/ConstantExpression.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/12 21:34:34 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: ConstantExpression.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  + * $Id: ConstantExpression.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
    */
   package org.apache.commons.jelly.expression;
   
  @@ -68,9 +68,9 @@
     * <p> In other words, {@link #evaluate} returns a value independent of the context. </p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
  -public class ConstantExpression implements Expression {
  +public class ConstantExpression extends ExpressionSupport {
   
       /** The value of this expression */
       private Object value;
  
  
  
  1.2       +27 -6     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/Expression.java
  
  Index: Expression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/Expression.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Expression.java	11 Feb 2002 00:27:41 -0000	1.1
  +++ Expression.java	12 Feb 2002 21:34:34 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/Expression.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:41 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/Expression.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/12 21:34:34 $
    *
    * ====================================================================
    *
  @@ -57,22 +57,43 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: Expression.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  + * $Id: Expression.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
    */
   package org.apache.commons.jelly.expression;
   
  +import java.util.Iterator;
  +
   import org.apache.commons.jelly.Context;
   
   /** <p><code>Expression</code> represents an arbitrary expression using some pluggable
     * expression language.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
   public interface Expression {
   
  -    /** Evaluates the expression with the given context
  +    /** 
  +     * Evaluates the expression with the given context
        * and returns the result 
        */
       public Object evaluate(Context context);        
  +    
  +    /**
  +     * Evaluates the expression with the given context
  +     * coercing the result to be a String.
  +     */
  +    public String evaluateAsString(Context context);
  +    
  +    /**
  +     * Evaluates the expression with the given context
  +     * coercing the result to be a boolean.
  +     */
  +    public boolean evaluateAsBoolean(Context context);
  +    
  +    /**
  +     * Evaluates the expression with the given context
  +     * coercing the result to be an Iterator.
  +     */
  +    public Iterator evaluateAsIterator(Context context);
   }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/ExpressionFactory.java
  
  Index: ExpressionFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/ExpressionFactory.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/12 21:34:34 $
   *
   * ====================================================================
   *
   * 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: ExpressionFactory.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   */
  package org.apache.commons.jelly.expression;
  
  import java.util.Iterator;
  
  import org.apache.commons.jelly.Context;
  
  /** <p><code>ExpressionFactory</code> is a factory of Expression objects.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public interface ExpressionFactory {
  
      /** 
       * Creates a new expression for the given text 
       */
      public Expression createExpression(String text) throws Exception;
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/ExpressionSupport.java
  
  Index: ExpressionSupport.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/ExpressionSupport.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/12 21:34:34 $
   *
   * ====================================================================
   *
   * 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: ExpressionSupport.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   */
  package org.apache.commons.jelly.expression;
  
  import java.util.Collections;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  
  import org.apache.commons.collections.ArrayIterator;
  import org.apache.commons.collections.SingletonIterator;
  
  import org.apache.commons.jelly.Context;
  
  /** <p><code>ExpressionSupport</code> 
    * an abstract base class for Expression implementations
    * which provides default implementations of some of the
    * typesafe evaluation methods.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public abstract class ExpressionSupport implements Expression {
  
      protected static final Iterator EMPTY_ITERATOR = Collections.EMPTY_LIST.iterator();
      
      // inherit javadoc from interface
      public String evaluateAsString(Context context) {
          Object value = evaluate(context);
          if ( value != null ) {
              return value.toString();
          }
          return null;
      }
      
      // inherit javadoc from interface
      public boolean evaluateAsBoolean(Context context) {
          Object value = evaluate(context);
          if ( value instanceof Boolean ) {
              Boolean b = (Boolean) value;
              return b.booleanValue();
          }
          else if ( value instanceof String ) {
              return Boolean.getBoolean( (String) value );
          }
          return false;
      }
      
      // inherit javadoc from interface
      public Iterator evaluateAsIterator(Context context) {
          Object value = evaluate(context);
          if ( value == null ) {
              return EMPTY_ITERATOR;
          }
          else
          if ( value instanceof Iterator ) {
              return (Iterator) value;
          }
          else if ( value instanceof List ) {
              List list = (List) value;
              return list.iterator();
          }
          else if ( value instanceof Map ) {
              Map map = (Map) value;
              return map.entrySet().iterator();
          }
          else if ( value.getClass().isArray() ) {
              return new ArrayIterator( value );
          }
          else {
              // XXX: should we return single iterator?
              return new SingletonIterator( value );
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/beanshell/BeanShellExpression.java
  
  Index: BeanShellExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/beanshell/BeanShellExpression.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/12 21:34:34 $
   *
   * ====================================================================
   *
   * 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: BeanShellExpression.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   */
  package org.apache.commons.jelly.expression.beanshell;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.expression.ExpressionSupport;
  
  /** Represents a <a href="http://www.beanshell.org">beanshell</a> expression
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class BeanShellExpression extends ExpressionSupport {
  
      /** The expression */
      private String text;
      
      public BeanShellExpression(String text) {
          this.text = text;
      }
  
      // Expression interface
      //------------------------------------------------------------------------- 
      public Object evaluate(Context context) {
          return null;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/beanshell/BeanShellExpressionFactory.java
  
  Index: BeanShellExpressionFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/beanshell/BeanShellExpressionFactory.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/12 21:34:34 $
   *
   * ====================================================================
   *
   * 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: BeanShellExpressionFactory.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   */
  package org.apache.commons.jelly.expression.beanshell;
  
  import org.apache.commons.jelly.expression.Expression;
  import org.apache.commons.jelly.expression.ExpressionFactory;
  
  /** Represents a factory of <a href="http://www.beanshell.org">beanshell</a> expressions
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class BeanShellExpressionFactory implements ExpressionFactory {
  
      // ExpressionFactory interface
      //------------------------------------------------------------------------- 
      public Expression createExpression(String text) throws Exception {
          int length = text.length();
          if ( length > 2 && text.charAt(0) == '{'  && text.charAt( length - 1 ) == '}' ) {
              text = text.substring( 1, length - 1 );
              return new BeanShellExpression(text);
          }
          return null;
      }
  }
  
  
  
  1.2       +13 -7     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/ScriptBlock.java
  
  Index: ScriptBlock.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/ScriptBlock.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ScriptBlock.java	11 Feb 2002 00:27:41 -0000	1.1
  +++ ScriptBlock.java	12 Feb 2002 21:34:34 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/ScriptBlock.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:41 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/ScriptBlock.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/12 21:34:34 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: ScriptBlock.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  + * $Id: ScriptBlock.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
    */
   package org.apache.commons.jelly.impl;
   
  @@ -72,7 +72,7 @@
   /** <p><code>ScriptBlock</code> a block of scripts.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
   public class ScriptBlock implements Script {
       
  @@ -107,13 +107,19 @@
       public Script[] getScripts() {
           return scripts;
       }
  +
  +    /** Allows direct modification of the List of scripts */
  +    public List getScriptList() {
  +        return list;
  +    }
       
       // Script interface
       //-------------------------------------------------------------------------                    
  -    public Script compile() throws Exception {        
  +    public Script compile() throws Exception {            
           int size = list.size();
           if ( size == 1 ) {
  -            return (Script) list.get(0);
  +            Script script = (Script) list.get(0);
  +            return script.compile();
           }
           scripts = new Script[ size ];
           list.toArray( scripts );
  
  
  
  1.2       +10 -22    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java
  
  Index: TagScript.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TagScript.java	11 Feb 2002 00:27:41 -0000	1.1
  +++ TagScript.java	12 Feb 2002 21:34:34 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:41 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/12 21:34:34 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - * $Id: TagScript.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  + * $Id: TagScript.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
    */
   package org.apache.commons.jelly.impl;
   
  @@ -85,7 +85,7 @@
   /** <p><code>TagScript</code> evaluates a custom tag.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
   public class TagScript implements Script {
       
  @@ -95,9 +95,6 @@
       /** the tag to be evaluated */
       private Tag tag;
   
  -    /** the body of the tag */
  -    private Script body;
  -
       /** The attribute expressions that are created */
       private Map attributes = new HashMap();
       
  @@ -118,7 +115,7 @@
       }
   
       public String toString() {
  -        return super.toString() + "[tag=" + tag + ", body=" + body + "]";
  +        return super.toString() + "[tag=" + tag + "]";
       }
       
       /** Add an initialization attribute for the tag.
  @@ -138,8 +135,6 @@
         * Will only be called once by the parser 
         */
       public Script compile() throws Exception {
  -        this.body = body.compile();
  -        
           List typeList = new ArrayList();
           List methodList = new ArrayList();
           List expressionList = new ArrayList();
  @@ -177,6 +172,9 @@
           expressionList.toArray( expressions );
           methodList.toArray( methods );
           typeList.toArray( types );
  +        
  +        // compile body
  +        tag.setBody( tag.getBody().compile() );        
           return this;
       }
       
  @@ -198,7 +196,7 @@
               Object[] arguments = { value };
               method.invoke( tag, arguments );
           }        
  -        tag.run( context, writer, body );
  +        tag.run( context, writer );
       }
       
       // Properties
  @@ -212,16 +210,6 @@
       /** Sets the tag to be evaluated */
       public void setTag(Tag tag) {
           this.tag = tag; 
  -    }
  -    
  -    /** @return the body of the tag */
  -    public Script getBody() {
  -        return body;
  -    }
  -    
  -    /** Sets the body of the tag */
  -    public void setBody(Script body) {
  -        this.body = body; 
       }
       
       // Implementation methods
  
  
  
  1.3       +91 -42    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java
  
  Index: XMLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XMLParser.java	11 Feb 2002 18:14:17 -0000	1.2
  +++ XMLParser.java	12 Feb 2002 21:34:34 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v 1.2 2002/02/11 18:14:17 jstrachan Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/02/11 18:14:17 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v 1.3 2002/02/12 21:34:34 jstrachan Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/12 21:34:34 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - * $Id: XMLParser.java,v 1.2 2002/02/11 18:14:17 jstrachan Exp $
  + * $Id: XMLParser.java,v 1.3 2002/02/12 21:34:34 jstrachan Exp $
    */
   package org.apache.commons.jelly.parser;
   
  @@ -91,6 +91,10 @@
   import org.apache.commons.jelly.impl.TextScript;
   import org.apache.commons.jelly.expression.ConstantExpression;
   import org.apache.commons.jelly.expression.Expression;
  +import org.apache.commons.jelly.expression.ExpressionFactory;
  +import org.apache.commons.jelly.expression.beanshell.BeanShellExpressionFactory;
  +import org.apache.commons.jelly.tags.core.CoreTagLibrary;
  +import org.apache.commons.jelly.tags.xml.XMLTagLibrary;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogSource;
  @@ -111,21 +115,27 @@
    * The SAXParser and XMLReader portions of this code come from Digester.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class XMLParser extends DefaultHandler {
       
  +    /** the expression factory used to evaluate tag attributes */
  +    private ExpressionFactory expressionFactory;
  +    
       /** The current script block */
       private ScriptBlock script;
       
  -    /** The current tag */
  -    private TagScript tag;
  +    /** The current tagScript */
  +    private TagScript tagScript;
  +
  +    /** The current parent tag */
  +    private Tag parentTag;
       
       /** The stack of body scripts. */
       private ArrayStack scriptStack = new ArrayStack();
       
  -    /** The stack of tags - use ArrayList as it allows null. */
  -    private ArrayList tagStack = new ArrayList();
  +    /** The stack of tagScripts - use ArrayList as it allows null. */
  +    private ArrayList tagScriptStack = new ArrayList();
       
       /** The current text buffer where non-custom tags get written */
       private StringBuffer textBuffer;
  @@ -133,9 +143,6 @@
       /** Tag libraries found so far */
       private Map taglibs = new HashMap();
       
  -    /** whether we are inside the root element or not */
  -    private boolean insideRoot = false;
  -    
       /**
        * The class loader to use for instantiating application objects.
        * If not specified, the context class loader, or the class loader
  @@ -186,7 +193,6 @@
       protected HashMap namespaces = new HashMap();
       
       
  -    
       /**
        * Do we want to use the Context ClassLoader when loading classes
        * for instantiating new objects?  Default is <code>false</code>.
  @@ -200,6 +206,9 @@
       protected boolean validating = false;
       
       
  +    /** Flag to indicate if this object has been configured */
  +    private boolean configured;
  +    
       /**
        * The Log to which most logging calls will be made.
        */
  @@ -237,7 +246,7 @@
       /** Registers the given tag library against the given namespace URI.
        * This should be called before the parser is used.
        */
  -    public void registerTaglib(String namespaceURI, TagLibrary taglib) {
  +    public void registerTagLibrary(String namespaceURI, TagLibrary taglib) {
           taglibs.put( namespaceURI, taglib );
       }
       
  @@ -251,6 +260,7 @@
        * @exception SAXException if a parsing exception occurs
        */
       public Script parse(File file) throws IOException, SAXException {
  +        ensureConfigured();
           getXMLReader().parse(new InputSource(new FileReader(file)));
           return script;
       }
  @@ -266,6 +276,7 @@
        * @exception SAXException if a parsing exception occurs
        */
       public Script parse(InputSource input) throws IOException, SAXException {
  +        ensureConfigured();
           getXMLReader().parse(input);
           return script;
           
  @@ -282,9 +293,9 @@
        * @exception SAXException if a parsing exception occurs
        */
       public Script parse(InputStream input) throws IOException, SAXException {
  +        ensureConfigured();
           getXMLReader().parse(new InputSource(input));
  -        return script;
  -        
  +        return script;        
       }
       
       
  @@ -298,6 +309,7 @@
        * @exception SAXException if a parsing exception occurs
        */
       public Script parse(Reader reader) throws IOException, SAXException {
  +        ensureConfigured();
           getXMLReader().parse(new InputSource(reader));
           return script;
           
  @@ -314,6 +326,7 @@
        * @exception SAXException if a parsing exception occurs
        */
       public Script parse(String uri) throws IOException, SAXException {
  +        ensureConfigured();
           getXMLReader().parse(uri);
           return script;
           
  @@ -412,6 +425,19 @@
       public void setLogger(Log log) {
           this.log = log;
       }
  +
  +    /** @return the expression factory used to evaluate tag attributes */
  +    public ExpressionFactory getExpressionFactory() {
  +        if ( expressionFactory == null ) {
  +            expressionFactory = createExpressionFactory();
  +        }
  +        return expressionFactory;
  +    }
  +    
  +    /** Sets the expression factory used to evaluate tag attributes */
  +    public void setExpressionFactory(ExpressionFactory expressionFactory) {
  +        this.expressionFactory = expressionFactory;
  +    }
       
       /**
        * Return the SAXParser we will use to parse the input stream.  If there
  @@ -532,7 +558,10 @@
       public void startDocument() throws SAXException {
           script = new ScriptBlock();
           textBuffer = new StringBuffer();
  -        insideRoot = false;
  +        tagScript = null;
  +        parentTag = null;
  +        scriptStack.clear();
  +        tagScriptStack.clear();
       }
       
       
  @@ -562,30 +591,28 @@
       String namespaceURI, String localName, String qName, Attributes list
       ) throws SAXException {
           
  -        // ignore the first element
  -        if ( ! insideRoot ) {
  -            insideRoot = true;
  -            tagStack.add( null );
  -            return;
  -        }
  -        
           // if this is a tag then create a script to run it
           // otherwise pass the text to the current body
  -        tag = createTag( namespaceURI, localName, list );
  -        tagStack.add( tag );
  +        tagScript = createTag( namespaceURI, localName, list );
  +        tagScriptStack.add( tagScript );
           
  -        if ( tag != null ) {
  +        if ( tagScript != null ) {            
  +            // set parent relationship...
  +            Tag tag = tagScript.getTag();
  +            tag.setParent( parentTag );
  +            parentTag = tag;
  +            
               if ( textBuffer.length() > 0 ) {
                   script.addScript( new TextScript( textBuffer.toString() ) );
                   textBuffer.setLength(0);
               }
               
  -            script.addScript( tag );
  +            script.addScript( tagScript );
               
               // start a new body
               scriptStack.push( script );
               script = new ScriptBlock();
  -            tag.setBody( script );
  +            tag.setBody( script );            
           }
           else {
               // XXXX: might wanna handle empty elements later...
  @@ -637,18 +664,13 @@
           String namespaceURI, String localName, String qName
       ) throws SAXException {        
           
  -        tag = (TagScript) tagStack.remove( tagStack.size() - 1 );
  -        if ( tag != null ) {
  +        tagScript = (TagScript) tagScriptStack.remove( tagScriptStack.size() - 1 );
  +        if ( tagScript != null ) {
               if ( textBuffer.length() > 0 ) {
                   script.addScript( new TextScript( textBuffer.toString() ) );
                   textBuffer.setLength(0);
               }
  -            if ( scriptStack.isEmpty() ) {
  -                script = (ScriptBlock) scriptStack.peek();
  -            }
  -            else {
  -                script = (ScriptBlock) scriptStack.pop();
  -            }
  +            script = (ScriptBlock) scriptStack.pop();
           }
           else {
               textBuffer.append( "</" );
  @@ -782,8 +804,9 @@
        * @param systemId The system identifier (if any)
        * @param notation The name of the associated notation
        */
  -    public void unparsedEntityDecl(String name, String publicId,
  -    String systemId, String notation) {
  +    public void unparsedEntityDecl(
  +        String name, String publicId, String systemId, String notation
  +    ) {
       }
       
       // ErrorHandler interface
  @@ -857,7 +880,27 @@
       
       // Implementation methods
       //-------------------------------------------------------------------------
  +
  +    /**
  +     * If this object has not been configured then register the default
  +     * namespaces
  +     */
  +    private void ensureConfigured() {
  +        if ( ! configured ) {
  +            configure();
  +            configured = false;
  +        }
  +    }
       
  +    /**
  +     * This method is called only once before parsing occurs
  +     * which allows tag libraries to be registered and so forth
  +     */
  +    protected void configure() {
  +        registerTagLibrary( "jelly:core", new CoreTagLibrary() );
  +        registerTagLibrary( "jelly:xml", new XMLTagLibrary() );
  +    }
  +        
       
       /**
        * Factory method to create new Tag script for the given namespaceURI and name or
  @@ -905,11 +948,17 @@
           }
       }
       
  -    protected Expression createExpression( String tagName, String attributeName, String attributeValue ) {
  -        // should use the default Expression library in context
  +    protected Expression createExpression( String tagName, String attributeName, String attributeValue ) throws Exception {
  +        Expression answer = getExpressionFactory().createExpression( attributeValue );
  +        if ( answer != null ) {
  +            return answer;
  +        }
           return new ConstantExpression( attributeValue );
       }
  -    
  +        
  +    protected ExpressionFactory createExpressionFactory() {
  +        return new BeanShellExpressionFactory();
  +    }
       
       
       /**
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java
  
  Index: CoreTagLibrary.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/12 21:34:34 $
   *
   * ====================================================================
   *
   * 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: CoreTagLibrary.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.core;
  
  import java.io.IOException;
  import java.io.Writer;
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.TagLibrary;
  import org.apache.commons.jelly.expression.Expression;
  
  
  /** Describes the Taglib. This class could be generated by XDoclet
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class CoreTagLibrary extends TagLibrary {
  
      public CoreTagLibrary() {
          registerTag( "expr", ExprTag.class );
          registerTag( "forEach", ForEachTag.class );
          registerTag( "jelly", JellyTag.class );
          registerTag( "set", SetTag.class );
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ExprTag.java
  
  Index: ExprTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ExprTag.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/12 21:34:34 $
   *
   * ====================================================================
   *
   * 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: ExprTag.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.core;
  
  import java.io.IOException;
  import java.io.Writer;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.expression.Expression;
  
  /** A tag which evaluates an expression
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class ExprTag extends TagSupport {
  
      /** The expression to evaluate. */
      private Expression value;        
  
      public ExprTag() {
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void run(Context context, Writer writer) throws IOException {
          if ( value != null ) {
              String text = value.evaluateAsString( context );
              if ( text != null ) {
                  writer.write( text );
              }
          }
      }
  
      // Properties
      //-------------------------------------------------------------------------                
      
      /** Sets the XPath expression to evaluate. */
      public void setValue(Expression value) {
          this.value = value;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ForEachTag.java
  
  Index: ForEachTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/ForEachTag.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/12 21:34:34 $
   *
   * ====================================================================
   *
   * 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: ForEachTag.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.core;
  
  import java.io.IOException;
  import java.io.Writer;
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.expression.Expression;
  
  
  /** A tag which performs an iteration over the results of an XPath expression
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class ForEachTag extends TagSupport {
  
      /** Holds the variable name to export for the item being iterated over. */
      private Expression items;
      /** 
       * If specified then the current item iterated through will be defined
       * as the given variable name. 
       */
      private String var;
      /** 
       * If specified then the current index counter will be defined
       * as the given variable name. 
       */
      private String indexVar;    
      /** The starting index value */
      private int begin;
      /** The ending index value */
      private int end = Integer.MAX_VALUE;
      /** The index increment step */
      private int step = 1;
      /** The iteration index */
      private int index;
      
      public ForEachTag() {
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void run(Context context, Writer writer) throws Exception {
          if ( items != null ) { 
              Iterator iter = items.evaluateAsIterator( context );
              for ( index = begin; iter.hasNext() && index < end; index += step ) {
                  Object value = iter.next();
                  if (var != null) {
                      context.setVariable( var, value );
                  }
                  if ( indexVar != null ) {
                      context.setVariable( indexVar, new Integer(index) );
                  }
                  getBody().run( context, writer );
              }
          }
      }
      
      // Properties
      //-------------------------------------------------------------------------                    
      
      /** Sets the expression used to iterate over
        */
      public void setItems(Expression items) {
          this.items = items;
      }
      
      /** Sets the variable name to export for the item being iterated over
       */
      public void setVar(String var) {
          this.var = var;
      }
      
      /** Sets the variable name to export the current index counter to 
       */
      public void setIndexVar(String indexVar) {
          this.indexVar = indexVar;
      }
      
      /** Sets the starting index value 
       */
      public void setBegin(int begin) {
          this.begin = begin;
      }
      
      /** Sets the ending index value 
       */
      public void setEnd(int end) {
          this.end = end;
      }
      
      /** Sets the index increment step 
       */
      public void setStep(int step) {
          this.step = step;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/JellyTag.java
  
  Index: JellyTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/JellyTag.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/12 21:34:34 $
   *
   * ====================================================================
   *
   * 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: JellyTag.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.core;
  
  import java.io.IOException;
  import java.io.Writer;
  import java.util.List;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.expression.Expression;
  import org.apache.commons.jelly.impl.ScriptBlock;
  import org.apache.commons.jelly.impl.TextScript;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogSource;
  
  
  /** The root Jelly tag which should be evaluated first
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class JellyTag extends TagSupport {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogSource.getInstance( JellyTag.class );
  
      /** whether whitespace should be trimmed or not. */
      private boolean trim = false;        
  
      /** Whether we've trimmed or not */
      private boolean hasTrimmed;
      
      public JellyTag() {
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void run(Context context, Writer writer) throws Exception {
          if ( trim && ! hasTrimmed ) {
              trimBody();
              hasTrimmed = true;
          }
          if ( log.isDebugEnabled() ) {
              log.debug( "Running body: " + getBody() );
          }
          getBody().run( context, writer );
      }
  
      // Properties
      //-------------------------------------------------------------------------                
      
      /** Sets whether whitespace should be trimmed or not. */
      public void setTrim(boolean trim) {
          this.trim = trim;
      }
      
      public void setBody(Script body) {
          super.setBody( body );
          hasTrimmed = false;
      }
      
      // Implementation methods
      //-------------------------------------------------------------------------                
      
      /** 
       * Find all text nodes inside the top level of this body and 
       * if they are just whitespace then remove them
       */
      protected void trimBody() throws Exception {
          Script body = getBody();
          if ( body instanceof ScriptBlock ) {
              ScriptBlock block = (ScriptBlock) body;
              List list = block.getScriptList();
              for ( int i = list.size() - 1; i >= 0; i-- ) {
                  Script script = (Script) list.get(i);
                  if ( script instanceof TextScript ) {
                      TextScript textScript = (TextScript) script;
                      String text = textScript.getText();
                      text = text.trim();
                      if ( text.length() == 0 ) {
                          list.remove(i);
                      }
                      else {
                          textScript.setText(text);
                      }
                  }
              }                
          }
      }
  }
      
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/SetTag.java
  
  Index: SetTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/SetTag.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/02/12 21:34:34 $
   *
   * ====================================================================
   *
   * 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: SetTag.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.core;
  
  import java.io.Writer;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.expression.Expression;
  
  /** A tag which sets a variable from the result of an expression 
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class SetTag extends TagSupport {
  
      /** The variable name to export. */
      private String var;
      /** The expression to evaluate. */
      private Expression value;        
  
      public SetTag() {
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void run(Context context, Writer writer) throws Exception {
          if ( var == null ) {
              throw new IllegalArgumentException( "The var attribute cannot be null" );
          }
          if ( value != null ) {
              Object answer = value.evaluate( context );
              context.setVariable( var, answer );
          }
          else {
              // must use body to get the value
              String text = getBodyText( context );
              context.setVariable( var, text );
          }
      }
  
      // Properties
      //-------------------------------------------------------------------------                
      
      /** Sets the variable name to define for this expression
       */
      public void setVar(String var) {
          this.var = var;
      }
      
      /** Sets the expression to evaluate. */
      public void setValue(Expression value) {
          this.value = value;
      }
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
  
    <p>The core Tags from the JSTL
    </p>
  </body>
  </html>
  
  
  
  1.2       +9 -9      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ExprTag.java
  
  Index: ExprTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ExprTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExprTag.java	11 Feb 2002 00:27:41 -0000	1.1
  +++ ExprTag.java	12 Feb 2002 21:34:34 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ExprTag.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:41 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ExprTag.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/12 21:34:34 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: ExprTag.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  + * $Id: ExprTag.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
    */
   package org.apache.commons.jelly.tags.xml;
   
  @@ -66,17 +66,17 @@
   
   import org.apache.commons.jelly.Context;
   import org.apache.commons.jelly.Script;
  -import org.apache.commons.jelly.Tag;
  +import org.apache.commons.jelly.TagSupport;
   
   import org.dom4j.XPath;
   
   /** A tag which performs a string XPath expression; similar to &lt;xsl:value-of&gt;
  -  * in XLST
  +  * in XSLT
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
  -public class ExprTag implements Tag {
  +public class ExprTag extends TagSupport {
   
       /** The XPath expression to evaluate. */
       private XPath select;        
  @@ -86,7 +86,7 @@
   
       // Tag interface
       //------------------------------------------------------------------------- 
  -    public void run(Context context, Writer writer, Script body) throws IOException {
  +    public void run(Context context, Writer writer) throws IOException {
           if ( select != null ) {
               String text = select.valueOf( null );
               writer.write( text );
  
  
  
  1.2       +9 -9      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ForEachTag.java
  
  Index: ForEachTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ForEachTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ForEachTag.java	11 Feb 2002 00:27:41 -0000	1.1
  +++ ForEachTag.java	12 Feb 2002 21:34:34 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ForEachTag.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:41 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ForEachTag.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/12 21:34:34 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: ForEachTag.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  + * $Id: ForEachTag.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
    */
   package org.apache.commons.jelly.tags.xml;
   
  @@ -68,7 +68,7 @@
   
   import org.apache.commons.jelly.Context;
   import org.apache.commons.jelly.Script;
  -import org.apache.commons.jelly.Tag;
  +import org.apache.commons.jelly.TagSupport;
   
   import org.dom4j.XPath;
   
  @@ -76,9 +76,9 @@
   /** A tag which performs an iteration over the results of an XPath expression
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
  -public class ForEachTag implements Tag {
  +public class ForEachTag extends TagSupport {
   
       /** Holds the XPath selector. */
       private XPath select;
  @@ -91,7 +91,7 @@
   
       // Tag interface
       //------------------------------------------------------------------------- 
  -    public void run(Context context, Writer writer, Script body) throws Exception {
  +    public void run(Context context, Writer writer) throws Exception {
           if ( select != null ) { 
               Iterator iter = select.selectNodes(null).iterator();
               while ( iter.hasNext() ) {
  @@ -99,7 +99,7 @@
                   if (var != null) {
                       context.setVariable( var, value );
                   }
  -                body.run( context, writer );
  +                getBody().run( context, writer );
               }
           }
       }
  
  
  
  1.2       +11 -13    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ParseTag.java
  
  Index: ParseTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ParseTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ParseTag.java	11 Feb 2002 00:27:41 -0000	1.1
  +++ ParseTag.java	12 Feb 2002 21:34:34 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ParseTag.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:41 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/ParseTag.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/12 21:34:34 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: ParseTag.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  + * $Id: ParseTag.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
    */
   package org.apache.commons.jelly.tags.xml;
   
  @@ -72,7 +72,7 @@
   
   import org.apache.commons.jelly.Context;
   import org.apache.commons.jelly.Script;
  -import org.apache.commons.jelly.Tag;
  +import org.apache.commons.jelly.TagSupport;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogSource;
  @@ -88,9 +88,9 @@
     * source property which can be a Reader, InputStream, URL or String URI.
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
  -public class ParseTag implements Tag {
  +public class ParseTag extends TagSupport {
   
       /** The Log to which logging calls will be made. */
       private static final Log log = LogSource.getInstance( ParseTag.class );
  @@ -112,21 +112,19 @@
   
       // Tag interface
       //------------------------------------------------------------------------- 
  -    public void run(Context context, Writer writer, Script body) throws Exception {
  +    public void run(Context context, Writer writer) throws Exception {
           if ( var == null ) {
               throw new IllegalArgumentException( "The var attribute cannot be null" );
           }
           Document document = null;
           if ( source == null ) {
               // parse body
  -            StringWriter buffer = new StringWriter();
  -            body.run( context, buffer );
  +            String text = getBodyText( context );
               
               if ( log.isDebugEnabled() ) {
  -                log.debug( "Evaluated body: " + body );
  -                log.debug( "About to parse: " + buffer.toString() );
  +                log.debug( "About to parse: " + text );
               }
  -            document = getSAXReader().read( new StringReader( buffer.toString() ) );
  +            document = getSAXReader().read( new StringReader( text ) );
           }
           else {
               if ( source instanceof String ) {
  
  
  
  1.2       +8 -8      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/SetTag.java
  
  Index: SetTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/SetTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SetTag.java	11 Feb 2002 00:27:41 -0000	1.1
  +++ SetTag.java	12 Feb 2002 21:34:34 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/SetTag.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:41 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/SetTag.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/12 21:34:34 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: SetTag.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  + * $Id: SetTag.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
    */
   package org.apache.commons.jelly.tags.xml;
   
  @@ -65,16 +65,16 @@
   
   import org.apache.commons.jelly.Context;
   import org.apache.commons.jelly.Script;
  -import org.apache.commons.jelly.Tag;
  +import org.apache.commons.jelly.TagSupport;
   
   import org.dom4j.XPath;
   
   /** A tag which defines a variable from an XPath expression 
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
  -public class SetTag implements Tag {
  +public class SetTag extends TagSupport {
   
       /** The variable name to export. */
       private String var;
  @@ -86,7 +86,7 @@
   
       // Tag interface
       //------------------------------------------------------------------------- 
  -    public void run(Context context, Writer writer, Script body) {
  +    public void run(Context context, Writer writer) {
           if ( var == null ) {
               throw new IllegalArgumentException( "The var attribute cannot be null" );
           }
  
  
  
  1.2       +7 -7      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XPathExpression.java
  
  Index: XPathExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XPathExpression.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XPathExpression.java	11 Feb 2002 00:27:41 -0000	1.1
  +++ XPathExpression.java	12 Feb 2002 21:34:34 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XPathExpression.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:41 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XPathExpression.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/12 21:34:34 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: XPathExpression.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  + * $Id: XPathExpression.java,v 1.2 2002/02/12 21:34:34 jstrachan Exp $
    */
   package org.apache.commons.jelly.tags.xml;
   
  @@ -67,7 +67,7 @@
   import org.apache.commons.jelly.Context;
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.Tag;
  -import org.apache.commons.jelly.expression.Expression;
  +import org.apache.commons.jelly.expression.ExpressionSupport;
   
   import org.dom4j.DocumentFactory;
   import org.dom4j.XPath;
  @@ -76,9 +76,9 @@
   /** An expression which returns an XPath object.
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
  -public class XPathExpression implements Expression, VariableContext {
  +public class XPathExpression extends ExpressionSupport implements VariableContext {
   
       private XPath xpath;        
       private Context context;
  
  
  
  1.2       +7 -17     jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestXMLTags.java
  
  Index: TestXMLTags.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestXMLTags.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestXMLTags.java	11 Feb 2002 00:27:41 -0000	1.1
  +++ TestXMLTags.java	12 Feb 2002 21:34:35 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestXMLTags.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:41 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestXMLTags.java,v 1.2 2002/02/12 21:34:35 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/12 21:34:35 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: TestXMLTags.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  + * $Id: TestXMLTags.java,v 1.2 2002/02/12 21:34:35 jstrachan Exp $
    */
   package org.apache.commons.jelly;
   
  @@ -72,7 +72,7 @@
   
   import org.apache.commons.jelly.Context;
   import org.apache.commons.jelly.Script;
  -import org.apache.commons.jelly.impl.ScriptBlock;
  +import org.apache.commons.jelly.impl.TagScript;
   import org.apache.commons.jelly.parser.XMLParser;
   
   import org.apache.commons.logging.Log;
  @@ -82,7 +82,7 @@
   /** Tests the parser, the engine and the XML tags
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
   public class TestXMLTags extends TestCase {
       
  @@ -107,19 +107,9 @@
           Script script = parser.parse( in );
           script = script.compile();
   
  -        assertTrue( "Script is a ScriptBlock", script instanceof ScriptBlock );
  +        log.debug( "Found: " + script );
           
  -        ScriptBlock block = (ScriptBlock) script;
  -        Script[] scripts = block.getScripts();
  -        
  -        assertTrue( "block contains child scripts", scripts.length != 0 );
  -
  -        if ( log.isDebugEnabled() ) {
  -            for ( int i = 0, size = scripts.length; i < size; i++ ) {
  -                Script s = scripts[i];
  -                log.debug( "Found script: " + i + " = " + s );
  -            }
  -        }
  +        assertTrue( "Script is a TagScript", script instanceof TagScript );
           
           Context context = new Context();        
           StringWriter buffer = new StringWriter();
  
  
  
  1.2       +1 -4      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example.jelly
  
  Index: example.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- example.jelly	11 Feb 2002 00:27:41 -0000	1.1
  +++ example.jelly	12 Feb 2002 21:34:35 -0000	1.2
  @@ -1,9 +1,6 @@
   <?xml version="1.0"?>
   
  -<j:jelly 
  -  xmlns:j="http://jakarta.apache.org/commons/jelly/1.0"
  -  xmlns:x="jelly:org.apache.commons.jelly.tags.xml.XMLTagLibrary"
  ->
  +<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml">
     <x:parse var="doc">
       <html>
         <title>It works!</title>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example2.jelly
  
  Index: example2.jelly
  ===================================================================
  <?xml version="1.0"?>
  
  <j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml">
    <x:parse var="doc">
      <web-app>
        <servlet>
          <servlet-name>snoop</servlet-name>
          <servlet-class>SnoopServlet</servlet-class>
        </servlet>
        <servlet>
          <servlet-name>file</servlet-name>
          <servlet-class>ViewFile</servlet-class>
          <init-param>
            <param-name>initial</param-name>
            <param-value>1000</param-value>
            <description>
              The initial value for the counter  <!-- optional -->
            </description>
          </init-param>
        </servlet>
        <servlet-mapping>
          <servlet-name>snoop</servlet-name>
          <url-pattern>/foo/snoop</url-pattern>
        </servlet-mapping>
      </web-app>
    </x:parse>
    <x:set var="count" select="count($doc//servlet)"/>
    <x:forEach var="s" select="$doc//servlet">
      name: <x:expr select="$s/servlet-name"/>
      class: <x:expr select="$s/servlet-class"/>
    </x:forEach>
    There are <x:expr select="$count"/> servlet(s)
  </j:jelly>
  
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/hello_world.jelly
  
  Index: hello_world.jelly
  ===================================================================
  <?xml version="1.0"?>
  <j:jelly xmlns:j="jelly:core">
    Hello World!
  </j:jelly>
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>