geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r593636 - in /geronimo/server/trunk/framework/modules/geronimo-system/src: main/java/org/apache/geronimo/system/configuration/condition/JexlExpressionParser.java test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java
Date Fri, 09 Nov 2007 19:48:23 GMT
Author: gawor
Date: Fri Nov  9 11:48:22 2007
New Revision: 593636

URL: http://svn.apache.org/viewvc?rev=593636&view=rev
Log:
handle nested blocks in expression parser

Modified:
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JexlExpressionParser.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JexlExpressionParser.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JexlExpressionParser.java?rev=593636&r1=593635&r2=593636&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JexlExpressionParser.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/condition/JexlExpressionParser.java
Fri Nov  9 11:48:22 2007
@@ -149,7 +149,7 @@
                 break;
             }
 
-            suffixLoc = input.indexOf("}", prefixLoc);
+            suffixLoc = findBlockEnd(prefixLoc + 2, input);
             if (suffixLoc < 0) {
                 throw new RuntimeException("Missing '}': " + input);
             }
@@ -176,6 +176,24 @@
         return buff.toString();
     }
 
+    private int findBlockEnd(int pos, String input) {
+        int nested = 0;
+        while (pos < input.length()) {
+            char ch = input.charAt(pos);
+            if (ch == '{') {
+                nested++;
+            } else if (ch == '}') {
+                if (nested == 0) {
+                    return pos;
+                } else {
+                    nested--;
+                }
+            }
+            pos++;
+        }
+        return -1;
+    }
+    
     public String parse(final String input, final boolean trim) {
         String output = parse(input);
         if (trim && output != null) {

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java?rev=593636&r1=593635&r2=593636&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/ServerOverrideTest.java
Fri Nov  9 11:48:22 2007
@@ -272,6 +272,10 @@
         gbean.setAttribute("expression", "${if (java == null) 'null'; else 'non-null';}");
         gbean.applyOverrides(data, null, null, getClass().getClassLoader());
         assertEquals("non-null", data.getAttribute("expression"));
+        
+        gbean.setAttribute("expression", "${if (java == null) { 'null'; } else { if (os ==
null) { 'java,null'; } else { 'java,non-null'; } } }");
+        gbean.applyOverrides(data, null, null, getClass().getClassLoader());
+        assertEquals("java,non-null", data.getAttribute("expression"));
     }
 
     private void assertCopyIdentical(ServerOverride server) throws Exception {



Mime
View raw message