dion        2003/01/11 05:27:30

  Added:       
jelly/jelly-tags/beanshell/src/java/org/apache/commons/jelly/tags/beanshell
                        ScriptTag.java package.html JellyInterpreter.java
                        BeanShellExpressionFactory.java
                        BeanShellTagLibrary.java BeanShellExpression.java
               
jelly/jelly-tags/beanshell/src/test/org/apache/commons/jelly/tags/beanshell
                        suite.jelly TestJelly.java TestBeanShellEL.java
               jelly/jelly-tags/beanshell maven.xml project.xml .cvsignore
                        project.properties
  Log:
  Move beanshell tag lib from core
  
  Revision  Changes    Path
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/java/org/apache/commons/jelly/tags/beanshell/ScriptTag.java
  
  Index: ScriptTag.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/java/org/apache/commons/jelly/tags/beanshell/ScriptTag.java,v
 1.1 2003/01/11 13:27:27 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/11 13:27:27 $
   *
   * ====================================================================
   *
   * 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 [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: ScriptTag.java,v 1.1 2003/01/11 13:27:27 dion Exp $
   */
  package org.apache.commons.jelly.tags.beanshell;
  
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  /** 
   * A tag which invokes a BeanShell script..
   *
   * @author Jason Horman
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class ScriptTag extends TagSupport {
  
      public ScriptTag() {
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
          JellyInterpreter interpreter = 
BeanShellExpressionFactory.getInterpreter(context);
          
          // @todo it'd be really nice to create a JellyNameSpace to pass into
          // this method so that any variables declared by beanshell could be exported
          // into the JellyContext
          String text = getBodyText();
          interpreter.eval(text);   
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/java/org/apache/commons/jelly/tags/beanshell/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
  
    <p>A tag library for working with BeanShell expressions and scripts within 
Jelly</p>
    
  </body>
  </html>
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/java/org/apache/commons/jelly/tags/beanshell/JellyInterpreter.java
  
  Index: JellyInterpreter.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/java/org/apache/commons/jelly/tags/beanshell/JellyInterpreter.java,v
 1.1 2003/01/11 13:27:29 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/11 13:27:29 $
   *
   * ====================================================================
   *
   * 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 [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: JellyInterpreter.java,v 1.1 2003/01/11 13:27:29 dion Exp $
   */
  package org.apache.commons.jelly.tags.beanshell;
  
  import bsh.EvalError;
  import bsh.Interpreter;
  
  import java.util.Iterator;
  
  import org.apache.commons.jelly.JellyContext;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /** Integrates BeanShell's interpreter with Jelly's JellyContext
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class JellyInterpreter extends Interpreter {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog( JellyInterpreter.class );
  
      private JellyContext context;
      
      public JellyInterpreter() {
      }
  
      public JellyContext getJellyContext() {
          return context;
      }
      
      public void setJellyContext(JellyContext 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);
              name = convertVariableName(name);
              if (name != null) {
                  set( name, value );
              }
          }
          
          // lets pass in the Jelly context 
          set( "context", context );
      }
  
  /*
    
      // 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 );
      }
  */
  
      /**
       * Converts variables to a beanshell allowable format or hides names that 
       * can't be converted, by returning null.
       * For now lets just turn '.' into '_'
       */
      protected String convertVariableName(String name) {
          return name.replace('.', '_');
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpressionFactory.java
  
  Index: BeanShellExpressionFactory.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpressionFactory.java,v
 1.1 2003/01/11 13:27:29 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/11 13:27:29 $
   *
   * ====================================================================
   *
   * 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 [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: BeanShellExpressionFactory.java,v 1.1 2003/01/11 13:27:29 dion Exp $
   */
  package org.apache.commons.jelly.tags.beanshell;
  
  import bsh.EvalError;
  
  import org.apache.commons.jelly.JellyContext;
  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:[EMAIL PROTECTED]";>James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class BeanShellExpressionFactory implements ExpressionFactory {
  
      /**
       * A helper method to return the JellyInterpreter for the given JellyContext
       */
      public static JellyInterpreter getInterpreter(JellyContext context) throws 
EvalError {
    
          /** 
           * @todo when we can unify the BeanShell and Jelly variable scopes we can 
share a single
           * BeanShell context for each JellyContext. 
           * For now lets create a new one each time, which is slower.
           */
          JellyInterpreter interpreter = new JellyInterpreter();
          interpreter.setJellyContext(context);
          return interpreter;
  /*        
          JellyInterpreter interpreter 
              = (JellyInterpreter) context.getVariable( 
"org.apache.commons.jelly.beanshell.JellyInterpreter" );
          if ( interpreter == null ) {
              interpreter = new JellyInterpreter();
              interpreter.setJellyContext(context);
              context.setVariable( 
"org.apache.commons.jelly.beanshell.JellyInterpreter", interpreter );
          }            
          return interpreter;
  */        
      }
      
      
      // ExpressionFactory interface
      //------------------------------------------------------------------------- 
      public Expression createExpression(String text) throws Exception {
          return new BeanShellExpression(text);
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellTagLibrary.java
  
  Index: BeanShellTagLibrary.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellTagLibrary.java,v
 1.1 2003/01/11 13:27:29 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/11 13:27:29 $
   *
   * ====================================================================
   *
   * 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 [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: BeanShellTagLibrary.java,v 1.1 2003/01/11 13:27:29 dion 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:[EMAIL PROTECTED]";>James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class BeanShellTagLibrary extends CoreTagLibrary {
  
      private ExpressionFactory expressionFactory = new BeanShellExpressionFactory();
  
      public BeanShellTagLibrary() {
          registerTag("script", ScriptTag.class);
      }
      
      /** Allows derived tag libraries to use their own factory */
      protected ExpressionFactory getExpressionFactory() {
          return expressionFactory;
      }
  
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpression.java
  
  Index: BeanShellExpression.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/java/org/apache/commons/jelly/tags/beanshell/BeanShellExpression.java,v
 1.1 2003/01/11 13:27:29 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/11 13:27:29 $
   *
   * ====================================================================
   *
   * 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 [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: BeanShellExpression.java,v 1.1 2003/01/11 13:27:29 dion Exp $
   */
  package org.apache.commons.jelly.tags.beanshell;
  
  import org.apache.commons.jelly.JellyContext;
  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:[EMAIL PROTECTED]";>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;
      
      public BeanShellExpression(String text) {
          this.text = text;
      }
  
      // Expression interface
      //------------------------------------------------------------------------- 
      public String getExpressionText() {
          return "${" + text + "}";
      }
      
      public Object evaluate(JellyContext context) {
          try {
              JellyInterpreter interpreter = new JellyInterpreter();
              interpreter.setJellyContext(context);
              
              if ( log.isDebugEnabled() ) {            
                  log.debug( "Evaluating beanshell: " + 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/jelly-tags/beanshell/src/test/org/apache/commons/jelly/tags/beanshell/suite.jelly
  
  Index: suite.jelly
  ===================================================================
  <?xml version="1.0"?>
  
  <test:suite 
        xmlns:j="jelly:core"
        xmlns:b="jelly:beanshell" 
        xmlns:test="jelly:junit">
  
  <test:case name="testPropertyWithDot">
  
        <j:set var="foo.bar" value="hello"/>
        
        <b:script>
                System.out.println( "foo.bar: " + context.getVariable("foo.bar") );
  
                if (context.getVariable("foo.bar") == null) {
                        throw new Exception("Failed: no foo.bar defined: " + foo_bar);
                }
                context.setVariable("foo.bar", "worked");
    </b:script>
  
        <test:assertEquals expected="worked" actual="${foo.bar}"/>
                
  </test:case>
  
  <test:case name="testDotConversion">
  
        <j:set var="foo.bar" value="hello"/>
        
        <b:script>
                System.out.println( "foo.bar: " + foo_bar );
  
                if (foo_bar == null) {
                         throw new Exception("Failed: no foo.bar defined: " + 
foo_bar);
                }
                context.setVariable("foo.bar", "worked");
    </b:script>
  
        <test:assertEquals expected="worked" actual="${foo.bar}"/>
                
  </test:case>
  
  </test:suite>
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/test/org/apache/commons/jelly/tags/beanshell/TestJelly.java
  
  Index: TestJelly.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/test/org/apache/commons/jelly/tags/beanshell/TestJelly.java,v
 1.1 2003/01/11 13:27:29 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/11 13:27:29 $
   *
   * ====================================================================
   *
   * 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 [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: TestJelly.java,v 1.1 2003/01/11 13:27:29 dion Exp $
   */
  package org.apache.commons.jelly.tags.beanshell;
  
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.jelly.tags.junit.JellyTestSuite;
  
  /** 
   * A helper class to run jelly test cases as part of Ant's JUnit tests
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class TestJelly extends JellyTestSuite {
  
      public static void main( String[] args ) throws Exception {
          TestRunner.run( suite() );
      }
      
      public static TestSuite suite() throws Exception {
          return createTestSuite(TestJelly.class, "suite.jelly");        
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/test/org/apache/commons/jelly/tags/beanshell/TestBeanShellEL.java
  
  Index: TestBeanShellEL.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/beanshell/src/test/org/apache/commons/jelly/tags/beanshell/TestBeanShellEL.java,v
 1.1 2003/01/11 13:27:29 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/11 13:27:29 $
   *
   * ====================================================================
   *
   * 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 [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: TestBeanShellEL.java,v 1.1 2003/01/11 13:27:29 dion Exp $
   */
  package org.apache.commons.jelly.tags.beanshell;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.expression.Expression;
  import org.apache.commons.jelly.expression.ExpressionFactory;
  import org.apache.commons.jelly.tags.beanshell.BeanShellExpressionFactory;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  
  /** Tests the BeanShell EL
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class TestBeanShellEL extends TestCase {
      
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog( TestBeanShellEL.class );
  
      /** Jelly context */
      protected JellyContext context;
      
      /** The factory of Expression objects */
      protected ExpressionFactory factory;
      
      
      public static void main( String[] args ) {
          TestRunner.run( suite() );
      }
      
      public static Test suite() {
          return new TestSuite(TestBeanShellEL.class);
      }
      
      public TestBeanShellEL(String testName) {
          super(testName);
      }
      
      public void setUp() {
          context = new JellyContext();
          context.setVariable( "foo", "abc" );
          context.setVariable( "bar", new Integer( 123 ) );
          factory = new BeanShellExpressionFactory();
      }
      
      public void testEL() throws Exception {
          assertExpression( "foo", "abc" );
          assertExpression( "bar * 2", new Integer( 246 ) );
          assertExpression( "bar == 123", Boolean.TRUE );
          assertExpression( "bar == 124", Boolean.FALSE );
          assertExpression( "foo.equals( \"abc\" )", Boolean.TRUE );
          assertExpression( "foo.equals( \"xyz\" )", Boolean.FALSE );
      }    
      
      /** Evaluates the given expression text and tests it against the expected value 
*/
      protected void assertExpression( String expressionText, Object expectedValue ) 
throws Exception {
          Expression expr = factory.createExpression( expressionText );
          Object value = expr.evaluate( context );
          assertEquals( "Value of expression: " + expressionText, expectedValue, value 
);
      }        
  }
  
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/beanshell/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="java:jar">
  
  </project>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/beanshell/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE project [
    <!-- see file for description -->
    <!ENTITY commonDeps SYSTEM "file:../../commonDependencies.ent">
  ]>
  <project>
    <extend>../tag-project.xml</extend>
    <id>commons-jelly-tags-beanshell</id>
    <name>commons-jelly-tags-beanshell</name>
    <package>org.apache.commons.jelly.tags.beanshell</package>
  
    <description>
        This is a Jelly interface for BeanShell.
    </description>
    <shortDescription>Commons Jelly BeanShell Tag Library</shortDescription>
    
    
<siteDirectory>/www/jakarta.apache.org/commons/sandbox/jelly/tags/beanshell</siteDirectory>
    
<distributionDirectory>/www/jakarta.apache.org/builds/jakarta-commons-sandbox/jelly/tags/beanshell</distributionDirectory>
    <repository>
      
<connection>scm:cvs:pserver:[EMAIL PROTECTED]:/home/cvspublic:jakarta-commons-sandbox/jelly/jelly-tags/beanshell/</connection>
      
<url>http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/jelly/jelly-tags/beanshell/</url>
    </repository>
    
      
    <dependencies>
    
      &commonDeps;
    
      <!-- START for compilation -->
    
      <dependency>
        <id>commons-jelly</id>
        <version>SNAPSHOT</version>
      </dependency>
  
      <dependency>
        <id>bsh</id>
        <version>1.2-b3</version>
      </dependency>
  
    </dependencies>
    
  </project>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/beanshell/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  maven.log
  target
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/jelly-tags/beanshell/project.properties
  
  Index: project.properties
  ===================================================================
  # -------------------------------------------------------------------
  # P R O J E C T  P R O P E R T I E S
  # -------------------------------------------------------------------
  
  maven.junit.fork=true
  
  maven.compile.deprecation = on
  
  # Installation dir
  maven.dist.install.dir = /usr/local/jelly
  
  maven.checkstyle.properties=../tag-checkstyle.properties
  
  

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

Reply via email to