jstrachan    02/02/13 09:03:10

  Modified:    jelly    build.xml
               jelly/src/java/org/apache/commons/jelly TagLibrary.java
               jelly/src/java/org/apache/commons/jelly/expression/beanshell
                        BeanShellExpressionFactory.java
               jelly/src/java/org/apache/commons/jelly/parser
                        XMLParser.java
               jelly/src/java/org/apache/commons/jelly/tags/core
                        CoreTagLibrary.java
               jelly/src/java/org/apache/commons/jelly/tags/xml
                        XMLTagLibrary.java
               jelly/src/test/org/apache/commons/jelly testing123.jelly
               jelly/src/test/org/apache/commons/jelly/beanshell
                        TestBeanShellEL.java
  Added:       jelly/src/test/org/apache/commons/jelly
                        show_properties.jelly
  Log:
  Modified the core tags so that the common tags expect an expression for their 
attributes. Tags which do not explicitly expect an expression for their attribute 
values can take {} around the expressions which will then be evaluated as an 
expression. This is kinda similar to 'Attribute Value Templates' in XSLT. It certainly 
makes common core tags look much simpler. Also added a sample script to output the 
current system properties as a HTML table to show the general idea
  
  Revision  Changes    Path
  1.4       +9 -1      jakarta-commons-sandbox/jelly/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/build.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- build.xml 13 Feb 2002 16:00:39 -0000      1.3
  +++ build.xml 13 Feb 2002 17:03:09 -0000      1.4
  @@ -3,7 +3,7 @@
   
   <!--
           "Digester" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.3 2002/02/13 16:00:39 jstrachan Exp $
  +        $Id: build.xml,v 1.4 2002/02/13 17:03:09 jstrachan Exp $
   -->
   
   
  @@ -299,6 +299,14 @@
         <arg value="one"/> 
         <arg value="two"/> 
         <arg value="three"/> 
  +    </java>
  +   </target>
  +
  +   <target name="demo.sysprop" depends="compile" 
  +      description="Runs demo which displays system properties">
  +    <java classname="org.apache.commons.jelly.Jelly" fork="yes">
  +      <classpath refid="test.classpath"/>
  +      <arg value="src/test/org/apache/commons/jelly/show_properties.jelly"/> 
       </java>
      </target>
   
  
  
  
  1.2       +7 -6      
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java
  
  Index: TagLibrary.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TagLibrary.java   11 Feb 2002 00:27:40 -0000      1.1
  +++ TagLibrary.java   13 Feb 2002 17:03:09 -0000      1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java,v
 1.1 2002/02/11 00:27:40 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:40 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/TagLibrary.java,v
 1.2 2002/02/13 17:03:09 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/13 17:03:09 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: TagLibrary.java,v 1.1 2002/02/11 00:27:40 jstrachan Exp $
  + * $Id: TagLibrary.java,v 1.2 2002/02/13 17:03:09 jstrachan Exp $
    */
   package org.apache.commons.jelly;
   
  @@ -66,6 +66,7 @@
   import java.util.Map;
   
   import org.apache.commons.jelly.expression.Expression;
  +import org.apache.commons.jelly.expression.ExpressionFactory;
   import org.apache.commons.jelly.impl.TagScript;
   
   import org.xml.sax.Attributes;
  @@ -73,7 +74,7 @@
   /** <p><code>Taglib</code> represents the metadata for a Jelly custom tag 
library.</p>
     *
     * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
   public abstract class TagLibrary {
   
  @@ -90,7 +91,7 @@
       }
       
       /** Allows taglibs to use their own expression evaluation mechanism */
  -    public Expression createExpression(String tagName, String attributeName, String 
attributeValue) {
  +    public Expression createExpression(ExpressionFactory factory, String tagName, 
String attributeName, String attributeValue) throws Exception {
           // will use the default expression instead
           return null;
       }
  
  
  
  1.3       +6 -11     
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/beanshell/BeanShellExpressionFactory.java
  
  Index: BeanShellExpressionFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/beanshell/BeanShellExpressionFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BeanShellExpressionFactory.java   13 Feb 2002 16:00:39 -0000      1.2
  +++ BeanShellExpressionFactory.java   13 Feb 2002 17:03:09 -0000      1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/beanshell/BeanShellExpressionFactory.java,v
 1.2 2002/02/13 16:00:39 jstrachan Exp $
  - * $Revision: 1.2 $
  - * $Date: 2002/02/13 16:00:39 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/expression/beanshell/BeanShellExpressionFactory.java,v
 1.3 2002/02/13 17:03:09 jstrachan Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/02/13 17:03:09 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: BeanShellExpressionFactory.java,v 1.2 2002/02/13 16:00:39 jstrachan Exp $
  + * $Id: BeanShellExpressionFactory.java,v 1.3 2002/02/13 17:03:09 jstrachan Exp $
    */
   package org.apache.commons.jelly.expression.beanshell;
   
  @@ -67,7 +67,7 @@
   /** 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.2 $
  +  * @version $Revision: 1.3 $
     */
   public class BeanShellExpressionFactory implements ExpressionFactory {
   
  @@ -77,11 +77,6 @@
       // ExpressionFactory interface
       //------------------------------------------------------------------------- 
       public Expression createExpression(String text) throws Exception {
  -        int length = text.length();
  -        if ( length > 2 && text.charAt(0) == '{'  && text.charAt( length - 1 ) == 
'}' ) {
  -            text = text.substring( 1, length - 1 );
  -            return new BeanShellExpression(text, interpreter);
  -        }
  -        return null;
  +        return new BeanShellExpression(text, interpreter);
       }
   }
  
  
  
  1.5       +14 -9     
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLParser.java    13 Feb 2002 16:00:39 -0000      1.4
  +++ XMLParser.java    13 Feb 2002 17:03:09 -0000      1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v
 1.4 2002/02/13 16:00:39 jstrachan Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/02/13 16:00:39 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v
 1.5 2002/02/13 17:03:09 jstrachan Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/02/13 17:03:09 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - * $Id: XMLParser.java,v 1.4 2002/02/13 16:00:39 jstrachan Exp $
  + * $Id: XMLParser.java,v 1.5 2002/02/13 17:03:09 jstrachan Exp $
    */
   package org.apache.commons.jelly.parser;
   
  @@ -115,7 +115,7 @@
    * The SAXParser and XMLReader portions of this code come from Digester.</p>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class XMLParser extends DefaultHandler {
       
  @@ -932,7 +932,7 @@
                   for ( int i = 0; i < size; i++ ) {
                       String attributeName = list.getLocalName(i);
                       String attributeValue = list.getValue(i);
  -                    Expression expression = taglib.createExpression( localName, 
attributeName, attributeValue );
  +                    Expression expression = taglib.createExpression( 
getExpressionFactory(), localName, attributeName, attributeValue );
                       if ( expression == null ) {
                           expression = createExpression( localName, attributeName, 
attributeValue );
                       }
  @@ -954,9 +954,14 @@
       }
       
       protected Expression createExpression( String tagName, String attributeName, 
String attributeValue ) throws Exception {
  -        Expression answer = getExpressionFactory().createExpression( attributeValue 
);
  -        if ( answer != null ) {
  -            return answer;
  +        String text = attributeValue;
  +        int length = text.length();
  +        if ( length > 2 && text.charAt(0) == '{'  && text.charAt( length - 1 ) == 
'}' ) {
  +            text = text.substring( 1, length - 1 );
  +            Expression answer = getExpressionFactory().createExpression( text );
  +            if ( answer != null ) {
  +                return answer;
  +            }
           }
           return new ConstantExpression( attributeValue );
       }
  
  
  
  1.2       +12 -3     
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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CoreTagLibrary.java       12 Feb 2002 21:34:34 -0000      1.1
  +++ CoreTagLibrary.java       13 Feb 2002 17:03:09 -0000      1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java,v
 1.1 2002/02/12 21:34:34 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/12 21:34:34 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/CoreTagLibrary.java,v
 1.2 2002/02/13 17:03:09 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/13 17:03:09 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: CoreTagLibrary.java,v 1.1 2002/02/12 21:34:34 jstrachan Exp $
  + * $Id: CoreTagLibrary.java,v 1.2 2002/02/13 17:03:09 jstrachan Exp $
    */
   package org.apache.commons.jelly.tags.core;
   
  @@ -70,12 +70,13 @@
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.TagLibrary;
   import org.apache.commons.jelly.expression.Expression;
  +import org.apache.commons.jelly.expression.ExpressionFactory;
   
   
   /** Describes the Taglib. This class could be generated by XDoclet
     *
     * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
   public class CoreTagLibrary extends TagLibrary {
   
  @@ -84,5 +85,13 @@
           registerTag( "forEach", ForEachTag.class );
           registerTag( "jelly", JellyTag.class );
           registerTag( "set", SetTag.class );
  +    }
  +    
  +    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 );
  +        }
  +        // will use the default expression instead
  +        return null;
       }
   }
  
  
  
  1.2       +7 -6      
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java
  
  Index: XMLTagLibrary.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLTagLibrary.java        11 Feb 2002 00:27:41 -0000      1.1
  +++ XMLTagLibrary.java        13 Feb 2002 17:03:09 -0000      1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java,v
 1.1 2002/02/11 00:27:41 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/11 00:27:41 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java,v
 1.2 2002/02/13 17:03:09 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/13 17:03:09 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: XMLTagLibrary.java,v 1.1 2002/02/11 00:27:41 jstrachan Exp $
  + * $Id: XMLTagLibrary.java,v 1.2 2002/02/13 17:03:09 jstrachan Exp $
    */
   package org.apache.commons.jelly.tags.xml;
   
  @@ -70,6 +70,7 @@
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.TagLibrary;
   import org.apache.commons.jelly.expression.Expression;
  +import org.apache.commons.jelly.expression.ExpressionFactory;
   
   import org.dom4j.XPath;
   
  @@ -77,7 +78,7 @@
   /** Describes the Taglib. This class could be generated by XDoclet
     *
     * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
   public class XMLTagLibrary extends TagLibrary {
   
  @@ -88,7 +89,7 @@
           registerTag( "set", SetTag.class );
       }
       
  -    public Expression createExpression(String tagName, String attributeName, String 
attributeValue) {
  +    public Expression createExpression(ExpressionFactory factory, String tagName, 
String attributeName, String attributeValue) {
           if (attributeName.equals( "select" ) ) {
               return new XPathExpression( attributeValue );
           }
  
  
  
  1.2       +1 -3      
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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- testing123.jelly  13 Feb 2002 16:00:39 -0000      1.1
  +++ testing123.jelly  13 Feb 2002 17:03:09 -0000      1.2
  @@ -1,6 +1,4 @@
   <?xml version="1.0"?>
   <j:jelly xmlns:j="jelly:core">
  -  <j:forEach var="arg" items="{args}">
  -    <j:expr value="{arg}"/> 
  -  </j:forEach>
  +  <j:forEach var="arg" items="args"><j:expr value="arg"/> </j:forEach>
   </j:jelly>
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/show_properties.jelly
  
  Index: show_properties.jelly
  ===================================================================
  <?xml version="1.0"?>
  <j:jelly xmlns:j="jelly:core">
  <html>
    <body>
      <h1>System properties</h1>
      <table>
        <tr>
          <th>Name</th>
          <th>Value</th>
        </tr>
        <j:forEach var="iter" items="System.getProperties()">
          <tr>
            <td><j:expr value="iter.key"/></td>
            <td><j:expr value="iter.value"/></td>
          </tr>
        </j:forEach>
      </table>
    </body>
  </html>
  </j:jelly>
  
  
  1.2       +7 -7      
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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestBeanShellEL.java      13 Feb 2002 16:00:39 -0000      1.1
  +++ TestBeanShellEL.java      13 Feb 2002 17:03:09 -0000      1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/beanshell/TestBeanShellEL.java,v
 1.1 2002/02/13 16:00:39 jstrachan Exp $
  - * $Revision: 1.1 $
  - * $Date: 2002/02/13 16:00:39 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/beanshell/TestBeanShellEL.java,v
 1.2 2002/02/13 17:03:09 jstrachan Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/02/13 17:03:09 $
    *
    * ====================================================================
    *
  @@ -57,7 +57,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    * 
  - * $Id: TestBeanShellEL.java,v 1.1 2002/02/13 16:00:39 jstrachan Exp $
  + * $Id: TestBeanShellEL.java,v 1.2 2002/02/13 17:03:09 jstrachan Exp $
    */
   package org.apache.commons.jelly.beanshell;
   
  @@ -78,7 +78,7 @@
   /** Tests the BeanShell EL
     *
     * @author <a href="mailto:[EMAIL PROTECTED]";>James Strachan</a>
  -  * @version $Revision: 1.1 $
  +  * @version $Revision: 1.2 $
     */
   public class TestBeanShellEL extends TestCase {
       
  @@ -112,8 +112,8 @@
       }
       
       public void testEL() throws Exception {
  -        assertExpression( "{foo}", "abc" );
  -        assertExpression( "{bar * 2}", new Integer( 246 ) );
  +        assertExpression( "foo", "abc" );
  +        assertExpression( "bar * 2", new Integer( 246 ) );
       }    
       
       /** Evaluates the given expression text and tests it against the expected value 
*/
  
  
  

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

Reply via email to