[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...

Norman Richards norman.richards at jboss.com
Thu Feb 1 14:58:07 EST 2007


  User: nrichards
  Date: 07/02/01 14:58:07

  Modified:    src/main/org/jboss/seam/core   Interpolator.java Locale.java
  Log:
  JBSEAM-726: fix double interpolation bug, add basic tests
  
  Revision  Changes    Path
  1.18      +31 -10    jboss-seam/src/main/org/jboss/seam/core/Interpolator.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Interpolator.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Interpolator.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -b -r1.17 -r1.18
  --- Interpolator.java	27 Jan 2007 01:55:25 -0000	1.17
  +++ Interpolator.java	1 Feb 2007 19:58:07 -0000	1.18
  @@ -59,14 +59,11 @@
         {
            throw new IllegalArgumentException("more than 10 parameters");
         }
  -      if ( string.indexOf('#')>=0 )
  -      {
  +
  +      if (string.indexOf('#')>=0 || string.indexOf('{')>=0) {
            string = interpolateExpressions(string, params);
         }
  -      if (params.length>0 && string.indexOf('{')>=0 )
  -      {
  -         string = new MessageFormat(string, Locale.instance()).format(params);
  -      }
  +
         return string;
      }
   
  @@ -115,9 +112,33 @@
                     builder.append("#").append(nextTok);
                  }
               }
  +         } else if ("{".equals(tok)) {
  +             StringBuilder expr = new StringBuilder();
  +             
  +             expr.append(tok);
  +             int level = 1;
  +
  +             while (tokens.hasMoreTokens()) {
  +                 String nextTok = tokens.nextToken();
  +                 expr.append(nextTok);
  +                 
  +                 if (nextTok.equals("{")) {
  +                     ++level;
  +                 } else if (nextTok.equals("}")) {
  +                     if (--level == 0) {
  +                         String value = new MessageFormat(expr.toString(), Locale.instance()).format(params);
  +                         builder.append(value);
  +                         
  +                         expr = null;
  +                         break;
  +                     }
  +                 }
            }
  -         else
  -         {
  +
  +             if (expr != null) {
  +                 builder.append(expr);
  +             }
  +         } else {
               builder.append(tok);
            }
         }
  
  
  
  1.6       +8 -4      jboss-seam/src/main/org/jboss/seam/core/Locale.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Locale.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Locale.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- Locale.java	24 Nov 2006 23:15:17 -0000	1.5
  +++ Locale.java	1 Feb 2007 19:58:07 -0000	1.6
  @@ -10,6 +10,7 @@
   import org.jboss.seam.annotations.Name;
   import org.jboss.seam.annotations.Scope;
   import org.jboss.seam.annotations.Unwrap;
  +import org.jboss.seam.contexts.Contexts;
   
   /**
    * Manager component for the current user's locale
  @@ -30,7 +31,10 @@
      
      public static java.util.Locale instance()
      {
  +       if (Contexts.isApplicationContextActive()) {
         return (java.util.Locale) Component.getInstance(Locale.class, ScopeType.STATELESS);
  +       } else {
  +          return java.util.Locale.US; // testing
  +       }
      }
  -   
   }
  
  
  



More information about the jboss-cvs-commits mailing list