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 2003/03/05 09:11:56 UTC

cvs commit: jakarta-commons/jelly/jelly-tags/bsf project.xml

jstrachan    2003/03/05 00:11:56

  Modified:    jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf
                        BSFExpressionFactory.java JellyContextRegistry.java
                        PNutsTagLibrary.java BSFExpression.java
                        BSFTagLibrary.java ScriptTag.java
               jelly/src/java/org/apache/commons/jelly jelly.properties
               jelly/jelly-tags/bsf project.xml
  Added:       jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf
                        JythonTagLibrary.java
  Log:
  Applied patches kindly supplied by Pete Kazmier to to fix a number of things in the BSF support including...
  
   -  The existing ScriptTag calls the BSF eval() method, which can
       only be used to evaluate single expressions. To evaluate a
       script, the exec() method must be used.  This patch fixes that
       issue.
  
    -  Updated the BSF Taglib to use the latest and greatest BSF thats
       been moved into the jakarta namespace.  Also provides more
       support for addtional languages.
  
    -  The ScriptTag was not populating the BSF object registry so the
       jelly context was not available to scripts.  I used the same hack
       that was used for the expressions, could be cleaned up, just
       wanted to get this in so we had something working.
  
    -  Added a JythonTagLibrary in addition to the JPythonTagLibrary.
       Also updated jelly.properties to register this tag library under
       "jython".
  
  Revision  Changes    Path
  1.3       +8 -8      jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFExpressionFactory.java
  
  Index: BSFExpressionFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFExpressionFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BSFExpressionFactory.java	24 Jan 2003 07:40:58 -0000	1.2
  +++ BSFExpressionFactory.java	5 Mar 2003 08:11:55 -0000	1.3
  @@ -67,9 +67,9 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  -import com.ibm.bsf.BSFEngine;
  -import com.ibm.bsf.BSFException;
  -import com.ibm.bsf.BSFManager;
  +import org.apache.bsf.BSFEngine;
  +import org.apache.bsf.BSFException;
  +import org.apache.bsf.BSFManager;
   
   /** Represents a factory of BSF expressions
     *
  
  
  
  1.2       +4 -4      jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/JellyContextRegistry.java
  
  Index: JellyContextRegistry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/JellyContextRegistry.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JellyContextRegistry.java	8 Jan 2003 05:02:48 -0000	1.1
  +++ JellyContextRegistry.java	5 Mar 2003 08:11:55 -0000	1.2
  @@ -61,7 +61,7 @@
    */
   package org.apache.commons.jelly.tags.bsf;
   
  -import com.ibm.bsf.util.ObjectRegistry;
  +import org.apache.bsf.util.ObjectRegistry;
   
   import org.apache.commons.jelly.JellyContext;
   import org.apache.commons.logging.Log;
  
  
  
  1.2       +4 -4      jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/PNutsTagLibrary.java
  
  Index: PNutsTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/PNutsTagLibrary.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PNutsTagLibrary.java	8 Jan 2003 05:02:47 -0000	1.1
  +++ PNutsTagLibrary.java	5 Mar 2003 08:11:55 -0000	1.2
  @@ -61,7 +61,7 @@
    */
   package org.apache.commons.jelly.tags.bsf;
   
  -import com.ibm.bsf.BSFManager;
  +import org.apache.bsf.BSFManager;
   
   /** Describes the Taglib. This class could be generated by XDoclet
     *
  
  
  
  1.2       +5 -5      jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFExpression.java
  
  Index: BSFExpression.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFExpression.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BSFExpression.java	8 Jan 2003 05:02:48 -0000	1.1
  +++ BSFExpression.java	5 Mar 2003 08:11:55 -0000	1.2
  @@ -61,8 +61,8 @@
    */
   package org.apache.commons.jelly.tags.bsf;
   
  -import com.ibm.bsf.BSFEngine;
  -import com.ibm.bsf.BSFManager;
  +import org.apache.bsf.BSFEngine;
  +import org.apache.bsf.BSFManager;
   
   import java.util.Iterator;
   
  
  
  
  1.3       +18 -12    jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFTagLibrary.java
  
  Index: BSFTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/BSFTagLibrary.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BSFTagLibrary.java	20 Feb 2003 18:56:16 -0000	1.2
  +++ BSFTagLibrary.java	5 Mar 2003 08:11:55 -0000	1.3
  @@ -68,8 +68,8 @@
   import org.apache.commons.jelly.tags.core.CoreTagLibrary;
   import org.xml.sax.Attributes;
   
  -import com.ibm.bsf.BSFEngine;
  -import com.ibm.bsf.BSFException;
  +import org.apache.bsf.BSFEngine;
  +import org.apache.bsf.BSFException;
   
   
   /** Describes the Taglib. This class could be generated by XDoclet
  @@ -83,16 +83,21 @@
       
       public BSFTagLibrary() {
           registerTagFactory(
  -			"script", 
  -			new TagFactory() {
  +            "script", 
  +            new TagFactory() {
                   public Tag createTag(String name, Attributes attributes)
                       throws JellyException {
                       return createScriptTag(name, attributes);
                   }
  -			}
  -		);	
  +            }
  +            );	
       }
   
  +    public BSFTagLibrary(String language) {
  +        this();
  +        setLanguage(language);
  +    }
  +    
       public void setLanguage(String language) {
           expressionFactory.setLanguage(language);
       }
  @@ -115,7 +120,8 @@
        */
       protected Tag createScriptTag(String name, Attributes attributes) throws JellyException {
           try {
  -            return new ScriptTag( expressionFactory.getBSFEngine() );
  +            return new ScriptTag( expressionFactory.getBSFEngine(),
  +                                  expressionFactory.getBSFManager());
           }
           catch (BSFException e) {
               throw new JellyException("Failed to create BSFEngine: " + e, e);
  
  
  
  1.2       +38 -16    jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/ScriptTag.java
  
  Index: ScriptTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/ScriptTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ScriptTag.java	20 Feb 2003 18:56:16 -0000	1.1
  +++ ScriptTag.java	5 Mar 2003 08:11:55 -0000	1.2
  @@ -61,6 +61,8 @@
    */
   package org.apache.commons.jelly.tags.bsf;
   
  +import java.util.Iterator;
  +
   import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.LocationAware;
   import org.apache.commons.jelly.MissingAttributeException;
  @@ -69,8 +71,9 @@
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   
  -import com.ibm.bsf.BSFEngine;
  -import com.ibm.bsf.BSFException;
  +import org.apache.bsf.BSFEngine;
  +import org.apache.bsf.BSFManager;
  +import org.apache.bsf.BSFException;
   
   /** 
    * A tag which evaluates its body using the current scripting language
  @@ -84,13 +87,15 @@
       private static final Log log = LogFactory.getLog(ScriptTag.class.getName() + ".evaluating");
   	
       private BSFEngine engine;
  +    private BSFManager manager;
       private String elementName;
       private String fileName;
       private int columnNumber;
       private int lineNumber;
       
  -    public ScriptTag(BSFEngine engine) {
  +    public ScriptTag(BSFEngine engine, BSFManager manager) {
           this.engine = engine;
  +        this.manager = manager;
       }
   
       // Tag interface
  @@ -98,15 +103,28 @@
       public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
           String text = getBodyText();
   
  -		log.debug(text);        
  -        
  -        try {
  -            engine.eval(fileName, lineNumber, columnNumber, text);
  -        }
  -        catch (BSFException e) {
  -            throw new JellyTagException("Error occurred with script: " + e, e);
  +        log.debug(text);        
  +
  +        // XXXX: unfortunately we must sychronize evaluations
  +        // so that we can swizzle in the context.
  +        // maybe we could create an expression from a context
  +        // (and so create a BSFManager for a context)
  +        synchronized (getRegistry()) {
  +            getRegistry().setJellyContext(context);
  +
  +            try {            
  +                // XXXX: hack - there must be a better way!!!
  +                for ( Iterator iter = context.getVariableNames(); iter.hasNext(); ) {
  +                    String name = (String) iter.next();
  +                    Object value = context.getVariable( name );
  +                    manager.declareBean( name, value, value.getClass() );
  +                }
  +                engine.exec(fileName, lineNumber, columnNumber, text);
  +            }
  +            catch (BSFException e) {
  +                throw new JellyTagException("Error occurred with script: " + e, e);
  +            }
           }
  -        
       }
       
       // Properties
  @@ -186,4 +204,8 @@
           this.lineNumber = lineNumber;
       }
   
  +    private JellyContextRegistry getRegistry()
  +    {
  +        return (JellyContextRegistry) this.manager.getObjectRegistry();
  +    }    
   }
  
  
  
  1.1                  jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/JythonTagLibrary.java
  
  Index: JythonTagLibrary.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/src/java/org/apache/commons/jelly/tags/bsf/JythonTagLibrary.java,v 1.1 2003/03/05 08:11:55 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2003/03/05 08:11:55 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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: JythonTagLibrary.java,v 1.1 2003/03/05 08:11:55 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.bsf;
  
  /** 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 JythonTagLibrary extends BSFTagLibrary {
  
      public JythonTagLibrary() {
          setLanguage( "jython" );
      }
  }
  
  
  
  1.37      +1 -0      jakarta-commons/jelly/src/java/org/apache/commons/jelly/jelly.properties
  
  Index: jelly.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/jelly.properties,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- jelly.properties	26 Feb 2003 09:41:37 -0000	1.36
  +++ jelly.properties	5 Mar 2003 08:11:56 -0000	1.37
  @@ -20,6 +20,7 @@
   jetty       = org.apache.commons.jelly.tags.jetty.JettyTagLibrary
   jms         = org.apache.commons.jelly.tags.jms.JMSTagLibrary
   jpython     = org.apache.commons.jelly.tags.bsf.JPythonTagLibrary
  +jython      = org.apache.commons.jelly.tags.bsf.JythonTagLibrary
   jsl         = org.apache.commons.jelly.tags.jsl.JSLTagLibrary
   junit 	    = org.apache.commons.jelly.tags.junit.JUnitTagLibrary
   log         = org.apache.commons.jelly.tags.log.LogTagLibrary
  
  
  
  1.5       +1 -1      jakarta-commons/jelly/jelly-tags/bsf/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/bsf/project.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- project.xml	27 Jan 2003 05:24:17 -0000	1.4
  +++ project.xml	5 Mar 2003 08:11:56 -0000	1.5
  @@ -30,7 +30,7 @@
   
       <dependency>
         <id>bsf</id>
  -      <version>2.2</version>
  +      <version>2.3.0-rc1</version>
         <url>http://jakarta.apache.org/bsf</url>
       </dependency>
       <!-- END for compilation -->
  
  
  

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