Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9373E17CDC for ; Fri, 30 Jan 2015 17:39:51 +0000 (UTC) Received: (qmail 3636 invoked by uid 500); 30 Jan 2015 17:39:52 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 3490 invoked by uid 500); 30 Jan 2015 17:39:52 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 3454 invoked by uid 99); 30 Jan 2015 17:39:52 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Jan 2015 17:39:52 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E3D4CE0111; Fri, 30 Jan 2015 17:39:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Fri, 30 Jan 2015 17:39:54 -0000 Message-Id: In-Reply-To: <53a780783c7444858c6536ac060c4623@git.apache.org> References: <53a780783c7444858c6536ac060c4623@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/5] camel git commit: CAMEL-7999: Camel model schema fixed issue around default values need escape and unescape. 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 Authored: Fri Jan 30 14:09:50 2015 +0100 Committer: Claus Ibsen 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 " */ 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 row = new LinkedHashMap(); 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 "", 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> rows = JsonSchemaHelper.parseJsonSchema("properties", json, true); + assertEquals(15, rows.size()); + + Map found = null; + for (Map 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 row = new LinkedHashMap(); 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; + } + + }