You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/06/15 14:36:15 UTC

[camel] 02/03: (chores) camel-core-languages: cleanup duplicated code for parsing in headers

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

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

commit 34bad642324412471b87934ec1d406b48da6b2a0
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Jun 15 09:23:28 2023 +0200

     (chores) camel-core-languages: cleanup duplicated code for parsing in headers
---
 .../simple/ast/SimpleFunctionExpression.java       | 37 ++++++++++------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
index e93a78125fc..d7413f0c9e6 100644
--- a/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
+++ b/core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java
@@ -385,16 +385,7 @@ public class SimpleFunctionExpression extends LiteralExpression {
         }
 
         // in header function
-        remainder = ifStartsWithReturnRemainder("in.headers", function);
-        if (remainder == null) {
-            remainder = ifStartsWithReturnRemainder("in.header", function);
-        }
-        if (remainder == null) {
-            remainder = ifStartsWithReturnRemainder("headers", function);
-        }
-        if (remainder == null) {
-            remainder = ifStartsWithReturnRemainder("header", function);
-        }
+        remainder = parseInHeader(function);
         if (remainder != null) {
             // remove leading character (dot, colon or ?)
             if (remainder.startsWith(".") || remainder.startsWith(":") || remainder.startsWith("?")) {
@@ -1113,16 +1104,7 @@ public class SimpleFunctionExpression extends LiteralExpression {
         }
 
         // in header function
-        remainder = ifStartsWithReturnRemainder("in.headers", function);
-        if (remainder == null) {
-            remainder = ifStartsWithReturnRemainder("in.header", function);
-        }
-        if (remainder == null) {
-            remainder = ifStartsWithReturnRemainder("headers", function);
-        }
-        if (remainder == null) {
-            remainder = ifStartsWithReturnRemainder("header", function);
-        }
+        remainder = parseInHeader(function);
         if (remainder != null) {
             // remove leading character (dot, colon or ?)
             if (remainder.startsWith(".") || remainder.startsWith(":") || remainder.startsWith("?")) {
@@ -1181,6 +1163,21 @@ public class SimpleFunctionExpression extends LiteralExpression {
         return null;
     }
 
+    private String parseInHeader(String function) {
+        String remainder;
+        remainder = ifStartsWithReturnRemainder("in.headers", function);
+        if (remainder == null) {
+            remainder = ifStartsWithReturnRemainder("in.header", function);
+        }
+        if (remainder == null) {
+            remainder = ifStartsWithReturnRemainder("headers", function);
+        }
+        if (remainder == null) {
+            remainder = ifStartsWithReturnRemainder("header", function);
+        }
+        return remainder;
+    }
+
     private String createCodeExchangeProperty(final String function) {
         // exchangePropertyAsIndex
         String remainder = ifStartsWithReturnRemainder("exchangePropertyAsIndex(", function);