This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 5b30176325b4 Polished simple doc
5b30176325b4 is described below
commit 5b30176325b401a91d66525f9ac86bfa3fff0188
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Jan 23 12:29:27 2026 +0100
Polished simple doc
---
.../modules/languages/pages/simple-language.adoc | 46 ++++++++++++++--------
.../language/simple/ast/TernaryExpression.java | 19 ++++++---
.../camel/language/simple/SimpleInitBlockTest.java | 8 ++--
3 files changed, 46 insertions(+), 27 deletions(-)
diff --git
a/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
b/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
index 1f543bbaddb0..1b5e2c025cee 100644
---
a/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
+++
b/core/camel-core-languages/src/main/docs/modules/languages/pages/simple-language.adoc
@@ -350,6 +350,19 @@ This requires having `camel-base64` JAR on the classpath.
|`base64Encode(exp)` | `String` |Base64 encodes the expression
|====
+== Built-in Symbols
+
+The following special symbols can be used when escaped with `\` as below:
+
+[width="100%",cols="50%,50%",options="header",]
+|====
+|Symbol |Description
+|`\n` | To use newline character.
+|`\t` | To use tab character.
+|`\r` | To use carriage return character.
+|`\}` | To use the `}` character as text. This may be needed when building a
JSon structure with the simple language.
+|====
+
== Built-in Operators
The simple language has limited support for operators that are used in
predicates to evaluate whether a condition is either _true_ or _false_.
@@ -371,7 +384,9 @@ Camel will automatically type convert the rightValue type
to the
leftValue type, so it is able to e.g., convert a string into a numeric, so
you can use `>` comparison for numeric values.
-The following operators are supported:
+=== Comparison Operators
+
+The following comparison operators are supported:
[width="100%",cols="50%,50%",options="header",]
|====
@@ -402,7 +417,9 @@ The following operators are supported:
|`!startsWith` | For testing if the left-hand side string does not start with
the right-hand string.
|====
-And the following unary operators can be used:
+=== Numeric Operators
+
+The following numeric operators can be used:
[width="100%",cols="50%,50%",options="header",]
|====
@@ -411,7 +428,9 @@ And the following unary operators can be used:
|`--` | To decrement a number by one. The left-hand side must be a function,
otherwise parsed as literal.
|====
-And the following other operators can be used:
+=== Other Operators
+
+The following other operators can be used:
[width="100%",cols="50%,50%",options="header",]
|====
@@ -449,24 +468,15 @@ then the default value of `Guest` is returned.
simple("${header.username} ?: 'Guest'");
----
-And the following special symbols:
-
-[width="100%",cols="50%,50%",options="header",]
-|====
-|Symbol |Description
-|`\n` | To use newline character.
-|`\t` | To use tab character.
-|`\r` | To use carriage return character.
-|`\}` | To use the `}` character as text. This may be needed when building a
JSon structure with the simple language.
-|====
+=== Boolean Operators
-And the following logical operators can be used to group expressions:
+And the following boolean operators can be used to group expressions:
[width="100%",cols="50%,50%",options="header",]
|====
|Operator |Description
-|`&&` | The logical and operator is used to group two expressions.
-|`\|\|` | The logical or operator is used to group two expressions.
+|`&&` | The `and` operator is used to group two expressions if both operands
evaluates to `true`.
+|`\|\|` | The `or` operator is used to group two expressions if any operand
evaluates to `true`.
|====
The syntax for AND is:
@@ -625,7 +635,7 @@ order:
</from>
----
-=== Combining multiple expression using AND / OR
+=== Combining multiple expression using AND / OR Operator
If you have two expressions you can combine them with the `&&` (and) or `||`
(or) operator.
@@ -652,6 +662,8 @@ make the simple expression easier to maintain and
understand.
IMPORTANT: Init Blocks is not supported with
xref:csimple-language.adoc[CSimple] language.
+NOTE: The init block declaration `$init{ ... }init$` may be changed in the
future.
+
The _init block_ is declared as follows:
[source,text]
diff --git
a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/TernaryExpression.java
b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/TernaryExpression.java
index 708a8ca5dd19..2ac1c1b40345 100644
---
a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/TernaryExpression.java
+++
b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/TernaryExpression.java
@@ -106,22 +106,29 @@ public class TernaryExpression extends BaseSimpleNode {
}
}
- final Expression conditionExp =
condition.createExpression(camelContext, expression);
+ final Predicate predicate
+ =
ExpressionToPredicateAdapter.toPredicate(condition.createExpression(camelContext,
expression));
final Expression trueExp = trueValue.createExpression(camelContext,
expression);
final Expression falseExp = falseValue.createExpression(camelContext,
expression);
- return createTernaryExpression(camelContext, conditionExp, trueExp,
falseExp);
+ return createTernaryExpression(camelContext, predicate, trueExp,
falseExp);
}
private Expression createTernaryExpression(
- final CamelContext camelContext, final Expression conditionExp,
+ final CamelContext camelContext, final Predicate predicate,
final Expression trueExp, final Expression falseExp) {
return new Expression() {
+
@Override
- public <T> T evaluate(Exchange exchange, Class<T> type) {
- // Convert condition to predicate
- Predicate predicate =
ExpressionToPredicateAdapter.toPredicate(conditionExp);
+ public void init(CamelContext context) {
+ Expression.super.init(context);
+ predicate.init(context);
+ trueExp.init(context);
+ falseExp.init(context);
+ }
+ @Override
+ public <T> T evaluate(Exchange exchange, Class<T> type) {
if (predicate.matches(exchange)) {
return trueExp.evaluate(exchange, type);
} else {
diff --git
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleInitBlockTest.java
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleInitBlockTest.java
index 515d88dc53e0..2af7bc087c1e 100644
---
a/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleInitBlockTest.java
+++
b/core/camel-core/src/test/java/org/apache/camel/language/simple/SimpleInitBlockTest.java
@@ -27,7 +27,7 @@ public class SimpleInitBlockTest extends LanguageTestSupport {
// this is a java like comment
$sum := ${sum(${header.lines},100)}
- $sku := ${iif(${body} contains 'Camel',123,999)}
+ $sku := ${body contains 'Camel' ? '123' : '999'}
}init$
orderId=$sku,total=$sum
""";
@@ -37,7 +37,7 @@ public class SimpleInitBlockTest extends LanguageTestSupport {
// this is a java like comment
$sum := ${sum(${header.lines},100)}
- $sku := ${iif(${body} contains 'Camel',123,999)}
+ $sku := ${body contains 'Camel' ? '123' : '999'}
}init$
$sum > 200 && $sku != 999
""";
@@ -47,7 +47,7 @@ public class SimpleInitBlockTest extends LanguageTestSupport {
// this is a java like comment
$sum := ${sum(${header.lines},100)}
- $sku := ${iif(${body} contains 'Camel',123,999)}
+ $sku := ${body contains 'Camel' ? '123' : '999'}
}init$
""";
@@ -56,7 +56,7 @@ public class SimpleInitBlockTest extends LanguageTestSupport {
// this is a java like comment
$sum := ${sum(${header.lines},100)}
- $sku := ${iif(${body} contains 'Hi := Me $sku',123,999)}
+ $sku := ${body contains 'Hi := Me $sku' ? '123' : '999'}
}init$
orderId=$sku,total=$sum
""";