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/04/25 20:58:48 UTC

cvs commit: jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/define TestDynamicTags.java example.jelly

jstrachan    02/04/25 11:58:48

  Modified:    jelly    build.xml
               jelly/src/java/org/apache/commons/jelly Context.java
                        Jelly.java XMLOutput.java jelly.properties
               jelly/src/java/org/apache/commons/jelly/parser
                        XMLParser.java
               jelly/src/java/org/apache/commons/jelly/tags/define
                        DefineTagLibTag.java DynamicTag.java
                        InvokeBodyTag.java
               jelly/src/test/org/apache/commons/jelly TestAll.java
               jelly/src/test/org/apache/commons/jelly/define example.jelly
  Added:       jelly/src/test/org/apache/commons/jelly/define
                        TestDynamicTags.java
  Log:
  Dynamic tags are just about working now. Need to support DynaTag in the tag invocation mechanism and need to figure out a neat way to implement the InvokeBodyTag, to associate the tag with the correct dynamic tags instance. Other than that just about there
  
  Revision  Changes    Path
  1.12      +11 -2     jakarta-commons-sandbox/jelly/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/build.xml,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- build.xml	24 Apr 2002 13:03:03 -0000	1.11
  +++ build.xml	25 Apr 2002 18:58:47 -0000	1.12
  @@ -3,7 +3,7 @@
   
   <!--
           "Jelly" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.11 2002/04/24 13:03:03 jstrachan Exp $
  +        $Id: build.xml,v 1.12 2002/04/25 18:58:47 jstrachan Exp $
   -->
   
   
  @@ -332,8 +332,17 @@
         description="Runs the test of the XML tags">
       <java classname="org.apache.commons.jelly.TestXMLTags" fork="yes">
         <classpath refid="test.classpath"/>
  -      <sysproperty key="org.apache.commons.logging.log" value="org.apache.commons.logging.impl.SimpleLog"/>
         <sysproperty key="org.apache.commons.logging.simplelog.defaultlog" value="debug"/>
  +    </java>
  +   </target>
  +
  +   <target name="test.define" depends="compile.tests" 
  +      description="Runs the test of the define tags to test dynamic tags">
  +    <java classname="org.apache.commons.jelly.define.TestDynamicTags" fork="yes">
  +      <classpath refid="test.classpath"/>
  +      <!--
  +      <sysproperty key="org.apache.commons.logging.simplelog.defaultlog" value="debug"/>
  +      -->
       </java>
      </target>
   
  
  
  
  1.8       +61 -6     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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Context.java	25 Apr 2002 18:14:09 -0000	1.7
  +++ Context.java	25 Apr 2002 18:58:47 -0000	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java,v 1.7 2002/04/25 18:14:09 jstrachan Exp $
  - * $Revision: 1.7 $
  - * $Date: 2002/04/25 18:14:09 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java,v 1.8 2002/04/25 18:58:47 jstrachan Exp $
  + * $Revision: 1.8 $
  + * $Date: 2002/04/25 18:58:47 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: Context.java,v 1.7 2002/04/25 18:14:09 jstrachan Exp $
  + * $Id: Context.java,v 1.8 2002/04/25 18:58:47 jstrachan Exp $
    */
   package org.apache.commons.jelly;
   
  @@ -65,16 +65,26 @@
   import java.util.Iterator;
   import java.util.Map;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +
  +
   /** <p><code>Context</code> represents the Jelly context.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.7 $
  +  * @version $Revision: 1.8 $
     */
   public class Context {
   
  +    /** Tag libraries found so far */
  +    private Map taglibs = new Hashtable();
  +    
       /** synchronized access to the variables in scope */
       private Map variables = new Hashtable();
   
  +    /** The Log to which logging calls will be made. */
  +    private Log log = LogFactory.getLog( Context.class );
  +
       public Context() {
       }
       
  @@ -135,6 +145,51 @@
           // XXXX: Or at least publish the parent scope
           // XXXX: as a Map in this new variable scope?
           newVariables.put( "parentScope", variables );
  -        return new Context( newVariables );
  +        Context answer = new Context( newVariables );
  +        answer.taglibs = this.taglibs;
  +        return answer;
  +    }
  +    
  +    
  +    /** Registers the given tag library against the given namespace URI.
  +     * This should be called before the parser is used.
  +     */
  +    public void registerTagLibrary(String namespaceURI, TagLibrary taglib) {
  +        log.info( "Registering tag library to: " + namespaceURI + " taglib: " + taglib );
  +        
  +        taglibs.put( namespaceURI, taglib );
  +    }
  +    
  +    /** Registers the given tag library class name against the given namespace URI.
  +     * The class will be loaded via the given ClassLoader
  +     * This should be called before the parser is used.
  +     */
  +    public void registerTagLibrary(String namespaceURI, String className, ClassLoader classLoader) {
  +        try {
  +            Class theClass = classLoader.loadClass( className );
  +            Object object = theClass.newInstance();
  +            if ( object instanceof TagLibrary ) {
  +                registerTagLibrary( namespaceURI, (TagLibrary) object );
  +            }
  +            else {
  +                log.error( 
  +                    "The tag library object mapped to: " 
  +                    + namespaceURI + " is not a TagLibrary. Object = " + object 
  +                );
  +            }
  +        }
  +        catch (ClassNotFoundException e) {
  +            log.error( "Could not find the class: " + className, e );
  +        }
  +        catch (Exception e) {
  +            log.error( "Could not instantiate instance of class: " + className + ". Reason: " + e, e );
  +        }
  +    }
  +    
  +    /** 
  +     * @return the TagLibrary for the given namespace URI or null if one could not be found
  +     */
  +    public TagLibrary getTagLibrary(String namespaceURI) {
  +        return (TagLibrary) taglibs.get( namespaceURI );
       }
   }
  
  
  
  1.5       +12 -11    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Jelly.java
  
  Index: Jelly.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Jelly.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Jelly.java	24 Apr 2002 11:59:12 -0000	1.4
  +++ Jelly.java	25 Apr 2002 18:58:47 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Jelly.java,v 1.4 2002/04/24 11:59:12 jstrachan Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/04/24 11:59:12 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Jelly.java,v 1.5 2002/04/25 18:58:47 jstrachan Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/04/25 18:58:47 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: Jelly.java,v 1.4 2002/04/24 11:59:12 jstrachan Exp $
  + * $Id: Jelly.java,v 1.5 2002/04/25 18:58:47 jstrachan Exp $
    */
   package org.apache.commons.jelly;
   
  @@ -74,7 +74,7 @@
   /** <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.4 $
  +  * @version $Revision: 1.5 $
     */
   public class Jelly {
   
  @@ -103,7 +103,13 @@
               new OutputStreamWriter( System.out )
           );
           
  +        // add the system properties and the command line arguments
  +        //Context context = new Context( System.getProperties() );
  +        Context context = new Context();
  +        context.setVariable( "args", args );
  +        
           XMLParser parser = new XMLParser();
  +        parser.setContext( context );
           Script script = parser.parse( input );
       
           script = script.compile();
  @@ -112,12 +118,7 @@
               log.debug( "Compiled script: " + script );
           }
           
  -        // add the system properties and the command line arguments
  -        //Context context = new Context( System.getProperties() );
  -        Context context = new Context();
  -        context.setVariable( "args", args );
  -        
  -        XMLOutput output= XMLOutput.createXMLOutput( writer );
  +        XMLOutput output = XMLOutput.createXMLOutput( writer );
           
           script.run( context, output );
           
  
  
  
  1.2       +7 -5      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/XMLOutput.java
  
  Index: XMLOutput.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/XMLOutput.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLOutput.java	24 Apr 2002 11:59:12 -0000	1.1
  +++ XMLOutput.java	25 Apr 2002 18:58:47 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/XMLOutput.java,v 1.1 2002/04/24 11:59:12 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/04/24 11:59:12 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/XMLOutput.java,v 1.2 2002/04/25 18:58:47 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/04/25 18:58:47 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: XMLOutput.java,v 1.1 2002/04/24 11:59:12 jstrachan Exp $
  + * $Id: XMLOutput.java,v 1.2 2002/04/25 18:58:47 jstrachan Exp $
    */
   package org.apache.commons.jelly;
   
  @@ -80,7 +80,7 @@
     * such as in the <a href="http://xml.apache.org/cocoon/">Cocoon</a> project.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
   public class XMLOutput implements ContentHandler, LexicalHandler {
   
  @@ -155,6 +155,8 @@
           return new XMLOutput( xmlWriter );
       }
       
  +    
  +        
       // Extra helper methods provided for tag authors
       //-------------------------------------------------------------------------                    
       
  
  
  
  1.4       +4 -1      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/jelly.properties
  
  Index: jelly.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/jelly.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- jelly.properties	25 Apr 2002 16:35:55 -0000	1.3
  +++ jelly.properties	25 Apr 2002 18:58:47 -0000	1.4
  @@ -1,8 +1,11 @@
   # register the default tag libraries with an abbreviated name
   core        = org.apache.commons.jelly.tags.core.CoreTagLibrary
  +define      = org.apache.commons.jelly.tags.define.DefineTagLibrary
  +xml         = org.apache.commons.jelly.tags.xml.XMLTagLibrary
  +
  +# optional taglibs
   beanshell   = org.apache.commons.jelly.tags.beanshell.BeanShellTagLibrary
   bsf         = org.apache.commons.jelly.tags.bsf.BSFTagLibrary
   javascript  = org.apache.commons.jelly.tags.bsf.JavaScriptTagLibrary
   jpython     = org.apache.commons.jelly.tags.bsf.JPythonTagLibrary
   pnuts       = org.apache.commons.jelly.tags.bsf.PNutsTagLibrary
  -xml         = org.apache.commons.jelly.tags.xml.XMLTagLibrary
  
  
  
  1.11      +27 -46    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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- XMLParser.java	25 Apr 2002 16:47:07 -0000	1.10
  +++ XMLParser.java	25 Apr 2002 18:58:47 -0000	1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v 1.10 2002/04/25 16:47:07 jstrachan Exp $
  - * $Revision: 1.10 $
  - * $Date: 2002/04/25 16:47:07 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v 1.11 2002/04/25 18:58:47 jstrachan Exp $
  + * $Revision: 1.11 $
  + * $Date: 2002/04/25 18:58:47 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - * $Id: XMLParser.java,v 1.10 2002/04/25 16:47:07 jstrachan Exp $
  + * $Id: XMLParser.java,v 1.11 2002/04/25 18:58:47 jstrachan Exp $
    */
   package org.apache.commons.jelly.parser;
   
  @@ -117,9 +117,12 @@
    * 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.10 $
  + * @version $Revision: 1.11 $
    */
   public class XMLParser extends DefaultHandler {
  +
  +    /** Context which is used to locate tag libraries*/
  +    private Context context = new Context();
       
       /** the expression factory used to evaluate tag attributes */
       private ExpressionFactory expressionFactory;
  @@ -142,9 +145,6 @@
       /** The current text buffer where non-custom tags get written */
       private StringBuffer textBuffer;
       
  -    /** Tag libraries found so far */
  -    private Map taglibs = new HashMap();
  -    
       /**
        * The class loader to use for instantiating application objects.
        * If not specified, the context class loader, or the class loader
  @@ -212,9 +212,9 @@
       private boolean configured;
       
       /**
  -     * The Log to which most logging calls will be made.
  +     * The Log to which logging calls will be made.
        */
  -    private Log log = LogFactory.getLog("org.apache.commons.digester.XMLParser");
  +    private Log log = LogFactory.getLog( XMLParser.class );
       
       
       /**
  @@ -245,40 +245,7 @@
           this.reader = reader;
       }
   
  -    /** Registers the given tag library against the given namespace URI.
  -     * This should be called before the parser is used.
  -     */
  -    public void registerTagLibrary(String namespaceURI, TagLibrary taglib) {
  -        taglibs.put( namespaceURI, taglib );
  -    }
  -    
   
  -    /** Registers the given tag library class name against the given namespace URI.
  -     * The class will be loaded via the getClassLoader().
  -     * This should be called before the parser is used.
  -     */
  -    public void registerTagLibrary(String namespaceURI, String className) {
  -        try {
  -            Class theClass = getClassLoader().loadClass( className );
  -            Object object = theClass.newInstance();
  -            if ( object instanceof TagLibrary ) {
  -                registerTagLibrary( namespaceURI, (TagLibrary) object );
  -            }
  -            else {
  -                log.error( 
  -                    "The tag library object mapped to: " 
  -                    + namespaceURI + " is not a TagLibrary. Object = " + object 
  -                );
  -            }
  -        }
  -        catch (ClassNotFoundException e) {
  -            log.error( "Could not find the class: " + className, e );
  -        }
  -        catch (Exception e) {
  -            log.error( "Could not instantiate instance of class: " + className + ". Reason: " + e, e );
  -        }
  -    }
  -    
       /**
        * Parse the content of the specified file using this XMLParser.  Returns
        * the root element from the object stack (if any).
  @@ -383,7 +350,19 @@
           }
       }
       
  +
  +    
  +    // Properties
  +    //-------------------------------------------------------------------------                    
  +    
  +    public Context getContext() {
  +        return context;
  +    }
       
  +    public void setContext(Context context) {
  +        this.context = context;
  +    }
  +        
       /**
        * Return the class loader to be used for instantiating application objects
        * when required.  This is determined based upon the following rules:
  @@ -921,7 +900,7 @@
       private void ensureConfigured() {
           if ( ! configured ) {
               configure();
  -            configured = false;
  +            configured = true;
           }
       }
       
  @@ -944,7 +923,7 @@
                       Map.Entry entry = (Map.Entry) iter.next();
                       String uri = (String) entry.getKey();
                       String className = (String) entry.getValue();
  -                    registerTagLibrary( "jelly:" + uri, className );
  +                    context.registerTagLibrary( "jelly:" + uri, className, getClassLoader() );
                   }
               }
               catch (IOException e) {
  @@ -969,7 +948,7 @@
       protected TagScript createTag( String namespaceURI, String localName, Attributes list ) throws SAXException {
           try {
               // use the URI to load a taglib
  -            TagLibrary taglib = (TagLibrary) taglibs.get( namespaceURI );
  +            TagLibrary taglib = context.getTagLibrary( namespaceURI );
               if ( taglib == null ) {
                   if ( namespaceURI != null && namespaceURI.startsWith( "jelly:" ) ) {
                       String uri = namespaceURI.substring(6);
  @@ -977,6 +956,8 @@
                       try {
                           Class taglibClass = getClassLoader().loadClass( uri );
                           taglib = (TagLibrary) taglibClass.newInstance();
  +                        
  +                        context.registerTagLibrary( namespaceURI, taglib );
                       }
                       catch (ClassNotFoundException e) {
                           log.warn( "Could not load class: " + uri + " so disabling the taglib" );
  
  
  
  1.2       +5 -3      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagLibTag.java
  
  Index: DefineTagLibTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagLibTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefineTagLibTag.java	25 Apr 2002 18:14:09 -0000	1.1
  +++ DefineTagLibTag.java	25 Apr 2002 18:58:47 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagLibTag.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/04/25 18:14:09 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagLibTag.java,v 1.2 2002/04/25 18:58:47 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/04/25 18:58:47 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: DefineTagLibTag.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
  + * $Id: DefineTagLibTag.java,v 1.2 2002/04/25 18:58:47 jstrachan Exp $
    */
   package org.apache.commons.jelly.tags.define;
   
  @@ -75,7 +75,7 @@
    * using a Jelly script..</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class DefineTagLibTag extends TagSupport {
       
  @@ -95,6 +95,8 @@
       //-------------------------------------------------------------------------                    
       public void run(Context context, XMLOutput output) throws Exception {
           tagLibrary = new DynamicTagLibrary( getUri() );
  +
  +        context.registerTagLibrary( getUri(), tagLibrary );
           
           getBody().run(context, output);
   
  
  
  
  1.2       +12 -3     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTag.java
  
  Index: DynamicTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DynamicTag.java	25 Apr 2002 18:14:09 -0000	1.1
  +++ DynamicTag.java	25 Apr 2002 18:58:47 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTag.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/04/25 18:14:09 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTag.java,v 1.2 2002/04/25 18:58:47 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/04/25 18:58:47 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: DynamicTag.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
  + * $Id: DynamicTag.java,v 1.2 2002/04/25 18:58:47 jstrachan Exp $
    */
   package org.apache.commons.jelly.tags.define;
   
  @@ -70,6 +70,10 @@
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +
  +
   /** 
    * <p><code>DynamicTag</code> is a tag that is created from
    * inside a Jelly script as a Jelly template and will invoke a 
  @@ -77,9 +81,12 @@
    * as variables and will allow the template to invoke its instance body.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class DynamicTag extends TagSupport implements DynaTag {
  +
  +    /** The Log to which logging calls will be made. */
  +    private static final Log log = LogFactory.getLog( DynamicTag.class );
       
       /** The template script */
       private Script template;
  @@ -98,6 +105,8 @@
       //-------------------------------------------------------------------------                    
       public void run(Context context, XMLOutput output) throws Exception {
   
  +        log.info( "Invoking dynamic tag with attributes: " + attributes );
  +        
           // create new context based on current attributes
           Context newContext = context.newContext( attributes );
           
  
  
  
  1.2       +17 -6     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/InvokeBodyTag.java
  
  Index: InvokeBodyTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/InvokeBodyTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- InvokeBodyTag.java	25 Apr 2002 18:14:09 -0000	1.1
  +++ InvokeBodyTag.java	25 Apr 2002 18:58:47 -0000	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/InvokeBodyTag.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/04/25 18:14:09 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/InvokeBodyTag.java,v 1.2 2002/04/25 18:58:47 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/04/25 18:58:47 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: InvokeBodyTag.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
  + * $Id: InvokeBodyTag.java,v 1.2 2002/04/25 18:58:47 jstrachan Exp $
    */
   package org.apache.commons.jelly.tags.define;
   
  @@ -67,16 +67,24 @@
   import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +
  +
   /** 
    * <p><code>InvokeBodyTag</code> this tag needs to find
    * the correct parent DynamicTag instance and call its
    * body.</p>
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class InvokeBodyTag extends TagSupport {
  -    
  +
  +    /** The Log to which logging calls will be made. */
  +    private static final Log log = LogFactory.getLog( Context.class );
  +
  +
       public InvokeBodyTag() {
       }
       
  @@ -88,8 +96,11 @@
           // #### nested dynamic tags. A better way is required.
           Tag tag = findAncestorWithClass(this, DynamicTag.class);
           if ( tag == null ) {
  -            throw new JellyException( "Cannot invoke body, no dynamic tag is defined in this block" );
  +            // throw new JellyException( "Cannot invoke body, no dynamic tag is defined in this block" );
  +            log.warn( "Cannot invoke body, no dynamic tag is defined in this block" );
  +        }
  +        else {
  +            tag.getBody().run(context, output);
           }
  -        tag.getBody().run(context, output);
       }    
   }
  
  
  
  1.3       +7 -5      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestAll.java
  
  Index: TestAll.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestAll.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestAll.java	13 Feb 2002 16:00:39 -0000	1.2
  +++ TestAll.java	25 Apr 2002 18:58:47 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestAll.java,v 1.2 2002/02/13 16:00:39 jstrachan Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/02/13 16:00:39 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/TestAll.java,v 1.3 2002/04/25 18:58:47 jstrachan Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/04/25 18:58:47 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: TestAll.java,v 1.2 2002/02/13 16:00:39 jstrachan Exp $
  + * $Id: TestAll.java,v 1.3 2002/04/25 18:58:47 jstrachan Exp $
    */
   package org.apache.commons.jelly;
   
  @@ -67,11 +67,12 @@
   import junit.textui.TestRunner;
   
   import org.apache.commons.jelly.beanshell.TestBeanShellEL;
  +import org.apache.commons.jelly.define.TestDynamicTags;
   
   /** Entry point for all JUnit tests.
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.2 $
  +  * @version $Revision: 1.3 $
    */
   public class TestAll extends TestCase {
       
  @@ -84,6 +85,7 @@
           suite.addTest(TestXMLTags.suite());
           suite.addTest(TestCoreTags.suite());
           suite.addTest(TestBeanShellEL.suite());
  +        suite.addTest(TestDynamicTags.suite());
           return suite;
       }
       
  
  
  
  1.2       +5 -0      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/define/example.jelly
  
  Index: example.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/define/example.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- example.jelly	25 Apr 2002 18:14:09 -0000	1.1
  +++ example.jelly	25 Apr 2002 18:58:47 -0000	1.2
  @@ -3,7 +3,12 @@
   <!-- uses the babelfish taglib -->
   
   <j:jelly xmlns:j="jelly:core" xmlns:babelfish="jelly:babelfish">
  +  This example should output a web service call...
  +  
     <babelfish:translate from="EN" to="FR">
       Jelly is cool stuff!
     </babelfish:translate>
  +  
  +  ... OK did that work?
  +  
   </j:jelly>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/define/TestDynamicTags.java
  
  Index: TestDynamicTags.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/define/TestDynamicTags.java,v 1.1 2002/04/25 18:58:47 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/04/25 18:58:47 $
   *
   * ====================================================================
   *
   * 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: TestDynamicTags.java,v 1.1 2002/04/25 18:58:47 jstrachan Exp $
   */
  package org.apache.commons.jelly.define;
  
  import java.io.BufferedWriter;
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.OutputStreamWriter;
  import java.io.StringWriter;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.impl.TagScript;
  import org.apache.commons.jelly.parser.XMLParser;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  
  /** Tests dynamic tags
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class TestDynamicTags extends TestCase {
      
      XMLParser parser = new XMLParser();        
      XMLOutput output;
      
      StringWriter buffer = new StringWriter();
      
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog( TestDynamicTags.class );
  
      public static void main( String[] args ) {
          TestRunner.run( suite() );
      }
      
      public static Test suite() {
          return new TestSuite(TestDynamicTags.class);
      }
      
      public TestDynamicTags(String testName) {
          super(testName);
      }
      
      public void testParse() throws Exception {
          
          
          output = XMLOutput.createXMLOutput( buffer );
      
          runScript( "babelfishTaglib.jelly" );
          runScript( "example.jelly" );
          
          log.info( "The output was as follows" );
          log.info( buffer.toString() );
      }
      
      protected void runScript(String name) throws Exception {
          
          InputStream in = getClass().getResourceAsStream( name );
          
          Script script = parser.parse( in );
          script = script.compile();
  
          log.info( "Evaluating: " + script );        
          script.run( parser.getContext(), output );
      }    
  }
  
  
  
  

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