commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser XMLParser.java
Date Wed, 24 Apr 2002 13:03:03 GMT
jstrachan    02/04/24 06:03:03

  Modified:    jelly    build.xml
               jelly/src/java/org/apache/commons/jelly Context.java
               jelly/src/java/org/apache/commons/jelly/parser
                        XMLParser.java
  Added:       jelly/src/java/org/apache/commons/jelly/expression/jexl
                        JexlExpression.java JexlExpressionFactory.java
  Log:
  Added support for Jexl and made it the default expression language when using Jelly
  
  Revision  Changes    Path
  1.11      +22 -13    jakarta-commons-sandbox/jelly/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/build.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- build.xml	24 Apr 2002 11:59:12 -0000	1.10
  +++ build.xml	24 Apr 2002 13:03:03 -0000	1.11
  @@ -3,7 +3,7 @@
   
   <!--
           "Jelly" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.10 2002/04/24 11:59:12 jstrachan Exp $
  +        $Id: build.xml,v 1.11 2002/04/24 13:03:03 jstrachan Exp $
   -->
   
   
  @@ -24,10 +24,12 @@
     <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="sandbox.home"            value=".."/>
     <property name="beanutils.home"          value="${commons.home}/beanutils"/>
     <property name="collections.home"        value="${commons.home}/collections"/>
     <property name="logging.home"            value="${commons.home}/logging"/>
     <property name="digester.home"           value="${commons.home}/digester"/>
  +  <property name="jexl.home"               value="${sandbox.home}/jexl"/>
   
   
   <!-- ========== Derived Values ============================================ -->
  @@ -49,6 +51,7 @@
     <property name="commons-logging.jar"     value="${logging.home}/dist/commons-logging.jar"/>
     <property name="commons-digester.api"    value="${digester.home}/dist/docs/api"/>
     <property name="commons-digester.jar"    value="${digester.home}/dist/commons-digester.jar"/>
  +  <property name="commons-jexl.jar"        value="${jexl.home}/dist/commons-jexl.jar"/>
     
   
   <!-- ========== Component Declarations ==================================== -->
  @@ -100,16 +103,19 @@
       <pathelement location="${jaxp.jaxp.jar}"/>
       <pathelement location="${jaxp.parser.jar}"/>
       <pathelement location="${dom4j.jar}"/>
  -    <pathelement location="${bsf.jar}"/>
  -    <pathelement location="${pnuts.jar}"/>
  -    <pathelement location="${rhino.jar}"/>
  -    <pathelement location="${tools.jar}"/>
  -    <pathelement location="${beanshell.jar}"/>
  +    <pathelement location="${jexl.jar}"/>
       <pathelement location="${commons-beanutils.jar}"/>
       <pathelement location="${commons-collections.jar}"/>
       <pathelement location="${commons-logging.jar}"/>
       <pathelement location="${commons-digester.jar}"/>
       <pathelement location="${junit.jar}"/>
  +    
  +    <!-- optional JARs -->
  +    <pathelement location="${beanshell.jar}"/>
  +    <pathelement location="${bsf.jar}"/>
  +    <pathelement location="${pnuts.jar}"/>
  +    <pathelement location="${rhino.jar}"/>
  +    <pathelement location="${tools.jar}"/>
     </path>
   
   
  @@ -120,19 +126,23 @@
     <path id="test.classpath">
       <pathelement location="${build.home}/classes"/>
       <pathelement location="${build.home}/tests"/>
  -    <pathelement location="${junit.jar}"/>
  +    <pathelement location="${build.home}/classes"/>
       <pathelement location="${jaxp.jaxp.jar}"/>
       <pathelement location="${jaxp.parser.jar}"/>
       <pathelement location="${dom4j.jar}"/>
  -    <pathelement location="${bsf.jar}"/>
  -    <pathelement location="${pnuts.jar}"/>
  -    <pathelement location="${rhino.jar}"/>
  -    <pathelement location="${tools.jar}"/>
  -    <pathelement location="${beanshell.jar}"/>
  +    <pathelement location="${jexl.jar}"/>
       <pathelement location="${commons-beanutils.jar}"/>
       <pathelement location="${commons-collections.jar}"/>
       <pathelement location="${commons-logging.jar}"/>
       <pathelement location="${commons-digester.jar}"/>
  +    <pathelement location="${junit.jar}"/>
  +    
  +    <!-- optional JARs -->
  +    <pathelement location="${beanshell.jar}"/>
  +    <pathelement location="${bsf.jar}"/>
  +    <pathelement location="${pnuts.jar}"/>
  +    <pathelement location="${rhino.jar}"/>
  +    <pathelement location="${tools.jar}"/>
     </path>
   
     <!-- Should all tests fail if one does? -->
  @@ -343,7 +353,6 @@
       <java classname="org.apache.commons.jelly.Jelly" fork="yes">
         <classpath refid="test.classpath"/>
         <arg value="src/test/org/apache/commons/jelly/hello_world.jelly"/> 
  -      <sysproperty key="org.apache.commons.logging.simplelog.defaultlog" value="debug"/>
       </java>
      </target>
   
  
  
  
  1.6       +19 -5     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java
  
  Index: Context.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Context.java	24 Apr 2002 11:59:12 -0000	1.5
  +++ Context.java	24 Apr 2002 13:03:03 -0000	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java,v
1.5 2002/04/24 11:59:12 jstrachan Exp $
  - * $Revision: 1.5 $
  - * $Date: 2002/04/24 11:59:12 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/Context.java,v
1.6 2002/04/24 13:03:03 jstrachan Exp $
  + * $Revision: 1.6 $
  + * $Date: 2002/04/24 13:03:03 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: Context.java,v 1.5 2002/04/24 11:59:12 jstrachan Exp $
  + * $Id: Context.java,v 1.6 2002/04/24 13:03:03 jstrachan Exp $
    */
   package org.apache.commons.jelly;
   
  @@ -68,7 +68,7 @@
   /** <p><code>Context</code> represents the Jelly context.</p>
     *
     * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  -  * @version $Revision: 1.5 $
  +  * @version $Revision: 1.6 $
     */
   public class Context {
   
  @@ -108,5 +108,19 @@
        */
       public Iterator getVariableNames() {
           return variables.keySet().iterator();
  +    }
  +    
  +    /**
  +     * @return the Map of variables in this scope
  +     */
  +    public Map getVariables() {
  +        return variables;
  +    }
  +    
  +    /**
  +     * Sets the Map of variables to use
  +     */
  +    public void setVariables(Map variables) {
  +        this.variables = variables;
       }
   }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java
  
  Index: JexlExpression.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/jexl/JexlExpression.java,v
1.1 2002/04/24 13:03:03 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/04/24 13:03:03 $
   *
   * ====================================================================
   *
   * 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: JexlExpression.java,v 1.1 2002/04/24 13:03:03 jstrachan Exp $
   */
  package org.apache.commons.jelly.expression.jexl;
  
  import org.apache.commons.jelly.Context;
  import org.apache.commons.jelly.expression.ExpressionSupport;
  
  import org.apache.commons.jexl.Expression;
  import org.apache.commons.jexl.JexlContext;
  import org.apache.commons.jexl.context.HashMapContext;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  
  /** 
   * Represents a <a href="http://jakarta.apache.org/commons/jexl.html">Jexl</a>

   * expression which fully supports the Expression Language in JSTL and JSP 
   * along with some extra features like object method invocation.
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class JexlExpression extends ExpressionSupport {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog( JexlExpression.class );
  
      /** The Jexl expression object */
      private Expression expression;
      
      public JexlExpression(Expression expression) {
          this.expression = expression;
      }
  
      // Expression interface
      //------------------------------------------------------------------------- 
      public Object evaluate(Context context) {
          try {
              // ##### this sucks - avoid doing a copy by value ASAP
              HashMapContext jexlContext = new HashMapContext();
              jexlContext.putAll( context.getVariables() );
              
              if ( log.isDebugEnabled() ) {            
                  log.debug( "Evaluating EL: " + expression );
              }
              
              return expression.evaluate( jexlContext );
          }
          catch (Exception e) {
              log.warn( "Caught exception evaluating: " + expression + ". Reason: " + e, e
);
              return null;
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/jexl/JexlExpressionFactory.java
  
  Index: JexlExpressionFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/jexl/JexlExpressionFactory.java,v
1.1 2002/04/24 13:03:03 jstrachan Exp $
   * $Revision: 1.1 $
   * $Date: 2002/04/24 13:03:03 $
   *
   * ====================================================================
   *
   * 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: JexlExpressionFactory.java,v 1.1 2002/04/24 13:03:03 jstrachan Exp $
   */
  package org.apache.commons.jelly.expression.jexl;
  
  import org.apache.commons.jelly.expression.Expression;
  import org.apache.commons.jelly.expression.ExpressionFactory;
  
  /** 
   * Represents a factory of <a href="http://jakarta.apache.org/commons/jexl.html">Jexl</a>

   * expression which fully supports the Expression Language in JSTL and JSP.
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class JexlExpressionFactory implements ExpressionFactory {
  
      // ExpressionFactory interface
      //------------------------------------------------------------------------- 
      public Expression createExpression(String text) throws Exception {
          return new JexlExpression(
              org.apache.commons.jexl.ExpressionFactory.createExpression( text )
          );
      }
  }
  
  
  
  1.9       +7 -7      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XMLParser.java	24 Apr 2002 11:59:12 -0000	1.8
  +++ XMLParser.java	24 Apr 2002 13:03:03 -0000	1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v
1.8 2002/04/24 11:59:12 jstrachan Exp $
  - * $Revision: 1.8 $
  - * $Date: 2002/04/24 11:59:12 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v
1.9 2002/04/24 13:03:03 jstrachan Exp $
  + * $Revision: 1.9 $
  + * $Date: 2002/04/24 13:03:03 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - * $Id: XMLParser.java,v 1.8 2002/04/24 11:59:12 jstrachan Exp $
  + * $Id: XMLParser.java,v 1.9 2002/04/24 13:03:03 jstrachan Exp $
    */
   package org.apache.commons.jelly.parser;
   
  @@ -94,7 +94,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.tags.beanshell.BeanShellExpressionFactory;
  +import org.apache.commons.jelly.expression.jexl.JexlExpressionFactory;
   import org.apache.commons.jelly.tags.core.CoreTagLibrary;
   import org.apache.commons.jelly.tags.xml.XMLTagLibrary;
   
  @@ -117,7 +117,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.8 $
  + * @version $Revision: 1.9 $
    */
   public class XMLParser extends DefaultHandler {
       
  @@ -1054,7 +1054,7 @@
       }
           
       protected ExpressionFactory createExpressionFactory() {
  -        return new BeanShellExpressionFactory();
  +        return new JexlExpressionFactory();
       }
       
       
  
  
  

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


Mime
View raw message