Author: hfnukal
Date: 2012-06-05 10:03:10 -0400 (Tue, 05 Jun 2012)
New Revision: 8713
Modified:
epp/portal/branches/EPP_5_2_Branch/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyPrinter.java
epp/portal/branches/EPP_5_2_Branch/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
Log:
Bug 824863 - groovy template should not print "null" string when variable is
null
Modified:
epp/portal/branches/EPP_5_2_Branch/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyPrinter.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyPrinter.java 2012-05-31
21:18:12 UTC (rev 8712)
+++
epp/portal/branches/EPP_5_2_Branch/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyPrinter.java 2012-06-05
14:03:10 UTC (rev 8713)
@@ -125,7 +125,7 @@
Object f = format(o);
if (f == null)
{
- return "null";
+ return "";
}
else if (f instanceof String)
{
@@ -152,6 +152,10 @@
for (int i = 0;i < values.length;i++)
{
values[i] = format(values[i]);
+ if (values[i] == null)
+ {
+ values[i] = "";
+ }
}
write(o.toString());
}
Modified:
epp/portal/branches/EPP_5_2_Branch/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2012-05-31
21:18:12 UTC (rev 8712)
+++
epp/portal/branches/EPP_5_2_Branch/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2012-06-05
14:03:10 UTC (rev 8713)
@@ -189,6 +189,15 @@
assertEquals("\"", s);
}
+ public void testNullVariable() throws Exception
+ {
+ GroovyTemplate template = new GroovyTemplate("<%
out.print(\"${foo}\") %>");
+ Map<String, String> context = new HashMap<String, String>();
+ context.put("foo", null);
+ String s = template.render(context);
+ assertEquals("", s);
+ }
+
public void testFooFoo() throws Exception
{
InputStream in =
Thread.currentThread().getContextClassLoader().getResourceAsStream("UIPortalApplication.gtmpl");