camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/5] camel git commit: Camel catalog - Add api to get list of all components in json
Date Sun, 18 Oct 2015 06:53:44 GMT
Camel catalog - Add api to get list of all components in json


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

Branch: refs/heads/master
Commit: c483e050563ed44030a7cc1ad83969165560dd4d
Parents: 23daa09
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Oct 17 17:39:47 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Oct 18 08:54:43 2015 +0200

----------------------------------------------------------------------
 .../org/apache/camel/catalog/CamelCatalog.java  |  5 +++
 .../org/apache/camel/catalog/CatalogHelper.java | 45 ++++++++++++++++++++
 .../camel/catalog/DefaultCamelCatalog.java      | 24 +++++++++++
 .../apache/camel/catalog/CamelCatalogTest.java  |  6 +++
 4 files changed, 80 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c483e050/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
index 350c2d4..e09ef78 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
@@ -209,4 +209,9 @@ public interface CamelCatalog {
      * @throws java.net.URISyntaxException is thrown if there is encoding error
      */
     String asEndpointUriXml(String scheme, Map<String, String> properties) throws URISyntaxException;
+
+    /**
+     * Lists all the component summary details in JSon
+     */
+    String listComponentAsJson();
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/c483e050/platforms/catalog/src/main/java/org/apache/camel/catalog/CatalogHelper.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/CatalogHelper.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/CatalogHelper.java
index e33b562..2ce8089 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/CatalogHelper.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/CatalogHelper.java
@@ -98,4 +98,49 @@ public final class CatalogHelper {
         }
         return false;
     }
+
+    /**
+     * Returns the string after the given token
+     *
+     * @param text  the text
+     * @param after the token
+     * @return the text after the token, or <tt>null</tt> if text does not contain
the token
+     */
+    public static String after(String text, String after) {
+        if (!text.contains(after)) {
+            return null;
+        }
+        return text.substring(text.indexOf(after) + after.length());
+    }
+
+    /**
+     * Returns the string before the given token
+     *
+     * @param text  the text
+     * @param before the token
+     * @return the text before the token, or <tt>null</tt> if text does not contain
the token
+     */
+    public static String before(String text, String before) {
+        if (!text.contains(before)) {
+            return null;
+        }
+        return text.substring(0, text.indexOf(before));
+    }
+
+    /**
+     * Returns the string between the given tokens
+     *
+     * @param text  the text
+     * @param after the before token
+     * @param before the after token
+     * @return the text between the tokens, or <tt>null</tt> if text does not
contain the tokens
+     */
+    public static String between(String text, String after, String before) {
+        text = after(text, after);
+        if (text == null) {
+            return null;
+        }
+        return before(text, before);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/c483e050/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 1641495..225b04d 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
@@ -732,4 +732,28 @@ public class DefaultCamelCatalog implements CamelCatalog {
         return sb.toString();
     }
 
+    @Override
+    public String listComponentAsJson() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("[");
+        List<String> names = findComponentNames();
+        for (int i = 0; i < names.size(); i++) {
+            String scheme = names.get(i);
+            String json = componentJSonSchema(scheme);
+            // skip first line
+            json = CatalogHelper.between(json, "\"component\": {", "\"componentProperties\"");
+            json = json.trim();
+            // skip last comma if not the last
+            if (i == names.size() - 1) {
+                json = json.substring(0, json.length() - 1);
+            }
+            sb.append("\n");
+            sb.append("  {\n");
+            sb.append("    ");
+            sb.append(json);
+        }
+
+        sb.append("\n]");
+        return sb.toString();
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/c483e050/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index ab69fed..2f529cb 100644
--- a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -238,4 +238,10 @@ public class CamelCatalogTest extends TestCase {
         assertEquals("jms", name);
     }
 
+    @Test
+    public void testListComponentAsJosn() throws Exception {
+        String json = catalog.listComponentAsJson();
+        assertNotNull(json);
+    }
+
 }


Mime
View raw message