sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1786639 - /sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
Date Mon, 13 Mar 2017 08:21:05 GMT
Author: radu
Date: Mon Mar 13 08:21:05 2017
New Revision: 1786639

URL: http://svn.apache.org/viewvc?rev=1786639&view=rev
Log:
SLING-6633 - [HTL] NumberFormat should support String-properties with number value

Modified:
    sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java

Modified: sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java?rev=1786639&r1=1786638&r2=1786639&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
(original)
+++ sling/trunk/bundles/scripting/sightly/java-compiler/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
Mon Mar 13 08:21:05 2017
@@ -35,6 +35,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
 import org.apache.sling.scripting.sightly.Record;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -75,7 +76,11 @@ public abstract class AbstractRuntimeObj
 
     @Override
     public boolean isNumber(Object target) {
-        return (target instanceof Number);
+        if (target == null) {
+            return false;
+        }
+        String value = toString(target);
+        return NumberUtils.isNumber(value);
     }
 
     @Override
@@ -102,10 +107,12 @@ public abstract class AbstractRuntimeObj
 
     @Override
     public Number toNumber(Object object) {
-        if (object instanceof Number) {
-            return (Number) object;
+        String stringValue = toString(object);
+        try {
+            return NumberUtils.createNumber(stringValue);
+        } catch (NumberFormatException e) {
+            return null;
         }
-        return null;
     }
 
     public Date toDate(Object object) {



Mime
View raw message