aboutsummaryrefslogtreecommitdiff
path: root/velocity-engine-core/src/main/java/org/apache
diff options
context:
space:
mode:
authorClaude Brisson <cbrisson@apache.org>2018-10-15 08:33:36 +0000
committerClaude Brisson <cbrisson@apache.org>2018-10-15 08:33:36 +0000
commita41e3944b261c5aa8b158bf5e9b79a77f05a4f30 (patch)
tree61f50fcc67ce77e30ae9c0ae69d42fed3f4e926c /velocity-engine-core/src/main/java/org/apache
parentc34d23c7e9cb6941ba28f94275139dd682efef1f (diff)
downloadapache-velocity-engine-a41e3944b261c5aa8b158bf5e9b79a77f05a4f30.tar.gz
[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)
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1843883 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-core/src/main/java/org/apache')
-rw-r--r--velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java27
1 files changed, 22 insertions, 5 deletions
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java b/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java
index 30112a35..92edcbbd 100644
--- a/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java
+++ b/velocity-engine-core/src/main/java/org/apache/velocity/util/ExtProperties.java
@@ -1734,6 +1734,10 @@ public class ExtProperties extends Hashtable<String,Object>
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 Hashtable<String,Object>
}
else
{
-
return defaultValue;
}
}
@@ -1821,7 +1824,10 @@ public class ExtProperties extends Hashtable<String,Object>
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 Hashtable<String,Object>
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 Hashtable<String,Object>
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 Hashtable<String,Object>
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;