Title: [1536] trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java: JBEHAVE-237: Added check for null objects in escaping HTML/XML values.
Revision
1536
Author
mauro
Date
2010-01-30 03:20:41 -0600 (Sat, 30 Jan 2010)

Log Message

JBEHAVE-237:  Added check for null objects in escaping HTML/XML values.

Modified Paths

Diff

Modified: trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java (1535 => 1536)

--- trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java	2010-01-22 15:10:03 UTC (rev 1535)
+++ trunk/core/jbehave-core/src/main/java/org/jbehave/scenario/reporters/PrintStreamScenarioReporter.java	2010-01-30 09:20:41 UTC (rev 1536)
@@ -66,6 +66,8 @@
  */
 public class PrintStreamScenarioReporter implements ScenarioReporter {
 
+    private static final String EMPTY = "";
+
     public enum Format { PLAIN, HTML, XML }
     
     protected PrintStream output;
@@ -181,7 +183,7 @@
             print(format("examplesTableHeadCell", "{0}|", header));
         }
         print(format("examplesTableHeadEnd", "\n"));
-        print(format("examplesTableBodyStart", ""));
+        print(format("examplesTableBodyStart", EMPTY));
         for (Map<String, String> row : rows) {
             print(format("examplesTableRowStart", "|"));
             for (String header : headers) {
@@ -242,11 +244,15 @@
         Transformer escapingTransformer = new Transformer( ) {
             public Object transform(Object object) {
                 switch ( format ){
-                    case HTML: return escapeHtml(object.toString());
-                    case XML: return escapeXml(object.toString());
+                    case HTML: return escapeHtml(asString(object));
+                    case XML: return escapeXml(asString(object));
                     default: return object;
                 }
             }
+
+            private String asString(Object object) {
+                return  ( object != null ? object.toString() : EMPTY );
+            }
         };
         List<?> list = Arrays.asList( ArrayUtils.clone( args ) );
         CollectionUtils.transform( list, escapingTransformer );
@@ -287,8 +293,8 @@
      * @param text the String to print
      */
     protected void print(String text) {
-        output.print(text.replace(format(PARAMETER_VALUE_START, PARAMETER_VALUE_START), format("parameterValueStart", ""))
-                         .replace(format(PARAMETER_VALUE_END, PARAMETER_VALUE_END), format("parameterValueEnd", "")));
+        output.print(text.replace(format(PARAMETER_VALUE_START, PARAMETER_VALUE_START), format("parameterValueStart", EMPTY))
+                         .replace(format(PARAMETER_VALUE_END, PARAMETER_VALUE_END), format("parameterValueEnd", EMPTY)));
     }
 
 }


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to