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 2024/04/12 08:33:14 UTC
(camel) 01/07: (chores) camel-core-catalog: extract independent code snippets from large code blocks
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 10c559b507c1b33c0ac685230e65db1c3ac6471e
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Thu Apr 11 13:34:04 2024 +0200
(chores) camel-core-catalog: extract independent code snippets from large code blocks
---
.../camel/catalog/impl/AbstractCamelCatalog.java | 93 ++++++++++++----------
1 file changed, 49 insertions(+), 44 deletions(-)
diff --git a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
index ee2e66b0b1d..170a17817aa 100644
--- a/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
+++ b/core/camel-core-catalog/src/main/java/org/apache/camel/catalog/impl/AbstractCamelCatalog.java
@@ -570,50 +570,7 @@ public abstract class AbstractCamelCatalog {
}
}
// parse the syntax and find each token between each option
- String[] tokens = SYNTAX_PATTERN.split(syntax);
-
- // find the position where each option start/end
- List<String> word2 = new ArrayList<>();
- int prev = 0;
- int prevPath = 0;
-
- // special for activemq/jms where the enum for destinationType causes a token issue as it includes a colon
- // for 'temp:queue' and 'temp:topic' values
- if ("activemq".equals(scheme) || "jms".equals(scheme)) {
- if (uriPath.startsWith("temp:")) {
- prevPath = 5;
- }
- }
-
- for (String token : tokens) {
- if (token.isEmpty()) {
- continue;
- }
-
- // special for some tokens where :// can be used also, eg http://foo
- int idx = -1;
- int len = 0;
- if (":".equals(token)) {
- idx = uriPath.indexOf("://", prevPath);
- len = 3;
- }
- if (idx == -1) {
- idx = uriPath.indexOf(token, prevPath);
- len = token.length();
- }
-
- if (idx > 0) {
- String option = uriPath.substring(prev, idx);
- word2.add(option);
- prev = idx + len;
- prevPath = prev;
- }
- }
- // special for last or if we did not add anyone
- if (prev > 0 || word2.isEmpty()) {
- String option = uriPath.substring(prev);
- word2.add(option);
- }
+ final List<String> word2 = findTokens(syntax, scheme, uriPath);
boolean defaultValueAdded = false;
@@ -738,6 +695,54 @@ public abstract class AbstractCamelCatalog {
return answer;
}
+ private static List<String> findTokens(String syntax, String scheme, String uriPath) {
+ String[] tokens = SYNTAX_PATTERN.split(syntax);
+
+ // find the position where each option start/end
+ List<String> word2 = new ArrayList<>();
+ int prev = 0;
+ int prevPath = 0;
+
+ // special for activemq/jms where the enum for destinationType causes a token issue as it includes a colon
+ // for 'temp:queue' and 'temp:topic' values
+ if ("activemq".equals(scheme) || "jms".equals(scheme)) {
+ if (uriPath.startsWith("temp:")) {
+ prevPath = 5;
+ }
+ }
+
+ for (String token : tokens) {
+ if (token.isEmpty()) {
+ continue;
+ }
+
+ // special for some tokens where :// can be used also, eg http://foo
+ int idx = -1;
+ int len = 0;
+ if (":".equals(token)) {
+ idx = uriPath.indexOf("://", prevPath);
+ len = 3;
+ }
+ if (idx == -1) {
+ idx = uriPath.indexOf(token, prevPath);
+ len = token.length();
+ }
+
+ if (idx > 0) {
+ String option = uriPath.substring(prev, idx);
+ word2.add(option);
+ prev = idx + len;
+ prevPath = prev;
+ }
+ }
+ // special for last or if we did not add anyone
+ if (prev > 0 || word2.isEmpty()) {
+ String option = uriPath.substring(prev);
+ word2.add(option);
+ }
+ return word2;
+ }
+
private Map<String, BaseOptionModel> extractApiProperties(ComponentModel model, String key, String key2) {
Map<String, BaseOptionModel> answer = new LinkedHashMap<>();
if (key != null) {