myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svieu...@apache.org
Subject cvs commit: incubator-myfaces/src/myfaces/org/apache/myfaces/el ELParserHelper.java
Date Mon, 11 Apr 2005 17:39:36 GMT
svieujot    2005/04/11 10:39:36

  Modified:    src/myfaces/org/apache/myfaces/el ELParserHelper.java
  Added:       src/junit/org/apache/myfaces/el ELParserHelperTest.java
  Log:
  ELParserHelper : Fix a String IndexOutOfBoundsException & several bugs in toJspELExpression.
  Add a JUnit Test.
  
  Revision  Changes    Path
  1.1                  incubator-myfaces/src/junit/org/apache/myfaces/el/ELParserHelperTest.java
  
  Index: ELParserHelperTest.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.myfaces.el;
  
  import junit.framework.TestCase;
  
  
  /**
   * @author Manfred Geiler (latest modification by $Author: svieujot $)
   * @author Anton Koinov
   * @version $Revision: 1.1 $ $Date: 2005/04/11 17:39:35 $
   */
  public class ELParserHelperTest extends TestCase
  {
      //~ Constructors -------------------------------------------------------------------------------
  
      public ELParserHelperTest(String name)
      {
          super(name);
      }
  
      //~ Methods ------------------------------------------------------------------------------------
  
      public void testToJspElExpression() throws Exception
      {
          assertEquals("${}", ELParserHelper.toJspElExpression("#{}"));
  		assertEquals("{}", ELParserHelper.toJspElExpression("{}"));
  		assertEquals("{aa} {bb}", ELParserHelper.toJspElExpression("{aa} {bb}"));
  		assertEquals("{aa}{bb}", ELParserHelper.toJspElExpression("{aa}{bb}"));
  		assertEquals("1${'<'}{0,number,integer}", ELParserHelper.toJspElExpression("1#{'<'}{0,number,integer}"));
  		
  		assertEquals(
  												 "{0,choice,0#${scrollerNoItem_}|1#${scrollerOneItem_}|1${'<'}{0,number,integer}
${scrollerItems_}} ${dataScrollerMsg.found_displaying} {1} to {2}. ${dataScrollerMsg.Page}
{3} / {4}",
  				ELParserHelper.toJspElExpression("{0,choice,0##{scrollerNoItem_}|1##{scrollerOneItem_}|1#{'<'}{0,number,integer}
#{scrollerItems_}} #{dataScrollerMsg.found_displaying} {1} to {2}. #{dataScrollerMsg.Page}
{3} / {4}"));
      }
      
  }
  
  
  1.7       +30 -20    incubator-myfaces/src/myfaces/org/apache/myfaces/el/ELParserHelper.java
  
  Index: ELParserHelper.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/myfaces/org/apache/myfaces/el/ELParserHelper.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ELParserHelper.java	13 Oct 2004 11:51:00 -0000	1.6
  +++ ELParserHelper.java	11 Apr 2005 17:39:36 -0000	1.7
  @@ -57,6 +57,10 @@
    * @version $Revision$ $Date$
    * 
    * $Log$
  + * Revision 1.7  2005/04/11 17:39:36  svieujot
  + * ELParserHelper : Fix a String IndexOutOfBoundsException & several bugs in toJspELExpression.
  + * Add a JUnit Test.
  + *
    * Revision 1.6  2004/10/13 11:51:00  matze
    * renamed packages to org.apache
    *
  @@ -127,25 +131,27 @@
       static String toJspElExpression(String expressionString)
       {
           StringBuffer sb = new StringBuffer(expressionString.length());
  -        int oldPos = 0;
  +        int remainsPos = 0;
   
  -        for (int pos = expressionString.indexOf('{'); pos >= 0; 
  -            pos = expressionString.indexOf('{', oldPos = (pos + 1)))
  +        for (int posOpenBrace = expressionString.indexOf('{'); posOpenBrace >= 0; 
  +            posOpenBrace = expressionString.indexOf('{', remainsPos))
           {
  -            sb.append(expressionString.substring(oldPos, pos - 1));
  -
  -            if (pos > 0)
  +            if (posOpenBrace > 0)
               {
  -                if (expressionString.charAt(pos - 1) == '$')
  +				if( posOpenBrace-1 > remainsPos )
  +					sb.append(expressionString.substring(remainsPos, posOpenBrace - 1));
  +
  +                if (expressionString.charAt(posOpenBrace - 1) == '$')
                   {
                       sb.append("${'${'}");
  -                    continue;
  +					remainsPos = posOpenBrace+1;
  +					continue;
                   }
  -                else if (expressionString.charAt(pos - 1) == '#')
  +                else if (expressionString.charAt(posOpenBrace - 1) == '#')
                   {
   //                    // TODO: should use \\ as escape for \ always, not just when before
#{
   //                    // allow use of '\' as escape symbol for #{ (for compatibility with
Sun's extended implementation)
  -//                    if (isEscaped(expressionString, pos - 1)) 
  +//                    if (isEscaped(expressionString, posOpenBrace - 1)) 
   //                    {
   //                      escapes: {
   //                            for (int i = sb.length() - 1; i >= 0; i--)
  @@ -164,21 +170,26 @@
   //                    else
   //                    {
                           sb.append("${");
  -                        oldPos = pos + 1;
  -                        pos = indexOfMatchingClosingBrace(expressionString, pos);
  -                        sb.append(expressionString.substring(oldPos, pos + 1));
  +						int posCloseBrace = indexOfMatchingClosingBrace(expressionString, posOpenBrace);
  +                        sb.append(expressionString.substring(posOpenBrace + 1, posCloseBrace
+ 1));
  +						remainsPos = posCloseBrace + 1;
  +						continue;
   //                    }
  -                    continue;
  +                }else{
  +					if( posOpenBrace > remainsPos )
  +						sb.append( expressionString.charAt(posOpenBrace - 1) );
                   }
               }
   
  -            // Standalone brace
  -            sb.append('{');
  +			// Standalone brace
  +			sb.append('{');
  +			remainsPos = posOpenBrace + 1;
           }
   
  +		sb.append(expressionString.substring(remainsPos));
  +		
           // Create a new String to shrink mem size since we are caching
  -        return new String(sb.append(expressionString.substring(oldPos))
  -            .toString());
  +        return new String(sb.toString());
       }
   
       private static int findQuote(String expressionString, int start)
  
  
  

Mime
View raw message