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/03/07 03:46:04 UTC

cvs commit: jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/beanshell TestBeanShellEL.java

jstrachan    02/03/06 18:46:04

  Modified:    jelly    build.properties.sample build.xml
               jelly/src/java/org/apache/commons/jelly Context.java
                        filesystem.attributes
               jelly/src/java/org/apache/commons/jelly/parser
                        XMLParser.java
               jelly/src/java/org/apache/commons/jelly/tags/core
                        CoreTagLibrary.java
               jelly/src/test/org/apache/commons/jelly example.jelly
                        example2.jelly example3.jelly hello_world.jelly
                        show_properties.jelly testing123.jelly
               jelly/src/test/org/apache/commons/jelly/beanshell
                        TestBeanShellEL.java
  Added:       jelly/src/java/org/apache/commons/jelly jelly.properties
               jelly/src/java/org/apache/commons/jelly/tags/beanshell
                        BeanShellExpression.java
                        BeanShellExpressionFactory.java
                        BeanShellTagLibrary.java JellyInterpreter.java
                        package.html
               jelly/src/java/org/apache/commons/jelly/tags/bsf
                        BSFExpression.java BSFExpressionFactory.java
                        BSFTagLibrary.java ContextRegistry.java
                        package.html
  Removed:     jelly/src/java/org/apache/commons/jelly/expression/beanshell
                        BeanShellExpression.java
                        BeanShellExpressionFactory.java
                        JellyInterpreter.java package.html
  Log:
  Added support for BSF and associated scripting languages. Also added a jelly.properties mechanism to allow common tag libraries to have well defined prefixes.
  
  Revision  Changes    Path
  1.4       +8 -1      jakarta-commons-sandbox/jelly/build.properties.sample
  
  Index: build.properties.sample
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/build.properties.sample,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- build.properties.sample	19 Feb 2002 15:40:58 -0000	1.3
  +++ build.properties.sample	7 Mar 2002 02:46:03 -0000	1.4
  @@ -18,8 +18,15 @@
   # dom4j.jar - go to http://dom4j.org to download
   dom4j.jar=/java/dom4j/dom4j.jar
   
  +# BSF: the Bean Scripting Framework from
  +# http://oss.software.ibm.com/developerworks/projects/bsf
  +bsf.jar=/java/bsf/bsf.jar
  +
  +# Rhino is the default language for BSF
  +# http://www.mozilla.org/rhino
  +rhino.jar=/java/rhino/js.jar
  +
   # for the beanshell expression language the following is required
   #
   # beanshell.jar - go to http://www.beanshell.org
   beanshell.jar=/java/beanshell/beanshell.jar
  -
  
  
  
  1.8       +55 -1     jakarta-commons-sandbox/jelly/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/build.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- build.xml	20 Feb 2002 00:21:12 -0000	1.7
  +++ build.xml	7 Mar 2002 02:46:03 -0000	1.8
  @@ -3,7 +3,7 @@
   
   <!--
           "Jelly" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.7 2002/02/20 00:21:12 geirm Exp $
  +        $Id: build.xml,v 1.8 2002/03/07 02:46:03 jstrachan Exp $
   -->
   
   
  @@ -22,6 +22,7 @@
     <property name="jaxp.home"               value="/usr/local/jaxp1.1"/>
     <property name="jdk.home"                value="/usr/local/jdk1.3"/>
     <property name="junit.home"              value="/usr/local/junit3.7"/>
  +  <property name="bsf.home"                value="/usr/local/bsf"/>
     <property name="commons.home"            value="../../jakarta-commons"/>
     <property name="beanutils.home"          value="${commons.home}/beanutils"/>
     <property name="collections.home"        value="${commons.home}/collections"/>
  @@ -34,10 +35,12 @@
   
     <!-- The locations of necessary jar files -->
     <property name="jdk.api"                 value="${jdk.home}/docs/api"/>
  +  <property name="tools.jar"               value="${jdk.home}/lib/tools.jar"/>
     <property name="jaxp.jaxp.jar"           value="${jaxp.home}/jaxp.jar"/>
     <property name="jaxp.parser.jar"         value="${jaxp.home}/crimson.jar"/>
     <property name="jaxp.api"                value="${jaxp.home}/docs/api"/>
     <property name="junit.jar"               value="${junit.home}/junit.jar"/>
  +  <property name="bsf.jar"                 value="${bsf.home}/bsf.jar"/>
     <property name="commons-beanutils.api"   value="${beanutils.home}/dist/docs/api"/>
     <property name="commons-beanutils.jar"   value="${beanutils.home}/dist/commons-beanutils.jar"/>
     <property name="commons-collections.api" value="${collections.home}/dist/docs/api"/>
  @@ -97,6 +100,9 @@
       <pathelement location="${jaxp.jaxp.jar}"/>
       <pathelement location="${jaxp.parser.jar}"/>
       <pathelement location="${dom4j.jar}"/>
  +    <pathelement location="${bsf.jar}"/>
  +    <pathelement location="${rhino.jar}"/>
  +    <pathelement location="${tools.jar}"/>
       <pathelement location="${beanshell.jar}"/>
       <pathelement location="${commons-beanutils.jar}"/>
       <pathelement location="${commons-collections.jar}"/>
  @@ -117,6 +123,9 @@
       <pathelement location="${jaxp.jaxp.jar}"/>
       <pathelement location="${jaxp.parser.jar}"/>
       <pathelement location="${dom4j.jar}"/>
  +    <pathelement location="${bsf.jar}"/>
  +    <pathelement location="${rhino.jar}"/>
  +    <pathelement location="${tools.jar}"/>
       <pathelement location="${beanshell.jar}"/>
       <pathelement location="${commons-beanutils.jar}"/>
       <pathelement location="${commons-collections.jar}"/>
  @@ -131,6 +140,13 @@
     <property name="test.runner"             value="junit.textui.TestRunner"/>
   
   
  +<!-- ========== Source files to be compiled =============================== -->
  +  <patternset id="javac.source.files">
  +    <!-- Optionally includes engines based on dependencies being present -->
  +    <exclude name="**/beanshell/**" unless="beanshell.present"/>
  +    <exclude name="**/bsf/**" unless="bsf.present"/>
  +  </patternset>
  +
   <!-- ========== Executable Targets ======================================== -->
   
   
  @@ -139,8 +155,44 @@
       <echo message="-------- ${component.name} ${component.version} --------"/>
       <filter  token="name"                  value="${component.package}"/>
       <filter  token="version"               value="${component.version}"/>
  +
  +    <!-- set the conditional compilations -->
  +    <available property="bsf.present"
  +               classpathref="compile.classpath"
  +               classname="com.ibm.bsf.BSFEngine"/>
  +
  +    <available property="beanshell.present"
  +               classpathref="compile.classpath"
  +               classname="bsh.Interpreter"/>
  +
  +    <available property="jpython.present"
  +               classpathref="compile.classpath"
  +               classname="org.python.util.PythonInterpreter"/>
  +
  +    <available property="rhino.present"
  +               classpathref="compile.classpath"
  +               classname="org.mozilla.javascript.Scriptable"/>
     </target>
   
  +  <!-- Warn the user about items not being compiled                        -->
  +  <target name="checkBsf" unless="bsf.present">
  +    <echo message="Warning: BSF dependencies were not resolved."/>
  +  </target>
  +  <target name="checkBeanShell" unless="beanshell.present">
  +    <echo message="Warning: BeanShell dependencies were not resolved."/>
  +  </target>
  +  <target name="checkJPython" unless="jpython.present">
  +<!--
  +    <echo message="Warning: JPython dependencies were not resolved."/>
  +-->
  +  </target>
  +  <target name="checkRhino" unless="rhino.present">
  +    <echo message="Warning: Rhino dependencies were not resolved."/>
  +  </target>
  +  <target name="checkDependencies" 
  +          depends="checkBsf, checkBeanShell, checkJPython, checkRhino"
  +          description="Checks for dependend (but non-essential) JARs are present"/>
  +
   
     <target name="prepare" depends="init"
      description="Prepare build directory">
  @@ -148,6 +200,8 @@
       <mkdir dir="${build.home}/classes"/>
       <mkdir dir="${build.home}/conf"/>
       <mkdir dir="${build.home}/tests"/>
  +
  +    <antcall target="checkDependencies"/>
     </target>
   
   
  
  
  
  1.4       +10 -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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Context.java	13 Feb 2002 16:00:39 -0000	1.3
  +++ Context.java	7 Mar 2002 02:46:03 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java,v 1.3 2002/02/13 16:00:39 jstrachan Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/02/13 16:00:39 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java,v 1.4 2002/03/07 02:46:03 jstrachan Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/03/07 02:46:03 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: Context.java,v 1.3 2002/02/13 16:00:39 jstrachan Exp $
  + * $Id: Context.java,v 1.4 2002/03/07 02:46:03 jstrachan Exp $
    */
   package org.apache.commons.jelly;
   
  @@ -69,7 +69,7 @@
   /** <p><code>Context</code> represents the Jelly context.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.3 $
  +  * @version $Revision: 1.4 $
     */
   public class Context {
   
  @@ -97,6 +97,11 @@
               variables.put( name, value );
           }
       }    
  +
  +    /** Removes the given variable */
  +    public void removeVariable( String name ) {
  +        variables.remove( name );
  +    }
       
       /** 
        * @return an Iterator over the current variable names in this
  
  
  
  1.2       +2 -1      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/filesystem.attributes
  
  	<<Binary file>>
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/jelly.properties
  
  Index: jelly.properties
  ===================================================================
  # register the default tag libraries with an abbreviated name
  beanshell = org.apache.commons.jelly.tags.beanshell.BeanShellTagLibrary
  bsf       = org.apache.commons.jelly.tags.bsf.BSFTagLibrary
  xml       = org.apache.commons.jelly.tags.xml.XMLTagLibrary
  
  
  
  1.7       +63 -8     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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XMLParser.java	19 Feb 2002 15:40:58 -0000	1.6
  +++ XMLParser.java	7 Mar 2002 02:46:04 -0000	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v 1.6 2002/02/19 15:40:58 jstrachan Exp $
  - * $Revision: 1.6 $
  - * $Date: 2002/02/19 15:40:58 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v 1.7 2002/03/07 02:46:04 jstrachan Exp $
  + * $Revision: 1.7 $
  + * $Date: 2002/03/07 02:46:04 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - * $Id: XMLParser.java,v 1.6 2002/02/19 15:40:58 jstrachan Exp $
  + * $Id: XMLParser.java,v 1.7 2002/03/07 02:46:04 jstrachan Exp $
    */
   package org.apache.commons.jelly.parser;
   
  @@ -75,6 +75,7 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  +import java.util.Properties;
   
   import javax.xml.parsers.SAXParser;
   import javax.xml.parsers.SAXParserFactory;
  @@ -92,7 +93,7 @@
   import org.apache.commons.jelly.expression.ConstantExpression;
   import org.apache.commons.jelly.expression.Expression;
   import org.apache.commons.jelly.expression.ExpressionFactory;
  -import org.apache.commons.jelly.expression.beanshell.BeanShellExpressionFactory;
  +import org.apache.commons.jelly.tags.beanshell.BeanShellExpressionFactory;
   import org.apache.commons.jelly.tags.core.CoreTagLibrary;
   import org.apache.commons.jelly.tags.xml.XMLTagLibrary;
   
  @@ -115,7 +116,7 @@
    * 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.6 $
  + * @version $Revision: 1.7 $
    */
   public class XMLParser extends DefaultHandler {
       
  @@ -250,6 +251,33 @@
           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).
  @@ -898,8 +926,35 @@
        * which allows tag libraries to be registered and so forth
        */
       protected void configure() {
  -        registerTagLibrary( "jelly:core", new CoreTagLibrary() );
  -        registerTagLibrary( "jelly:xml", new XMLTagLibrary() );
  +        // load the properties file of libraries available
  +        InputStream in = null;
  +        URL url = getClassLoader().getResource( "org/apache/commons/jelly/jelly.properties" );
  +        if ( url != null ) {
  +            log.debug( "Loading Jelly default tag libraries from: " + url );
  +            
  +            Properties properties = new Properties();
  +            try {
  +                in = url.openStream();
  +                properties.load( in );
  +                for ( Iterator iter = properties.entrySet().iterator(); iter.hasNext(); ) {
  +                    Map.Entry entry = (Map.Entry) iter.next();
  +                    String uri = (String) entry.getKey();
  +                    String className = (String) entry.getValue();
  +                    registerTagLibrary( "jelly:" + uri, className );
  +                }
  +            }
  +            catch (IOException e) {
  +                log.error( "Could not load jelly properties from: " + url + ". Reason: " + e, e );
  +            }
  +            finally {
  +                try {
  +                    in.close();
  +                }
  +                catch (Exception e) {
  +                    // ignore
  +                }
  +            }
  +        }
       }
           
       
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpression.java
  
  Index: BeanShellExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpression.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/07 02:46:04 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: BeanShellExpression.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.beanshell;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.expression.ExpressionSupport;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  
  /** Represents a <a href="http://www.beanshell.org">beanshell</a> expression
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class BeanShellExpression extends ExpressionSupport {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog( BeanShellExpression.class );
  
      /** The expression */
      private String text;
      
      /** The interpreter */
      private JellyInterpreter interpreter = new JellyInterpreter();
      
      public BeanShellExpression(String text, JellyInterpreter interpreter) {
          this.text = text;
          this.interpreter = interpreter;
      }
  
      // Expression interface
      //------------------------------------------------------------------------- 
      public Object evaluate(Context context) {
          try {
              interpreter.setContext(context);
              if ( log.isDebugEnabled() ) {            
                  log.debug( "Evaluating EL: " + text );
              }
              
              return interpreter.eval( text );
          }
          catch (Exception e) {
              log.warn( "Caught exception evaluating: " + text + ". Reason: " + e, e );
              return null;
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpressionFactory.java
  
  Index: BeanShellExpressionFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpressionFactory.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/07 02:46:04 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: BeanShellExpressionFactory.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.beanshell;
  
  import org.apache.commons.jelly.expression.Expression;
  import org.apache.commons.jelly.expression.ExpressionFactory;
  
  /** Represents a factory of <a href="http://www.beanshell.org">beanshell</a> expressions
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class BeanShellExpressionFactory implements ExpressionFactory {
  
      /** The interpreter */
      private JellyInterpreter interpreter = new JellyInterpreter();
      
      // ExpressionFactory interface
      //------------------------------------------------------------------------- 
      public Expression createExpression(String text) throws Exception {
          return new BeanShellExpression(text, interpreter);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellTagLibrary.java
  
  Index: BeanShellTagLibrary.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellTagLibrary.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/07 02:46:04 $
   *
   * ====================================================================
   *
   * 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: BeanShellTagLibrary.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.beanshell;
  
  import org.apache.commons.jelly.expression.ExpressionFactory;
  import org.apache.commons.jelly.tags.core.CoreTagLibrary;
  
  
  /** 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 BeanShellTagLibrary extends CoreTagLibrary {
  
      private ExpressionFactory expressionFactory = new BeanShellExpressionFactory();
      
          /** Allows derived tag libraries to use their own factory */
      protected ExpressionFactory getExpressionFactory() {
          return expressionFactory;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/JellyInterpreter.java
  
  Index: JellyInterpreter.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/JellyInterpreter.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/07 02:46:04 $
   *
   * ====================================================================
   *
   * 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: JellyInterpreter.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.beanshell;
  
  import bsh.EvalError;
  import bsh.Interpreter;
  
  import java.util.Iterator;
  
  import org.apache.commons.jelly.Context;
  
  /** Integrates BeanShell's interpreter with Jelly's Context
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class JellyInterpreter extends Interpreter {
  
      private Context context;
      
      public JellyInterpreter() {
      }
  
      public Context getContext() {
          return context;
      }
      
      public void setContext(Context context) throws EvalError {
          this.context = context;
          
          // now pass in all the variables
          for ( Iterator iter = context.getVariableNames(); iter.hasNext(); ) {
              String name = (String) iter.next();
              Object value = context.getVariable(name);
              set( name, value );
          }
      }
  
  /*
    
      // the following code doesn't work - it seems that
      // all variables must be passed into the Interpreter
      // via set() method
   
      public Object get(String name) throws EvalError {
          if ( context != null ) {
              Object answer = context.getVariable( name );
              if ( answer != null ) { 
                  return answer;
              }
          }
          return super.get( name );
      }
  */
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/beanshell/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
  
    <p>Implementation of Expression and ExpressionFactory that uses <a href="http://www.beanshell.org">BeanShell</a>.
    </p>
  
  </body>
  </html>
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/BSFExpression.java
  
  Index: BSFExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/BSFExpression.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/07 02:46:04 $
   *
   * ====================================================================
   *
   * 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: BSFExpression.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.bsf;
  
  import com.ibm.bsf.BSFEngine;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.expression.ExpressionSupport;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  
  /** Represents a BSF expression
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class BSFExpression extends ExpressionSupport {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog( BSFExpression.class );
  
      /** The expression */
      private String text;
      
      /** The BSF Engine to evaluate expressions */
      private BSFEngine engine;
      
      /** The adapter to BSF's ObjectRegistry that uses the Context */
      private ContextRegistry registry;
      
      public BSFExpression(String text, BSFEngine engine, ContextRegistry registry) {
          this.text = text;
          this.engine = engine;
          this.registry = registry;
      }
  
      // Expression interface
      //------------------------------------------------------------------------- 
      public Object evaluate(Context context) {
          // 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 (registry) {
              registry.setContext(context);
              try {
                  return engine.eval( text, -1, -1, text );
              }
              catch (Exception e) {
                  log.warn( "Caught exception evaluating: " + text + ". Reason: " + e, e );
                  return null;
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/BSFExpressionFactory.java
  
  Index: BSFExpressionFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/BSFExpressionFactory.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/07 02:46:04 $
   *
   * ====================================================================
   *
   * 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: BSFExpressionFactory.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.bsf;
  
  import com.ibm.bsf.BSFEngine;
  import com.ibm.bsf.BSFException;
  import com.ibm.bsf.BSFManager;
  
  import java.io.File;
  
  import org.apache.commons.jelly.expression.Expression;
  import org.apache.commons.jelly.expression.ExpressionFactory;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** Represents a factory of BSF expressions
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class BSFExpressionFactory implements ExpressionFactory {
  
      /** The logger of messages */
      private Log log = LogFactory.getLog( getClass() );
      
      private String language = "javascript";
      private BSFManager manager;
      private BSFEngine engine;
      private ContextRegistry registry = new ContextRegistry();
      
      public BSFExpressionFactory() {
      }
      
      // Properties
      //------------------------------------------------------------------------- 
  
      /** @return the BSF language to be used */
      public String getLanguage() {
          return language;
      }
      
      public void setLanguage(String language) {
          this.language = language;
      }
      
      /** @return the BSF Engine to be used by this expression factory */
      public BSFEngine getBSFEngine() throws BSFException {
          if ( engine == null ) {
              engine = createBSFEngine();
          }
          return engine;
      }
      
      public void setBSFEngine(BSFEngine engine) {
          this.engine = engine;
      }
      
      public BSFManager getBSFManager() {
          if ( manager == null ) {
              manager = createBSFManager();
              manager.setObjectRegistry( registry );
          }
          return manager;
      }
      
      public void setBSFManager(BSFManager manager) {
          this.manager = manager;
          manager.setObjectRegistry( registry );
      }
      
      // ExpressionFactory interface
      //------------------------------------------------------------------------- 
      public Expression createExpression(String text) throws Exception {
          return new BSFExpression( text, getBSFEngine(), registry );
      }
      
      // Implementation methods
      //------------------------------------------------------------------------- 
      
      /** Factory method */
      protected BSFEngine createBSFEngine() throws BSFException {        
          return getBSFManager().loadScriptingEngine( getLanguage() );
      }
      
      /** Factory method */
      protected BSFManager createBSFManager() {
          BSFManager answer = new BSFManager();
          
          // sets a temporary directory
          answer.setTempDir( "/tmp" );
  /*        
          this fails on windows...
   
          try {
              File file = File.createTempFile( "foo", "bar" );
              File tmpDirectory = file.getParentFile();
              if ( tmpDirectory != null ) {
                  log.debug( "Setting scripting temporary directory to be: " + tmpDirectory );
                  answer.setTempDir( tmpDirectory.getAbsolutePath() );
              }
          }
          catch (Exception e) {
              log.error( "Failed to set temporary directory for BSF manager" );
          }
  */
          return answer;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/BSFTagLibrary.java
  
  Index: BSFTagLibrary.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/BSFTagLibrary.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/07 02:46:04 $
   *
   * ====================================================================
   *
   * 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: BSFTagLibrary.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.bsf;
  
  import org.apache.commons.jelly.expression.ExpressionFactory;
  import org.apache.commons.jelly.tags.core.CoreTagLibrary;
  
  
  /** 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 BSFTagLibrary extends CoreTagLibrary {
  
      private ExpressionFactory expressionFactory = new BSFExpressionFactory();
      
          /** Allows derived tag libraries to use their own factory */
      protected ExpressionFactory getExpressionFactory() {
          return expressionFactory;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/ContextRegistry.java
  
  Index: ContextRegistry.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/ContextRegistry.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/03/07 02:46:04 $
   *
   * ====================================================================
   *
   * 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: ContextRegistry.java,v 1.1 2002/03/07 02:46:04 jstrachan Exp $
   */
  package org.apache.commons.jelly.tags.bsf;
  
  import com.ibm.bsf.util.ObjectRegistry;
  
  import org.apache.commons.jelly.Context;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  
  /** A BSF ObjectRegistry which uses the Context to find and
    * register objects
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class ContextRegistry extends ObjectRegistry {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog( ContextRegistry.class );
  
      /** The context */
      private Context context;
      
      public ContextRegistry() {
      }
  
      public Context getContext() {
          return context;
      }
      
      public void setContext(Context context) {
          this.context = context;
      }
      
      // ObjectRegistry interface
      //------------------------------------------------------------------------- 
      public Object lookup(String name) {
          return context.getVariable( name );
      }
      
      public void register(String name, Object value) {
          context.setVariable( name, value );
      }
      
      public void unregister(String name) {
          context.removeVariable( name );
      }        
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/bsf/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
  
    <p>Implementation of Expression and ExpressionFactory that uses 
      the <a href="http://oss.software.ibm.com/developerworks/projects/bsf">Bean Scripting Framework</a>.
    </p>
  
  </body>
  </html>
  
  
  1.4       +19 -7     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java
  
  Index: CoreTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CoreTagLibrary.java	15 Feb 2002 18:25:06 -0000	1.3
  +++ CoreTagLibrary.java	7 Mar 2002 02:46:04 -0000	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java,v 1.3 2002/02/15 18:25:06 jstrachan Exp $
  - * $Revision: 1.3 $
  - * $Date: 2002/02/15 18:25:06 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java,v 1.4 2002/03/07 02:46:04 jstrachan Exp $
  + * $Revision: 1.4 $
  + * $Date: 2002/03/07 02:46:04 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: CoreTagLibrary.java,v 1.3 2002/02/15 18:25:06 jstrachan Exp $
  + * $Id: CoreTagLibrary.java,v 1.4 2002/03/07 02:46:04 jstrachan Exp $
    */
   package org.apache.commons.jelly.tags.core;
   
  @@ -76,7 +76,7 @@
   /** Describes the Taglib. This class could be generated by XDoclet
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.3 $
  +  * @version $Revision: 1.4 $
     */
   public class CoreTagLibrary extends TagLibrary {
   
  @@ -96,10 +96,22 @@
       }
       
       public Expression createExpression(ExpressionFactory factory, String tagName, String attributeName, String attributeValue) throws Exception {
  -        if (attributeName.equals( "value" ) || attributeName.equals( "items" )  || attributeName.equals( "test" ) ) {
  -            return factory.createExpression( attributeValue );
  +        ExpressionFactory myFactory = getExpressionFactory();
  +        if ( myFactory == null ) {
  +            myFactory = factory;
  +        }
  +        if ( myFactory != null ) {
  +            if (attributeName.equals( "value" ) || attributeName.equals( "items" )  || attributeName.equals( "test" ) ) {
  +                return myFactory.createExpression( attributeValue );
  +            }
           }
           // will use the default expression instead
  +        return null;
  +    }
  +    
  +    
  +    /** Allows derived tag libraries to use their own factory */
  +    protected ExpressionFactory getExpressionFactory() {
           return null;
       }
   }
  
  
  
  1.3       +1 -1      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example.jelly
  
  Index: example.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example.jelly,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- example.jelly	12 Feb 2002 21:34:35 -0000	1.2
  +++ example.jelly	7 Mar 2002 02:46:04 -0000	1.3
  @@ -1,6 +1,6 @@
   <?xml version="1.0"?>
   
  -<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml">
  +<j:jelly xmlns:j="jelly:beanshell" xmlns:x="jelly:xml">
     <x:parse var="doc">
       <html>
         <title>It works!</title>
  
  
  
  1.2       +1 -1      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example2.jelly
  
  Index: example2.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example2.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- example2.jelly	12 Feb 2002 21:34:35 -0000	1.1
  +++ example2.jelly	7 Mar 2002 02:46:04 -0000	1.2
  @@ -1,6 +1,6 @@
   <?xml version="1.0"?>
   
  -<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml">
  +<j:jelly xmlns:j="jelly:beanshell" xmlns:x="jelly:xml">
     <x:parse var="doc">
       <web-app>
         <servlet>
  
  
  
  1.2       +1 -1      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example3.jelly
  
  Index: example3.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/example3.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- example3.jelly	15 Feb 2002 18:25:06 -0000	1.1
  +++ example3.jelly	7 Mar 2002 02:46:04 -0000	1.2
  @@ -1,6 +1,6 @@
   <?xml version="1.0"?>
   
  -<jelly xmlns="jelly:core">
  +<jelly xmlns="jelly:beanshell">
     <!-- a really silly way to do this but -->
     <!-- this should test the choose/when/otherwise tags -->
     <forEach var="iter" items="System.getProperties()">
  
  
  
  1.2       +1 -1      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/hello_world.jelly
  
  Index: hello_world.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/hello_world.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- hello_world.jelly	12 Feb 2002 21:34:35 -0000	1.1
  +++ hello_world.jelly	7 Mar 2002 02:46:04 -0000	1.2
  @@ -1,4 +1,4 @@
   <?xml version="1.0"?>
  -<j:jelly xmlns:j="jelly:core">
  +<j:jelly xmlns:j="jelly:beanshell">
     Hello World!
   </j:jelly>
  
  
  
  1.2       +1 -1      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/show_properties.jelly
  
  Index: show_properties.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/show_properties.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- show_properties.jelly	13 Feb 2002 17:03:09 -0000	1.1
  +++ show_properties.jelly	7 Mar 2002 02:46:04 -0000	1.2
  @@ -1,5 +1,5 @@
   <?xml version="1.0"?>
  -<j:jelly xmlns:j="jelly:core">
  +<j:jelly xmlns:j="jelly:beanshell">
   <html>
     <body>
       <h1>System properties</h1>
  
  
  
  1.3       +1 -1      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/testing123.jelly
  
  Index: testing123.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/testing123.jelly,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- testing123.jelly	13 Feb 2002 17:03:09 -0000	1.2
  +++ testing123.jelly	7 Mar 2002 02:46:04 -0000	1.3
  @@ -1,4 +1,4 @@
   <?xml version="1.0"?>
  -<j:jelly xmlns:j="jelly:core">
  +<j:jelly xmlns:j="jelly:beanshell">
     <j:forEach var="arg" items="args"><j:expr value="arg"/> </j:forEach>
   </j:jelly>
  
  
  
  1.5       +6 -6      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/beanshell/TestBeanShellEL.java
  
  Index: TestBeanShellEL.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/beanshell/TestBeanShellEL.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestBeanShellEL.java	19 Feb 2002 15:40:58 -0000	1.4
  +++ TestBeanShellEL.java	7 Mar 2002 02:46:04 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/beanshell/TestBeanShellEL.java,v 1.4 2002/02/19 15:40:58 jstrachan Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/02/19 15:40:58 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/beanshell/TestBeanShellEL.java,v 1.5 2002/03/07 02:46:04 jstrachan Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/03/07 02:46:04 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: TestBeanShellEL.java,v 1.4 2002/02/19 15:40:58 jstrachan Exp $
  + * $Id: TestBeanShellEL.java,v 1.5 2002/03/07 02:46:04 jstrachan Exp $
    */
   package org.apache.commons.jelly.beanshell;
   
  @@ -69,7 +69,7 @@
   import org.apache.commons.jelly.Context;
   import org.apache.commons.jelly.expression.Expression;
   import org.apache.commons.jelly.expression.ExpressionFactory;
  -import org.apache.commons.jelly.expression.beanshell.BeanShellExpressionFactory;
  +import org.apache.commons.jelly.tags.beanshell.BeanShellExpressionFactory;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -78,7 +78,7 @@
   /** Tests the BeanShell EL
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.4 $
  +  * @version $Revision: 1.5 $
     */
   public class TestBeanShellEL extends TestCase {
       
  
  
  

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