From 47bd3d8e3c8d18ab0c80e94cade117610169207b Mon Sep 17 00:00:00 2001 From: Dilan Tharaka Date: Thu, 8 Apr 2021 11:12:44 +0530 Subject: [PATCH] add whitespace separators --- docs/csv_to_csv.md | 3 ++- docs/csv_to_json.md | 3 ++- docs/csv_to_xml.md | 3 ++- .../wso2/carbon/module/csv/util/PropertyReader.java | 13 ++++++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/docs/csv_to_csv.md b/docs/csv_to_csv.md index cdb3c72..24f08a1 100644 --- a/docs/csv_to_csv.md +++ b/docs/csv_to_csv.md @@ -13,7 +13,8 @@ To transform a CSV payload to another CSV payload in a different format you can Specify whether the CSV input has a header row. This accepts **Absent** or **Present** as values. The Default value is **Absent**. * valueSeparator (Separator): -Specify the separator to use in the CSV input. Default is the `,` (comma). +Specify the separator to use in the CSV input. Default is the `,` (comma). To use tab as the separator, use the + value `tab` to this property. To use space, use the value `space`. * skipHeader (Skip Headers): Skip the header row or not in the output CSV. This property accepts **true** or **false** as values. The Default is false. This is available only if the value of the `headerPresent` property is set to `Present`. diff --git a/docs/csv_to_json.md b/docs/csv_to_json.md index 54ec23e..f6bba0b 100644 --- a/docs/csv_to_json.md +++ b/docs/csv_to_json.md @@ -13,7 +13,8 @@ You can use the csvToJson operation to transform a CSV payload in to a JSON payl Specify whether the CSV input has a header row. This accepts **Absent** or **Present** as values. The Default value is **Absent**. * valueSeparator (Separator): -Specify the separator to use in the CSV input. Default is the `,` (comma). +Specify the separator to use in the CSV input. Default is the `,` (comma). To use tab as the separator, use the + value `tab` to this property. To use space, use the value `space`. This property accepts **true** or **false** as values. The Default is false. This is available only if the value of the `headerPresent` property is set to `Present`. * columnsToSkip (Skip Columns): diff --git a/docs/csv_to_xml.md b/docs/csv_to_xml.md index 8ca649d..b3d838a 100644 --- a/docs/csv_to_xml.md +++ b/docs/csv_to_xml.md @@ -13,7 +13,8 @@ You can use the csvToXml operation to transform a CSV payload in to an XML paylo Specify whether the CSV input has a header row. This accepts **Absent** or **Present** as values. The Default value is **Absent**. * valueSeparator (Separator): -Specify the separator to use in the CSV input. Default is the `,` (comma). +Specify the separator to use in the CSV input. Default is the `,` (comma). To use tab as the separator, use the + value `tab` to this property. To use space, use the value `space`. * skipHeader (Skip Headers): Skip the header row or not in the output CSV. This property accepts **true** or **false** as values. The Default is false. This is available only if the value of the `headerPresent` property is set to `Present`. diff --git a/src/main/java/org/wso2/carbon/module/csv/util/PropertyReader.java b/src/main/java/org/wso2/carbon/module/csv/util/PropertyReader.java index d920688..dd3591e 100644 --- a/src/main/java/org/wso2/carbon/module/csv/util/PropertyReader.java +++ b/src/main/java/org/wso2/carbon/module/csv/util/PropertyReader.java @@ -70,7 +70,18 @@ public static Optional getStringParam(SimpleMessageContext mc, String pa public static Optional getCharParam(SimpleMessageContext mc, String parameterKey) { Optional parameterValue = getStringParam(mc, parameterKey); - return parameterValue.map(s -> s.charAt(0)); + return parameterValue.map(PropertyReader::replaceWhitespaces); + } + + private static Character replaceWhitespaces(String text) { + + if (text.equals("tab")) { + return 9; + } else if (text.equals("space")) { + return 32; + } else { + return text.charAt(0); + } } /**