From 7a87866adb979aec94a529f3ad928ef6de72acc6 Mon Sep 17 00:00:00 2001 From: Jeanette Clark Date: Wed, 6 Dec 2023 11:02:38 -0700 Subject: [PATCH] only convert numeric looking things if they don't have a leading 0 --- .../nceas/mdqengine/processor/XMLDialect.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/edu/ucsb/nceas/mdqengine/processor/XMLDialect.java b/src/main/java/edu/ucsb/nceas/mdqengine/processor/XMLDialect.java index c1934f30..4c3491fb 100644 --- a/src/main/java/edu/ucsb/nceas/mdqengine/processor/XMLDialect.java +++ b/src/main/java/edu/ucsb/nceas/mdqengine/processor/XMLDialect.java @@ -258,7 +258,6 @@ public Result runCheck(Check check) throws XPathExpressionException { result.setStatus(Status.ERROR); result.setOutput(new Output(e.getMessage())); } - //dispatcher.close(); } else { // we just skip instead @@ -361,6 +360,7 @@ private Object selectPath(Selector selector, Node contextNode) throws XPathExpre // select one or more values from document String selectorPath = selector.getXpath(); + XPath xpath = xPathfactory.newXPath(); // combine the found namespaces and any additional ones asserted by selector. @@ -454,22 +454,28 @@ else if (nodes.getLength() > 0 || selector.getSubSelector() != null) { /* * Retype an object based on a few simple assumptions. A "String" value is * typically passed in. If only numeric characters are present in the String, - * then - * the object is caste to type "Number". If the string value appears to be an - * "affermative" or "negative" value (e.g. "Y", "Yes", "N", "No", ...) then the - * value is caste to "Boolean". + * then the object is caste to type "Number". If the string value appears to + * be an "affirmative" or "negative" value (e.g. "Y", "Yes", "N", "No", ...) + * then the value is caste to "Boolean". */ public static Object retypeObject(Object value) { Object result = value; - // type the value correctly - if (NumberUtils.isNumber((String) value)) { - result = NumberUtils.createNumber((String) value); - } else { - // relies on this method to return null if we are not sure if it is a boolean - Boolean bool = BooleanUtils.toBooleanObject((String) value); - if (bool != null) { - result = bool; + + if (value instanceof String) { + String stringValue = (String) value; + // try to type the value correctly + if (NumberUtils.isNumber(stringValue) && !stringValue.matches("^0\\d*$")) { + // If it's a valid number and doesn't start with zeros, create a Number object + result = NumberUtils.createNumber(stringValue); + } else { + // try to convert to bool + Boolean bool = BooleanUtils.toBooleanObject((String) value); + // if it worked, return the boolean, otherwise the original result is returned + if (bool != null) { + result = bool; + } } + } return result;