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:14:09 UTC

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

jstrachan    02/04/25 11:14:09

  Modified:    jelly/src/java/org/apache/commons/jelly Context.java
                        TagSupport.java
  Added:       jelly/src/java/org/apache/commons/jelly JellyException.java
               jelly/src/java/org/apache/commons/jelly/tags/define
                        DefineTagLibTag.java DefineTagLibrary.java
                        DefineTagTag.java DynamicTag.java
                        DynamicTagLibrary.java InvokeBodyTag.java
                        package.html
               jelly/src/test/org/apache/commons/jelly/define
                        babelfishTaglib.jelly example.jelly
  Log:
  Added the 'define' tag library which allows new tags to be defined at runtime, allowing dynamic tags to be created as well as using Jelly scripts to write macro or template definitions. This isn't tested yet but most of the code is just about there.
  
  Revision  Changes    Path
  1.7       +19 -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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Context.java	24 Apr 2002 13:03:03 -0000	1.6
  +++ Context.java	25 Apr 2002 18:14:09 -0000	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java,v 1.6 2002/04/24 13:03:03 jstrachan Exp $
  - * $Revision: 1.6 $
  - * $Date: 2002/04/24 13:03:03 $
  + * $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 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: Context.java,v 1.6 2002/04/24 13:03:03 jstrachan Exp $
  + * $Id: Context.java,v 1.7 2002/04/25 18:14:09 jstrachan Exp $
    */
   package org.apache.commons.jelly;
   
  @@ -68,7 +68,7 @@
   /** <p><code>Context</code> represents the Jelly context.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.6 $
  +  * @version $Revision: 1.7 $
     */
   public class Context {
   
  @@ -122,5 +122,19 @@
        */
       public void setVariables(Map variables) {
           this.variables = variables;
  +    }
  +    
  +    
  +    /**
  +     * A factory method to create a new child context of the
  +     * current context.
  +     */
  +    public Context newContext(Map newVariables) {
  +        // XXXX: should allow this new context to
  +        // XXXX: inherit parent contexts? 
  +        // 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 );
       }
   }
  
  
  
  1.3       +11 -5     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagSupport.java
  
  Index: TagSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagSupport.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TagSupport.java	24 Apr 2002 11:59:12 -0000	1.2
  +++ TagSupport.java	25 Apr 2002 18:14:09 -0000	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagSupport.java,v 1.2 2002/04/24 11:59:12 jstrachan Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/04/24 11:59:12 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagSupport.java,v 1.3 2002/04/25 18:14:09 jstrachan Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/04/25 18:14:09 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: TagSupport.java,v 1.2 2002/04/24 11:59:12 jstrachan Exp $
  + * $Id: TagSupport.java,v 1.3 2002/04/25 18:14:09 jstrachan Exp $
    */
   package org.apache.commons.jelly;
   
  @@ -68,7 +68,7 @@
     * inherit from if developing your own tag.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.2 $
  +  * @version $Revision: 1.3 $
     */
   public abstract class TagSupport implements Tag {
   
  @@ -115,6 +115,12 @@
       public void setBody(Script body) {
           this.body = body; 
       }
  +    
  +    /** By default just evaluate the body */
  +    public void run(Context context, XMLOutput output) throws Exception {
  +        getBody().run(context, output);
  +    }    
  +    
       
       // Implementation methods
       //-------------------------------------------------------------------------                
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyException.java
  
  Index: JellyException.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyException.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/04/25 18:14:09 $
   *
   * ====================================================================
   *
   * 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: JellyException.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
   */
  package org.apache.commons.jelly;
  
  /** 
   * <p><code>JellyException</code> is the root of all Jelly exceptions.</p>
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class JellyException extends Exception {
  
      public JellyException() {
      }
  
      public JellyException(String message) {
          super(message);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagLibTag.java
  
  Index: DefineTagLibTag.java
  ===================================================================
  /*
   * $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 $
   *
   * ====================================================================
   *
   * 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: DefineTagLibTag.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.define;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.DynaTag;
  import org.apache.commons.jelly.TagLibrary;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  import org.xml.sax.Attributes;
  import org.xml.sax.helpers.AttributesImpl;
  
  /** 
   * <p><code>DefineTag</code> is used to define a new taglib
   * using a Jelly script..</p>
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class DefineTagLibTag extends TagSupport {
      
      /** The namespace URI */
      private String uri;
      /** The new tags being added */
      private DynamicTagLibrary tagLibrary;
      
      public DefineTagLibTag() {
      }
      
      public DefineTagLibTag(String uri) {
          this.uri = uri;
      }
      
      // Tag interface
      //-------------------------------------------------------------------------                    
      public void run(Context context, XMLOutput output) throws Exception {
          tagLibrary = new DynamicTagLibrary( getUri() );
          
          getBody().run(context, output);
  
          tagLibrary = null;
      }    
      
      // Properties
      //-------------------------------------------------------------------------                    
      public String getUri() {
          return uri;
      }
      
      public void setUri(String uri) {
          this.uri = uri;
      }
      
      public DynamicTagLibrary getTagLibrary() {
          return tagLibrary;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagLibrary.java
  
  Index: DefineTagLibrary.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagLibrary.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/04/25 18:14:09 $
   *
   * ====================================================================
   *
   * 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: DefineTagLibrary.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.define;
  
  import org.apache.commons.jelly.TagLibrary;
  
  
  /** 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 DefineTagLibrary extends TagLibrary {
  
      public DefineTagLibrary() {
          registerTag( "taglib", DefineTagLibTag.class );
          registerTag( "tag", DefineTagTag.class );
          registerTag( "invokeBody", InvokeBodyTag.class );
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagTag.java
  
  Index: DefineTagTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DefineTagTag.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/04/25 18:14:09 $
   *
   * ====================================================================
   *
   * 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: DefineTagTag.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.define;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  /** 
   * <p><code>DefineTagTag</code> is used to define a new tag
   * using a Jelly script..</p>
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class DefineTagTag extends TagSupport {
      
      private String name;
      
      public DefineTagTag() {
      }
      
      // Tag interface
      //-------------------------------------------------------------------------                    
      public void run(Context context, XMLOutput output) throws Exception {
          DefineTagLibTag tag 
              = (DefineTagLibTag) findAncestorWithClass(this, DefineTagLibTag.class);
          if ( tag == null ) {
              throw new JellyException( "<define:tag> must be inside <define:taglib>" );
          }
          tag.getTagLibrary().registerDynamicTag( getName(), getBody() );
      }    
      
      // Properties
      //-------------------------------------------------------------------------                    
      
      /** @return the name of the tag to create */
      public String getName() {
          return name;
      }
      
      /** Sets the name of the tag to create */
      public void setName(String name) {
          this.name = name;
      }    
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTag.java
  
  Index: DynamicTag.java
  ===================================================================
  /*
   * $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 $
   *
   * ====================================================================
   *
   * 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: DynamicTag.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.define;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.DynaTag;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  /** 
   * <p><code>DynamicTag</code> is a tag that is created from
   * inside a Jelly script as a Jelly template and will invoke a 
   * given script, passing in its instantiation attributes 
   * 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 $
   */
  public class DynamicTag extends TagSupport implements DynaTag {
      
      /** The template script */
      private Script template;
      /** The instance attributes */
      private Map attributes = new HashMap();
      
      public DynamicTag() {
      }
      
      public DynamicTag(Script template) {
          this.template = template;
      }
      
      
      // Tag interface
      //-------------------------------------------------------------------------                    
      public void run(Context context, XMLOutput output) throws Exception {
  
          // create new context based on current attributes
          Context newContext = context.newContext( attributes );
          
          getTemplate().run( newContext, output );
      }    
      
      // DynaTag interface
      //-------------------------------------------------------------------------                    
      public void setAttribute(String name, Object value) {
          attributes.put( name, value );
      }
      
      // Properties
      //-------------------------------------------------------------------------                    
      
      /** The template to be executed by this tag which may well 
       * invoke this instances body from inside the template
       */
      public Script getTemplate() {
          return template;
      }
      
      public void setTemplate(Script template) {
          this.template = template;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTagLibrary.java
  
  Index: DynamicTagLibrary.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/DynamicTagLibrary.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/04/25 18:14:09 $
   *
   * ====================================================================
   *
   * 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: DynamicTagLibrary.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.define;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.TagLibrary;
  import org.apache.commons.jelly.impl.TagScript;
  
  import org.xml.sax.Attributes;
  
  /** 
   * <p><code>DynamicTagLibrary</code> represents a TagLibrary which
   * gets created by running a Jelly script.</p>
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class DynamicTagLibrary extends TagLibrary {
  
      private String uri;
      private Map templates = new HashMap();
      
      public DynamicTagLibrary() {
      }
      
      public DynamicTagLibrary(String uri) {
          this.uri = uri;
      }
      
      /** Creates a new script to execute the given tag name and attributes */
      public TagScript createTagScript(String name, Attributes attributes) throws Exception {
          Script template = (Script) templates.get(name);
          if ( template != null ) {
              DynamicTag tag = new DynamicTag( template );
              // XXXX: somehow we should find the template's 
              // <invokeBody> tag and associate it with this instance
              
              return new TagScript( tag );
          }
          return null;
      }
  
      /**
       * Creates a new tag with the given name and template 
       */
      public void registerDynamicTag(String name, Script template) {
          templates.put( name, template );
      }
      
      // Properties
      //-------------------------------------------------------------------------     
      public String getUri() {
          return uri;
      }
      
      public void setUri(String uri) {
          this.uri = uri;
      }
      
      
      
      // Implementation methods
      //-------------------------------------------------------------------------     
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/InvokeBodyTag.java
  
  Index: InvokeBodyTag.java
  ===================================================================
  /*
   * $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 $
   *
   * ====================================================================
   *
   * 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: InvokeBodyTag.java,v 1.1 2002/04/25 18:14:09 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.define;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.Tag;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  /** 
   * <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 $
   */
  public class InvokeBodyTag extends TagSupport {
      
      public InvokeBodyTag() {
      }
      
      // Tag interface
      //-------------------------------------------------------------------------                    
      public void run(Context context, XMLOutput output) throws Exception {
          
          // #### note this mechanism does not work properly for arbitrarily 
          // #### 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" );
          }
          tag.getBody().run(context, output);
      }    
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/define/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
  
    <p>Tag library which allows the creation of new tags using Jelly script itself.
    </p>
  </body>
  </html>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/define/babelfishTaglib.jelly
  
  Index: babelfishTaglib.jelly
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- defines a new taglib of babelfish soap services -->
  
  <j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml" xmlns:define="jelly:define" xmlns:http="notImplementedYet">
    <define:taglib uri="jelly:babelfish">
    
      <!-- defines the <translate> tag -->
      <define:tag name="translate">
        <http:post url="http://services.xmethods.net:80/perl/soaplite.cgi">
         <http:header name="SOAPAction" value="urn:xmethodsBabelFish#BabelFish"/>
         <http:header name="Content-Type" value="text/xml"/>
         <http:body>
          <env:Envelope 
            xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
            env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
            <env:Body>
              <m:BabelFish xmlns:m="urn:xmethodsBabelFish">
                <translationmode><j:expr value="${from}"/>_<j:expr value="${to}"/></translationmode>      
                <sourcedata><define:invokeBody/></sourcedata>    
              </m:BabelFish>
            </env:Body>
          </env:Envelope>
         </http:body>
        </http:post>
      </define:tag>
      
    </define:taglib>    
  </j:jelly>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/define/example.jelly
  
  Index: example.jelly
  ===================================================================
  <?xml version="1.0"?>
  
  <!-- uses the babelfish taglib -->
  
  <j:jelly xmlns:j="jelly:core" xmlns:babelfish="jelly:babelfish">
    <babelfish:translate from="EN" to="FR">
      Jelly is cool stuff!
    </babelfish:translate>
  </j:jelly>
  
  
  

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