This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f0fd289744cc9bced1081257c20f4608882442dc
Author: Dimitrios Liapis <dimitri...@gmail.com>
AuthorDate: Tue May 21 17:23:04 2019 +0200

    CAMEL-13534 Adding colon as alternative syntax style
---
 .../simple/ast/SimpleFunctionExpression.java       | 16 +++++++--
 .../apache/camel/language/simple/SimpleTest.java   | 40 ++++++++++++++++++----
 2 files changed, 47 insertions(+), 9 deletions(-)

diff --git 
a/core/camel-base/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
 
b/core/camel-base/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
index c3e2a01..641a8ca 100644
--- 
a/core/camel-base/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
+++ 
b/core/camel-base/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
@@ -150,8 +150,14 @@ public class SimpleFunctionExpression extends 
LiteralExpression {
         }
         remainder = ifStartsWithReturnRemainder("sysenv.", function);
         if (remainder == null) {
+            remainder = ifStartsWithReturnRemainder("sysenv:", function);
+        }
+        if (remainder == null) {
             remainder = ifStartsWithReturnRemainder("env.", function);
         }
+        if (remainder == null) {
+            remainder = ifStartsWithReturnRemainder("env:", function);
+        }
         if (remainder != null) {
             return ExpressionBuilder.systemEnvironmentExpression(remainder);
         }
@@ -355,8 +361,8 @@ public class SimpleFunctionExpression extends 
LiteralExpression {
             remainder = ifStartsWithReturnRemainder("header", function);
         }
         if (remainder != null) {
-            // remove leading character (dot or ?)
-            if (remainder.startsWith(".") || remainder.startsWith("?")) {
+            // remove leading character (dot, colon or ?)
+            if (remainder.startsWith(".") || remainder.startsWith(":") || 
remainder.startsWith("?")) {
                 remainder = remainder.substring(1);
             }
             // remove starting and ending brackets
@@ -384,8 +390,14 @@ public class SimpleFunctionExpression extends 
LiteralExpression {
         // out header function
         remainder = ifStartsWithReturnRemainder("out.header.", function);
         if (remainder == null) {
+            remainder = ifStartsWithReturnRemainder("out.header:", function);
+        }
+        if (remainder == null) {
             remainder = ifStartsWithReturnRemainder("out.headers.", function);
         }
+        if (remainder == null) {
+            remainder = ifStartsWithReturnRemainder("out.headers:", function);
+        }
         if (remainder != null) {
             return ExpressionBuilder.outHeaderExpression(remainder);
         }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
index 39d09e1..261d18b 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleTest.java
@@ -164,7 +164,7 @@ public class SimpleTest extends LanguageTestSupport {
     public void testBodyOgnlExpression() throws Exception {
         Expression exp = SimpleLanguage.simple("${body.xxx}");
         assertNotNull(exp);
-        
+
         // must start with a dot
         try {
             SimpleLanguage.simple("${bodyxxx}");
@@ -248,7 +248,9 @@ public class SimpleTest extends LanguageTestSupport {
         exchange.getOut().setHeader("quote", "Camel rocks");
         assertExpression("${out.body}", "Bye World");
         assertExpression("${out.header.quote}", "Camel rocks");
+        assertExpression("${out.header:quote}", "Camel rocks");
         assertExpression("${out.headers.quote}", "Camel rocks");
+        assertExpression("${out.headers:quote}", "Camel rocks");
     }
 
     @Test
@@ -268,16 +270,20 @@ public class SimpleTest extends LanguageTestSupport {
         String path = System.getenv("PATH");
         if (path != null) {
             assertExpression("${sysenv.PATH}", path);
+            assertExpression("${sysenv:PATH}", path);
             assertExpression("${env.PATH}", path);
+            assertExpression("${env:PATH}", path);
         }
     }
-    
+
     @Test
     public void testSimpleSystemEnvironmentExpressionsIfDash() throws 
Exception {
         String foo = System.getenv("FOO_SERVICE_HOST");
         if (foo != null) {
             assertExpression("${sysenv.FOO-SERVICE-HOST}", foo);
+            assertExpression("${sysenv:FOO-SERVICE-HOST}", foo);
             assertExpression("${env.FOO-SERVICE-HOST}", foo);
+            assertExpression("${env:FOO-SERVICE-HOST}", foo);
         }
     }
 
@@ -286,7 +292,9 @@ public class SimpleTest extends LanguageTestSupport {
         String path = System.getenv("PATH");
         if (path != null) {
             assertExpression("${sysenv.path}", path);
+            assertExpression("${sysenv:path}", path);
             assertExpression("${env.path}", path);
+            assertExpression("${env:path}", path);
         }
     }
 
@@ -418,11 +426,11 @@ public class SimpleTest extends LanguageTestSupport {
         } catch (Exception e) {
             IndexOutOfBoundsException cause = 
assertIsInstanceOf(IndexOutOfBoundsException.class, e.getCause());
             if (getJavaMajorVersion() <= 8) {
-                assertEquals(JAVA8_INDEX_OUT_OF_BOUNDS_ERROR_MSG, 
cause.getMessage());    
+                assertEquals(JAVA8_INDEX_OUT_OF_BOUNDS_ERROR_MSG, 
cause.getMessage());
             } else {
                 assertEquals(INDEX_OUT_OF_BOUNDS_ERROR_MSG, 
cause.getMessage());
             }
-            
+
         }
         assertExpression("${exchangeProperty.unknown[cool]}", null);
     }
@@ -551,7 +559,7 @@ public class SimpleTest extends LanguageTestSupport {
         Calendar inHeaderCalendar = Calendar.getInstance();
         inHeaderCalendar.set(1974, Calendar.APRIL, 20);
         exchange.getIn().setHeader("birthday", inHeaderCalendar.getTime());
-        
+
         Calendar outHeaderCalendar = Calendar.getInstance();
         outHeaderCalendar.set(1975, Calendar.MAY, 21);
         exchange.getOut().setHeader("birthday", outHeaderCalendar.getTime());
@@ -563,11 +571,11 @@ public class SimpleTest extends LanguageTestSupport {
         assertExpression("${date:header.birthday}", 
inHeaderCalendar.getTime());
         assertExpression("${date:header.birthday:yyyyMMdd}", "19740420");
         assertExpression("${date:header.birthday+24h:yyyyMMdd}", "19740421");
-        
+
         assertExpression("${date:in.header.birthday}", 
inHeaderCalendar.getTime());
         assertExpression("${date:in.header.birthday:yyyyMMdd}", "19740420");
         assertExpression("${date:in.header.birthday+24h:yyyyMMdd}", 
"19740421");
-        
+
         assertExpression("${date:out.header.birthday}", 
outHeaderCalendar.getTime());
         assertExpression("${date:out.header.birthday:yyyyMMdd}", "19750521");
         assertExpression("${date:out.header.birthday+24h:yyyyMMdd}", 
"19750522");
@@ -631,23 +639,37 @@ public class SimpleTest extends LanguageTestSupport {
     @Test
     public void testComplexExpressions() throws Exception {
         assertExpression("hey ${in.header.foo}", "hey abc");
+        assertExpression("hey ${in.header:foo}", "hey abc");
         assertExpression("hey ${in.header.foo}!", "hey abc!");
+        assertExpression("hey ${in.header:foo}!", "hey abc!");
         assertExpression("hey ${in.header.foo}-${in.header.foo}!", "hey 
abc-abc!");
+        assertExpression("hey ${in.header:foo}-${in.header.foo}!", "hey 
abc-abc!");
         assertExpression("hey ${in.header.foo}${in.header.foo}", "hey abcabc");
+        assertExpression("hey ${in.header:foo}${in.header.foo}", "hey abcabc");
         assertExpression("${in.header.foo}${in.header.foo}", "abcabc");
+        assertExpression("${in.header:foo}${in.header:foo}", "abcabc");
         assertExpression("${in.header.foo}", "abc");
+        assertExpression("${in.header:foo}", "abc");
         assertExpression("${in.header.foo}!", "abc!");
+        assertExpression("${in.header:foo}!", "abc!");
     }
 
     @Test
     public void testComplexExpressionsUsingAlternativeStartToken() throws 
Exception {
         assertExpression("hey $simple{in.header.foo}", "hey abc");
+        assertExpression("hey $simple{in.header:foo}", "hey abc");
         assertExpression("hey $simple{in.header.foo}!", "hey abc!");
+        assertExpression("hey $simple{in.header:foo}!", "hey abc!");
         assertExpression("hey $simple{in.header.foo}-$simple{in.header.foo}!", 
"hey abc-abc!");
+        assertExpression("hey $simple{in.header:foo}-$simple{in.header.foo}!", 
"hey abc-abc!");
         assertExpression("hey $simple{in.header.foo}$simple{in.header.foo}", 
"hey abcabc");
+        assertExpression("hey $simple{in.header:foo}$simple{in.header.foo}", 
"hey abcabc");
         assertExpression("$simple{in.header.foo}$simple{in.header.foo}", 
"abcabc");
+        assertExpression("$simple{in.header:foo}$simple{in.header.foo}", 
"abcabc");
         assertExpression("$simple{in.header.foo}", "abc");
+        assertExpression("$simple{in.header:foo}", "abc");
         assertExpression("$simple{in.header.foo}!", "abc!");
+        assertExpression("$simple{in.header:foo}!", "abc!");
     }
 
     @Test
@@ -747,9 +769,13 @@ public class SimpleTest extends LanguageTestSupport {
         exchange.getIn().setBody(null);
 
         assertExpression("${header.foo}", "abc");
+        assertExpression("${header:foo}", "abc");
         assertExpression("${headers.foo}", "abc");
+        assertExpression("${headers:foo}", "abc");
         assertExpression("${in.header.foo}", "abc");
+        assertExpression("${in.header:foo}", "abc");
         assertExpression("${in.headers.foo}", "abc");
+        assertExpression("${in.headers:foo}", "abc");
     }
 
     @Test

Reply via email to