From 1c44182dea702b5a796a55054088838e1b9f1c7b Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Fri, 2 Oct 2020 09:41:34 +0200 Subject: [PATCH] minor changes --- .../eu/dnetlib/dhp/utils/saxon/NormalizeDate.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/NormalizeDate.java b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/NormalizeDate.java index 9fb60e1452..e1bc090ea6 100644 --- a/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/NormalizeDate.java +++ b/dhp-common/src/main/java/eu/dnetlib/dhp/utils/saxon/NormalizeDate.java @@ -10,6 +10,7 @@ import net.sf.saxon.om.Sequence; import net.sf.saxon.trans.XPathException; import net.sf.saxon.value.SequenceType; import net.sf.saxon.value.StringValue; +import org.apache.commons.lang3.StringUtils; public class NormalizeDate extends AbstractExtensionFunction { @@ -19,6 +20,8 @@ public class NormalizeDate extends AbstractExtensionFunction { private static final String normalizeOutFormat = "yyyy-MM-dd'T'hh:mm:ss'Z'"; + public static final String BLANK = ""; + @Override public String getName() { return "normalizeDate"; @@ -27,10 +30,10 @@ public class NormalizeDate extends AbstractExtensionFunction { @Override public Sequence doCall(XPathContext context, Sequence[] arguments) throws XPathException { if (arguments == null | arguments.length == 0) { - return new StringValue(""); + return new StringValue(BLANK); } String s = arguments[0].head().getStringValue(); - return new StringValue(_year(s)); + return new StringValue(_normalizeDate(s)); } @Override @@ -55,8 +58,8 @@ public class NormalizeDate extends AbstractExtensionFunction { return SequenceType.SINGLE_STRING; } - private String _year(String s) { - final String date = s != null ? s.trim() : ""; + private String _normalizeDate(String s) { + final String date = StringUtils.isNotBlank(s) ? s.trim() : BLANK; for (String format : normalizeDateFormats) { try { @@ -66,6 +69,6 @@ public class NormalizeDate extends AbstractExtensionFunction { } catch (ParseException e) { } } - return ""; + return BLANK; } }