camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/5] camel git commit: CAMEL-7999: Camel model schema fixed issue around default values need escape and unescape.
Date Fri, 30 Jan 2015 17:39:54 GMT
CAMEL-7999: Camel model schema fixed issue around default values need escape and unescape.


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

Branch: refs/heads/master
Commit: 8dd6c1fc49a4af03aa2db35ac2a97740f621da1e
Parents: 9e52ce4
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Jan 30 14:09:50 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Jan 30 14:09:50 2015 +0100

----------------------------------------------------------------------
 .../model/dataformat/FlatpackDataFormat.java    |  2 +-
 .../org/apache/camel/util/JsonSchemaHelper.java | 13 +++++--
 ...ponentConfigurationAndDocumentationTest.java | 37 ++++++++++++++++++--
 .../camel/maven/packaging/JSonSchemaHelper.java | 14 ++++++--
 4 files changed, 59 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8dd6c1fc/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java
b/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java
index 0b6f85e..1463581 100644
--- a/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/FlatpackDataFormat.java
@@ -109,7 +109,7 @@ public class FlatpackDataFormat extends DataFormatDefinition {
     }
 
     /**
-     * If the text is qualified with a char such as "
+     * If the text is qualified with a char such as &quot;
      */
     public void setTextQualifier(String textQualifier) {
         this.textQualifier = textQualifier;

http://git-wip-us.apache.org/repos/asf/camel/blob/8dd6c1fc/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java b/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
index c8049ab..3c48267 100644
--- a/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/JsonSchemaHelper.java
@@ -145,7 +145,7 @@ public final class JsonSchemaHelper {
             }
 
             // need to safe encode \" so we can parse the line
-            line = line.replaceAll("\\\\\"", QUOT);
+            line = line.replaceAll("\"\\\\\"\"", '"' + QUOT + '"');
 
             Map<String, String> row = new LinkedHashMap<String, String>();
             Matcher matcher = PATTERN.matcher(line);
@@ -170,8 +170,9 @@ public final class JsonSchemaHelper {
                     }
                     if (value != null) {
                         value = value.trim();
-                        // encode back
+                        // decode
                         value = value.replaceAll(QUOT, "\"");
+                        value = decodeJson(value);
                     }
                     row.put(key, value);
                     // reset
@@ -186,4 +187,12 @@ public final class JsonSchemaHelper {
         return answer;
     }
 
+    private static String decodeJson(String value) {
+        // json encodes a \ as \\ so we need to decode from \\ back to \
+        if ("\\\\".equals(value)) {
+            value = "\\";
+        }
+        return value;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/8dd6c1fc/camel-core/src/test/java/org/apache/camel/component/dataformat/DataFormatComponentConfigurationAndDocumentationTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/dataformat/DataFormatComponentConfigurationAndDocumentationTest.java
b/camel-core/src/test/java/org/apache/camel/component/dataformat/DataFormatComponentConfigurationAndDocumentationTest.java
index 2d7973f..bd17c4b 100644
--- a/camel-core/src/test/java/org/apache/camel/component/dataformat/DataFormatComponentConfigurationAndDocumentationTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/dataformat/DataFormatComponentConfigurationAndDocumentationTest.java
@@ -56,11 +56,11 @@ public class DataFormatComponentConfigurationAndDocumentationTest extends
Contex
         assertNotNull("Should have found some auto-generated HTML", html);
     }
 
+    @Test
     public void testFlatpackDefaultValue() throws Exception {
         CamelContext context = new DefaultCamelContext();
         String json = context.getEipParameterJsonSchema("flatpack");
         assertNotNull(json);
-        System.out.println(json);
 
         assertTrue(json.contains("\"name\": \"flatpack"));
 
@@ -86,7 +86,40 @@ public class DataFormatComponentConfigurationAndDocumentationTest extends
Contex
         assertEquals("java.lang.String", found.get("javaType"));
         assertEquals("false", found.get("deprecated"));
         assertEquals("\"", found.get("defaultValue"));
-        assertEquals("If the text is qualified with a char such as &quot;", found.get("description"));
+        assertEquals("If the text is qualified with a char such as \"", found.get("description"));
+    }
+
+    @Test
+    public void testUniVocityTsvEscapeChar() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        String json = context.getEipParameterJsonSchema("univocity-tsv");
+        assertNotNull(json);
+
+        assertTrue(json.contains("\"name\": \"univocity-tsv"));
+
+        // the default value is a bit tricky as its \, which is written escaped as \\
+        assertTrue(json.contains("\"escapeChar\": { \"kind\": \"attribute\", \"required\":
\"false\", \"type\": \"string\", \"javaType\": \"java.lang.String\","
+                + " \"deprecated\": \"false\", \"defaultValue\": \"\\\\\", \"description\":
\"The escape character.\""));
+
+        List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("properties",
json, true);
+        assertEquals(15, rows.size());
+
+        Map<String, String> found = null;
+        for (Map<String, String> row : rows) {
+            if ("escapeChar".equals(row.get("name"))) {
+                found = row;
+                break;
+            }
+        }
+        assertNotNull(found);
+        assertEquals("escapeChar", found.get("name"));
+        assertEquals("attribute", found.get("kind"));
+        assertEquals("false", found.get("required"));
+        assertEquals("string", found.get("type"));
+        assertEquals("java.lang.String", found.get("javaType"));
+        assertEquals("false", found.get("deprecated"));
+        assertEquals("\\", found.get("defaultValue"));
+        assertEquals("The escape character.", found.get("description"));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/8dd6c1fc/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java
index 8acf615..0d2c7f8 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java
@@ -62,7 +62,7 @@ public final class JSonSchemaHelper {
             }
 
             // need to safe encode \" so we can parse the line
-            line = line.replaceAll("\\\\\"", QUOT);
+            line = line.replaceAll("\"\\\\\"\"", '"' + QUOT + '"');
 
             Map<String, String> row = new LinkedHashMap<String, String>();
             Matcher matcher = PATTERN.matcher(line);
@@ -87,8 +87,9 @@ public final class JSonSchemaHelper {
                     }
                     if (value != null) {
                         value = value.trim();
-                        // encode back
+                        // decode
                         value = value.replaceAll(QUOT, "\"");
+                        value = decodeJson(value);
                     }
                     row.put(key, value);
                     // reset
@@ -103,4 +104,13 @@ public final class JSonSchemaHelper {
         return answer;
     }
 
+    private static String decodeJson(String value) {
+        // json encodes a \ as \\ so we need to decode from \\ back to \
+        if ("\\\\".equals(value)) {
+            value = "\\";
+        }
+        return value;
+    }
+
+
 }


Mime
View raw message