commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/jelly/src/test/org/apache/commons/jelly suite.jelly
Date Tue, 31 Aug 2004 04:55:02 GMT
dion        2004/08/30 21:55:02

  Modified:    jelly/src/java/org/apache/commons/jelly/expression
                        ExpressionSupport.java
               jelly/src/test/org/apache/commons/jelly suite.jelly
  Log:
  Apply Jelly-98. Allow comma separated strings in forEach
  
  Revision  Changes    Path
  1.13      +13 -16    jakarta-commons/jelly/src/java/org/apache/commons/jelly/expression/ExpressionSupport.java
  
  Index: ExpressionSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/java/org/apache/commons/jelly/expression/ExpressionSupport.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ExpressionSupport.java	24 Feb 2004 14:02:07 -0000	1.12
  +++ ExpressionSupport.java	31 Aug 2004 04:55:02 -0000	1.13
  @@ -27,6 +27,7 @@
   import org.apache.commons.collections.iterators.SingletonIterator;
   
   import org.apache.commons.jelly.JellyContext;
  +import org.apache.commons.lang.StringUtils;
   
   /** <p><code>ExpressionSupport</code>
     * an abstract base class for Expression implementations
  @@ -100,30 +101,26 @@
           Object value = evaluateRecurse(context);
           if ( value == null ) {
               return EMPTY_ITERATOR;
  -        }
  -        else
  -        if ( value instanceof Iterator ) {
  +        } else if ( value instanceof Iterator ) {
               return (Iterator) value;
  -        }
  -        else if ( value instanceof List ) {
  +        } else if ( value instanceof List ) {
               List list = (List) value;
               return list.iterator();
  -        }
  -        else if ( value instanceof Map ) {
  +        } else if ( value instanceof Map ) {
               Map map = (Map) value;
               return map.entrySet().iterator();
  -        }
  -        else if ( value.getClass().isArray() ) {
  +        } else if ( value.getClass().isArray() ) {
               return new ArrayIterator( value );
  -        }
  -        else if ( value instanceof Enumeration ) {
  +        } else if ( value instanceof Enumeration ) {
               return new EnumerationIterator((Enumeration ) value);
  -        }
  -        else if ( value instanceof Collection ) {
  +        } else if ( value instanceof Collection ) {
             Collection collection = (Collection) value;
             return collection.iterator();
  -        }
  -        else {
  +        } else if ( value instanceof String ) {
  +           String[] array = StringUtils.split((String) value, "," );
  +           array = StringUtils.stripAll( array );
  +           return new ArrayIterator( array );
  +        } else {
               // XXX: should we return single iterator?
               return new SingletonIterator( value );
           }
  
  
  
  1.20      +10 -1     jakarta-commons/jelly/src/test/org/apache/commons/jelly/suite.jelly
  
  Index: suite.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/src/test/org/apache/commons/jelly/suite.jelly,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- suite.jelly	31 Aug 2004 04:52:29 -0000	1.19
  +++ suite.jelly	31 Aug 2004 04:55:02 -0000	1.20
  @@ -335,5 +335,14 @@
       <j:set var="shouldBeNothing"><j:mute>blop</j:mute></j:set>
       <test:assertEquals expected="" actual="${shouldBeNothing}"/>
     </test:case>
  -    
  +
  +  <test:case name="testForEachWithString">
  +    <j:set var="j" value=""/>
  +        
  +    <j:forEach var="i" items="a,b,c">
  +      <j:set var="j" value="${j}${i}"/>
  +    </j:forEach>
  +
  +    <test:assertEquals expected="abc" actual="${j}"/>
  +  </test:case>    
   </test:suite>
  
  
  

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


Mime
View raw message