You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 10:11:17 UTC

[sling-org-apache-sling-scripting-sightly-compiler-java] 26/31: SLING-6633 - [HTL] NumberFormat should support String-properties with number value

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.scripting.sightly.compiler.java-1.0.10
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-compiler-java.git

commit d317aad5720018f13bf7f3424b93d9896ae8a4c2
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Mar 13 08:21:05 2017 +0000

    SLING-6633 - [HTL] NumberFormat should support String-properties with number value
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/scripting/sightly/java-compiler@1786639 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sightly/render/AbstractRuntimeObjectModel.java        | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
index 4b512c3..aae53e4 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/render/AbstractRuntimeObjectModel.java
@@ -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 AbstractRuntimeObjectModel implements RuntimeObjectModel {
 
     @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 AbstractRuntimeObjectModel implements RuntimeObjectModel {
 
     @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) {

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.