You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/01/03 15:28:29 UTC

[7/9] camel git commit: CAMEL-9470: Component docs - Some options support using an optional prefix such as consumer.

CAMEL-9470: Component docs - Some options support using an optional prefix such as consumer.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/946ed735
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/946ed735
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/946ed735

Branch: refs/heads/master
Commit: 946ed7357daa98a392c5f2fb9b8f18c35e299c6e
Parents: 3c782db
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Jan 3 15:00:11 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Jan 3 15:00:42 2016 +0100

----------------------------------------------------------------------
 .../apache/camel/catalog/DefaultCamelCatalog.java  | 15 ++++-----------
 .../org/apache/camel/catalog/JSonSchemaHelper.java | 17 ++++++++---------
 2 files changed, 12 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/946ed735/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index 1c70f40..a4e638a 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -47,13 +47,13 @@ import static org.apache.camel.catalog.JSonSchemaHelper.getNames;
 import static org.apache.camel.catalog.JSonSchemaHelper.getPropertyDefaultValue;
 import static org.apache.camel.catalog.JSonSchemaHelper.getPropertyEnum;
 import static org.apache.camel.catalog.JSonSchemaHelper.getPropertyKind;
-import static org.apache.camel.catalog.JSonSchemaHelper.getPropertyOptionalPrefix;
 import static org.apache.camel.catalog.JSonSchemaHelper.getRow;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyBoolean;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyInteger;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyNumber;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyObject;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyRequired;
+import static org.apache.camel.catalog.JSonSchemaHelper.stripOptionalPrefixFromName;
 import static org.apache.camel.catalog.URISupport.createQueryString;
 import static org.apache.camel.catalog.URISupport.isEmpty;
 import static org.apache.camel.catalog.URISupport.normalizeUri;
@@ -753,21 +753,14 @@ public class DefaultCamelCatalog implements CamelCatalog {
         // validate all the options
         for (Map.Entry<String, String> property : properties.entrySet()) {
             String name = property.getKey();
-            String optionalPrefix = getPropertyOptionalPrefix(rows, name);
+            // the name may be using an optional prefix, so lets strip that because the options
+            // in the schema are listed without the prefix
+            name = stripOptionalPrefixFromName(rows, name);
             String value = property.getValue();
             boolean placeholder = value.startsWith("{{") || value.startsWith("${") || value.startsWith("$simple{");
             boolean lookup = value.startsWith("#") && value.length() > 1;
 
             Map<String, String> row = getRow(rows, name);
-
-            // maybe the name was using an optional prefix, and if so then lookup without the prefix
-            if (row == null && !isEmpty(optionalPrefix)) {
-                if (name.startsWith(optionalPrefix)) {
-                    name = name.substring(optionalPrefix.length());
-                }
-                row = getRow(rows, name);
-            }
-
             if (row == null) {
                 // unknown option
                 result.addUnknown(name);

http://git-wip-us.apache.org/repos/asf/camel/blob/946ed735/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
index bbfe7c1..2293a7a 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
@@ -233,7 +233,7 @@ public final class JSonSchemaHelper {
         return null;
     }
 
-    public static String getPropertyOptionalPrefix(List<Map<String, String>> rows, String name) {
+    public static String stripOptionalPrefixFromName(List<Map<String, String>> rows, String name) {
         for (Map<String, String> row : rows) {
             String optionalPrefix = null;
             boolean found = false;
@@ -241,20 +241,19 @@ public final class JSonSchemaHelper {
                 optionalPrefix = row.get("optionalPrefix");
             }
             if (row.containsKey("name")) {
-                String key = name;
-                if (optionalPrefix != null && key.startsWith(optionalPrefix)) {
-                    key = key.substring(optionalPrefix.length());
-                    // found the optional prefix so remove it from the key, and lookup again
-                    return getPropertyOptionalPrefix(rows, key);
+                if (optionalPrefix != null && name.startsWith(optionalPrefix)) {
+                    name = name.substring(optionalPrefix.length());
+                    // try again
+                    return stripOptionalPrefixFromName(rows, name);
                 } else {
-                    found = key.equals(row.get("name"));
+                    found = name.equals(row.get("name"));
                 }
             }
             if (found) {
-                return optionalPrefix;
+                return name;
             }
         }
-        return null;
+        return name;
     }
 
     public static String getPropertyEnum(List<Map<String, String>> rows, String name) {