From 2c6df2af8c5751d1ba68df589f4c0d228c401742 Mon Sep 17 00:00:00 2001 From: Thomas Lenz Date: Mon, 18 Jan 2016 16:29:04 +0100 Subject: add two methods to KeyValueUtils --- .../moa/id/commons/utils/KeyValueUtils.java | 43 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa') diff --git a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/KeyValueUtils.java b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/KeyValueUtils.java index 8f3a8402d..cbdd13d0e 100644 --- a/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/KeyValueUtils.java +++ b/id/server/moa-id-commons/src/main/java/at/gv/egovernment/moa/id/commons/utils/KeyValueUtils.java @@ -31,6 +31,8 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import org.apache.commons.lang3.StringUtils; + import at.gv.egovernment.moa.util.MiscUtil; /** @@ -40,6 +42,7 @@ import at.gv.egovernment.moa.util.MiscUtil; public class KeyValueUtils { public static final String KEY_DELIMITER = "."; + public static final String CSV_DELIMITER = ","; /** * Extract the first child of an input key after a the prefix @@ -237,7 +240,8 @@ public class KeyValueUtils { * Normalize a CSV encoded list of value of an key/value pair * * This method removes all whitespace at the begin or the - * end of CSV values + * end of CSV values and remove newLine signs at the end of value. + * The ',' is used as list delimiter * * @param value CSV encoded input data * @return normalized CSV encoded data or null if {value} is null or empty @@ -245,7 +249,7 @@ public class KeyValueUtils { public static String normalizeCSVValueString(String value) { String normalizedCodes = null; if (MiscUtil.isNotEmpty(value)) { - String[] codes = value.split(","); + String[] codes = value.split(CSV_DELIMITER); for (String el: codes) { if (normalizedCodes == null) normalizedCodes = el.trim(); @@ -256,4 +260,39 @@ public class KeyValueUtils { } return normalizedCodes; } + + + /** + * Check a String if it is a comma separated list of values + * + * This method uses the ',' as list delimiter. + * + * @param value CSV encoded input data + * @return true if the input data contains a ',' and has more then 1 list element, otherwise false + */ + public static boolean isCSVValueString(String value) { + if (MiscUtil.isNotEmpty(value)) { + String[] codes = value.split(CSV_DELIMITER); + if (codes.length >= 2) { + if (MiscUtil.isNotEmpty(codes[1].trim())) + return true; + + } + } + + return false; + } + + + /** + * This method remove all newline delimiter (\n or \r\n) from input data + * + * @param value Input String + * @return Input String without newline characters + */ + public static String removeAllNewlineFromString(String value) { + return value.replaceAll("(\\t|\\r?\\n)+", ""); + + } + } -- cgit v1.2.3