jstrachan    02/05/30 01:11:55

  Modified:    jelly/src/java/org/apache/commons/jelly jelly.properties
                        TagLibrary.java
               jelly/src/java/org/apache/commons/jelly/task JellyTask.java
  Added:       jelly/src/java/org/apache/commons/jelly
                        DynaBeanTagSupport.java
               jelly/src/java/org/apache/commons/jelly/tags/ant
                        package.html TaskTag.java DataTypeTag.java
                        AntTagLibrary.java
               jelly/src/test/org/apache/commons/jelly
                        example_ant_tasks.jelly
  Log:
  Added an Ant tag library which can invoke Ant tasks from inside a Jelly script. 
  Invoking Tasks is working fine, though support for Ant DataTypes isn't quite working 
yet (like nested <classpath> elements). Should have that working soon.
  
  Also added a new DynaBeanTagSupport class for developers wishing to use a DynaBean 
to hold tag attribute values.
  
  Revision  Changes    Path
  1.9       +1 -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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- jelly.properties  25 May 2002 18:27:21 -0000      1.8
  +++ jelly.properties  30 May 2002 08:11:55 -0000      1.9
  @@ -3,9 +3,9 @@
   define      = org.apache.commons.jelly.tags.define.DefineTagLibrary
   xml         = org.apache.commons.jelly.tags.xml.XMLTagLibrary
   sql         = org.apache.commons.jelly.tags.sql.SqlTagLibrary
  +jsl                  = org.apache.commons.jelly.tags.jsl.JSLTagLibrary
   
   # optional taglibs
  -jsl                  = org.apache.commons.jelly.tags.jsl.JSLTagLibrary
   ojb                  = org.apache.commons.jelly.tags.ojb.OjbTagLibrary
   beanshell   = org.apache.commons.jelly.tags.beanshell.BeanShellTagLibrary
   bsf         = org.apache.commons.jelly.tags.bsf.BSFTagLibrary
  
  
  
  1.9       +9 -5      
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java
  
  Index: TagLibrary.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TagLibrary.java   23 May 2002 23:53:42 -0000      1.8
  +++ TagLibrary.java   30 May 2002 08:11:55 -0000      1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java,v
 1.8 2002/05/23 23:53:42 jstrachan Exp $
  - * $Revision: 1.8 $
  - * $Date: 2002/05/23 23:53:42 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java,v
 1.9 2002/05/30 08:11:55 jstrachan Exp $
  + * $Revision: 1.9 $
  + * $Date: 2002/05/30 08:11:55 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: TagLibrary.java,v 1.8 2002/05/23 23:53:42 jstrachan Exp $
  + * $Id: TagLibrary.java,v 1.9 2002/05/30 08:11:55 jstrachan Exp $
    */
   
   package org.apache.commons.jelly;
  @@ -74,7 +74,7 @@
   /** <p><code>Taglib</code> represents the metadata for a Jelly custom tag 
library.</p>
     *
     * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
  -  * @version $Revision: 1.8 $
  +  * @version $Revision: 1.9 $
     */
   
   public abstract class TagLibrary {
  @@ -129,6 +129,10 @@
       /** Allows derived tag libraries to use their own factory */
       protected ExpressionFactory getExpressionFactory() {
           return null;
  +    }
  +    
  +    protected Map getTagClasses() {
  +        return tags;
       }
   
   }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/DynaBeanTagSupport.java
  
  Index: DynaBeanTagSupport.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/MapTagSupport.java,v
 1.3 2002/05/17 15:18:12 jstrachan Exp $
   * $Revision: 1.3 $
   * $Date: 2002/05/17 15:18:12 $
   *
   * ====================================================================
   *
   * 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 [EMAIL PROTECTED]
   *
   * 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: MapTagSupport.java,v 1.3 2002/05/17 15:18:12 jstrachan Exp $
   */
  
  package org.apache.commons.jelly;
  
  import org.apache.commons.beanutils.DynaBean;
  
  /** 
   * <p><code>DynaBeanTag</code> is a DynaTag implementation which uses a DynaBean
   * to store its attribute values in. Derived tags can then process this
   * DynaBean in any way it wishes.
   * </p>
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.3 $
   */
  
  public abstract class DynaBeanTagSupport extends TagSupport implements DynaTag {
  
      /** the DynaBean which is used to store the attributes of this tag */
      private DynaBean dynaBean;
  
      public DynaBeanTagSupport() {
      }
      
      public DynaBeanTagSupport(DynaBean dynaBean) {
          this.dynaBean = dynaBean;
      }
       
      /** Sets an attribute value of this tag before the tag is invoked
       */
      public void setAttribute(String name, Object value) {
          getDynaBean().set(name, value);
      }
  
      /** 
       * @return the DynaBean which is used to store the
       *  attributes of this tag
       */
      public DynaBean getDynaBean() {
          return dynaBean;
      }
      
      /**
       * Sets the DynaBean which is used to store the
       *  attributes of this tag
       */
      public void setDynaBean(DynaBean dynaBean) {
          this.dynaBean = dynaBean;
      }
      
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
  
    <p>A tag library for using Ant tasks within Jelly</p>
    
    <p>Jelly can be invoked inside Ant and this tag library allows Ant tasks to be 
invoked from inside
        Jelly. This allows Jelly to be used for more 'scripting' style targets, such 
as parsing XML databases,
        working with custom java beans, doing SQL, the use of JSTL and so forth.
    </p>
    
  </body>
  </html>
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/TaskTag.java
  
  Index: TaskTag.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IfTag.java,v
 1.6 2002/05/17 15:18:08 jstrachan Exp $
   * $Revision: 1.6 $
   * $Date: 2002/05/17 15:18:08 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: IfTag.java,v 1.6 2002/05/17 15:18:08 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.ant;
  
  import org.apache.commons.beanutils.DynaBean;
  import org.apache.commons.beanutils.WrapDynaBean;
  
  import org.apache.commons.jelly.DynaBeanTagSupport;
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.XMLOutput;
  
  import org.apache.tools.ant.Task;
  
  /** 
   * A tag which invokes an Ant Task
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.6 $
   */
  public class TaskTag extends DynaBeanTagSupport {
  
      /** the Ant task */
      private Task task;
  
      public TaskTag() {
      }
  
      public TaskTag(Task task) {
          this.task = task;
          setDynaBean( new WrapDynaBean(task) );
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
          Task task = getTask();
          task.init();
          
          // run the body first to configure the task via nested
          getBody().run(context, output);
          
          task.execute();        
      }
      
      // Properties
      //-------------------------------------------------------------------------      
          
      
      /** 
       * @return the Ant task
       */
      public Task getTask() {
          return task;
      }
      
      /** 
       * Sets the Ant task
       */
      public void setTask(Task task) {
          this.task = task;
          setDynaBean( new WrapDynaBean(task) );
      }
      
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/DataTypeTag.java
  
  Index: DataTypeTag.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/IfTag.java,v
 1.6 2002/05/17 15:18:08 jstrachan Exp $
   * $Revision: 1.6 $
   * $Date: 2002/05/17 15:18:08 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: IfTag.java,v 1.6 2002/05/17 15:18:08 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.ant;
  
  import java.lang.reflect.Method;
  
  import org.apache.commons.beanutils.DynaBean;
  import org.apache.commons.beanutils.DynaClass;
  import org.apache.commons.beanutils.DynaProperty;
  import org.apache.commons.beanutils.WrapDynaBean;
  
  import org.apache.commons.jelly.DynaBeanTagSupport;
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.XMLOutput;
  
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.types.DataType;
  
  /** 
   * A tag which manages a DataType used to configure a Task
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.6 $
   */
  public class DataTypeTag extends DynaBeanTagSupport {
  
      /** the name of the DataType */
      private String name;
      
      /** the Ant DataType */
      private DataType dataType;
  
      public DataTypeTag() {
      }
  
      public DataTypeTag(String name, DataType dataType) {
          this.name = name;
          this.dataType = dataType;
          setDynaBean( new WrapDynaBean(dataType) );
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
          TaskTag tag = (TaskTag) findAncestorWithClass( TaskTag.class );
          if ( tag == null ) {
              throw new JellyException( "You should only use Ant DataType tags within 
an Ant Task" );
          }        
          
          Task task = tag.getTask();
          DataType dataType = getDataType();
  
          // now we need to configure the task with the data type
          
          // first try setting a property on the DynaBean wrapper of the task
          DynaBean dynaBean = tag.getDynaBean();
          DynaClass dynaClass = dynaBean.getDynaClass();
          DynaProperty dynaProperty = dynaClass.getDynaProperty(name);
          if ( dynaProperty != null ) {
              // lets set the bean property
              dynaBean.set( name, dataType );
          }
          else {
              // lets invoke the addFoo() method instead
              String methodName = "add" + name.substring(0,1).toUpperCase() + 
name.substring(1);
              
              System.out.println( "About to invoke method: " + methodName );
              
              Class taskClass = task.getClass();
              Class[] parameterTypes = new Class[] { dataType.getClass() };
              Method method = taskClass.getMethod( methodName, parameterTypes );
              if ( method == null ) {
                  throw new JellyException( 
                      "Cannot add dataType: " + dataType + " to Ant task: " + task 
                      + " as no method called: " + methodName + " could be found" 
                  );
              }
              
              Object[] parameters = new Object[] { dataType };
              method.invoke( task, parameters );
          }
          
          
                  
          // run the body first to configure any nested DataType instances
          getBody().run(context, output);
      }
      
      // Properties
      //-------------------------------------------------------------------------      
          
      
      /** 
       * @return the name of the DataType 
       */
      public String getName() {
          return name;
      }
      
      /** 
       * Sets the name of the DataType 
       */
      public void setName(String name) {
          this.name = name;
      }
      
      /** 
       * @return the Ant dataType
       */
      public DataType getDataType() {
          return dataType;
      }
      
      /** 
       * Sets the Ant dataType
       */
      public void setDataType(DataType dataType) {
          this.dataType = dataType;
          setDynaBean( new WrapDynaBean(dataType) );
      }
      
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/ant/AntTagLibrary.java
  
  Index: AntTagLibrary.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java,v
 1.6 2002/05/17 18:04:00 jstrachan Exp $
   * $Revision: 1.6 $
   * $Date: 2002/05/17 18:04:00 $
   *
   * ====================================================================
   *
   * 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 [EMAIL PROTECTED]
   *
   * 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: XMLTagLibrary.java,v 1.6 2002/05/17 18:04:00 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.ant;
  
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.Tag;
  import org.apache.commons.jelly.TagLibrary;
  import org.apache.commons.jelly.impl.TagScript;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.apache.tools.ant.Project;
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.types.DataType;
  
  import org.xml.sax.Attributes;
  
  /** 
   * A Jelly custom tag library that allows Ant tasks to be called from inside Jelly.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.6 $
   */
  public class AntTagLibrary extends TagLibrary {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(AntTagLibrary.class);
      
      /** the Ant Project for this tag library */
      private Project project;
          
          
      public AntTagLibrary() {
      }
  
      public AntTagLibrary(Project project) {
          this.project = project;
      }
  
      /** Creates a new script to execute the given tag name and attributes */
      public TagScript createTagScript(String name, Attributes attributes) throws 
Exception {
          Project project = getProject();
          Class type = (Class) project.getTaskDefinitions().get(name);
          if ( type != null ) {            
              Task task = (Task) type.newInstance();
              task.setProject(project);
              task.setTaskName(name);
              Tag tag = new TaskTag( task );
              return TagScript.newInstance(tag);
          }
          type = (Class) project.getDataTypeDefinitions().get(name);
          if ( type != null ) {
              DataType dataType = (DataType) type.newInstance();
              dataType.setProject(project);
              Tag tag = new DataTypeTag( name, dataType );
              return TagScript.newInstance(tag);
          }
          return null;
      }
  
      
      // Properties
      //-------------------------------------------------------------------------      
          
      
      /**
       * @return the Ant Project for this tag library.
       */
      public Project getProject() {
          return project;
      }
      
      /**
       * Sets the Ant Project for this tag library.
       */
      public void setProject(Project project) {
          this.project = project;
      }
  
  }
  
  
  
  1.5       +4 -0      
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/task/JellyTask.java
  
  Index: JellyTask.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/task/JellyTask.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JellyTask.java    21 May 2002 16:53:26 -0000      1.4
  +++ JellyTask.java    30 May 2002 08:11:55 -0000      1.5
  @@ -21,6 +21,7 @@
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.XMLOutput;
   import org.apache.commons.jelly.parser.XMLParser;
  +import org.apache.commons.jelly.tags.ant.AntTagLibrary;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -163,6 +164,9 @@
               text = text.substring(0, idx + 1);
               JellyContext parentContext =  new JellyContext(getRootContext(), new 
URL(text));
               context = new AntJellyContext(project, parentContext);
  +            
  +            // register the Ant tag library
  +            context.registerTagLibrary( "jelly:ant", new AntTagLibrary(project) );
           }
           return context;
       }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example_ant_tasks.jelly
  
  Index: example_ant_tasks.jelly
  ===================================================================
  <?xml version="1.0"?>
<j:jelly xmlns:j="jelly:core" xmlns="jelly:ant">

  <!-- this 
example attempts to invoke some Ant tasks -->
  <echo message="Invoking the echo task 
from inside Jelly; the Maven repository is ${lib.repo}"/>           
  
  <!-- lets try invoke a program -->
  <java 
classname="org.apache.commons.jelly.Jelly" fork="yes">
    <classpath 
refid="test.classpath"/>
    <arg 
value="src/test/org/apache/commons/jelly/show_args.jelly"/> 
    <arg value="one"/> 
  
  <arg value="two"/> 
    <arg value="three"/> 
  </java>
    
</j:jelly>
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to