You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by cb...@apache.org on 2018/10/15 08:33:36 UTC

svn commit: r1843883 - /velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java

Author: cbrisson
Date: Mon Oct 15 08:33:36 2018
New Revision: 1843883

URL: http://svn.apache.org/viewvc?rev=1843883&view=rev
Log:
[VELOCITY-850] Better number conversion support in ExpProperties and allow the initial Properties object to contain non-string values (even if putting sthing else than strings in Properties is strongly discouraged, supporting it doesn't do any harm)

Modified:
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java?rev=1843883&r1=1843882&r2=1843883&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java Mon Oct 15 08:33:36 2018
@@ -1734,6 +1734,10 @@ public class ExtProperties extends Hasht
             return (Integer) value;
 
         }
+        else if (value instanceof Number)
+        {
+            return ((Number)value).intValue();
+        }
         else if (value instanceof String)
         {
             Integer i = Integer.valueOf((String) value);
@@ -1749,7 +1753,6 @@ public class ExtProperties extends Hasht
             }
             else
             {
-
                 return defaultValue;
             }
         }
@@ -1821,7 +1824,10 @@ public class ExtProperties extends Hasht
         if (value instanceof Long)
         {
             return (Long) value;
-
+        }
+        else if (value instanceof Number)
+        {
+            return ((Number)value).longValue();
         }
         else if (value instanceof String)
         {
@@ -1912,6 +1918,10 @@ public class ExtProperties extends Hasht
             return (Float) value;
 
         }
+        else if (value instanceof Number)
+        {
+            return ((Number)value).floatValue();
+        }
         else if (value instanceof String)
         {
             Float f = new Float((String) value);
@@ -1999,14 +2009,16 @@ public class ExtProperties extends Hasht
         if (value instanceof Double)
         {
             return (Double) value;
-
+        }
+        else if (value instanceof Number)
+        {
+            return ((Number)value).doubleValue();
         }
         else if (value instanceof String)
         {
             Double d = new Double((String) value);
             put(key, d);
             return d;
-
         }
         else if (value == null)
         {
@@ -2043,7 +2055,12 @@ public class ExtProperties extends Hasht
         for (Enumeration e = props.propertyNames(); e.hasMoreElements();)
         {
             String s = (String) e.nextElement();
-            c.setProperty(s, props.getProperty(s));
+            /*
+             * We use get() and not getProperty() in case the user didn't
+             * respect the Properties contract of only holding strings.
+             * Sun's fault.
+             */
+            c.setProperty(s, props.get(s));
         }
 
         return c;