1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.latka;
18
19 import java.io.PrintWriter;
20 import java.io.Writer;
21
22 /***
23 * Provides more attractive HTML formatting for the runtime
24 * output of Latka. The characters printed during test
25 * execution ("." for success, "F" for failure, "E" for
26 * error, "S" for skipped) will be color coded,
27 * and a <wbr> tag will be inserted roughly
28 * every five characters
29 * to allow for line wrapping.
30 *
31 * @author Morgan Delagrange
32 * @author dIon Gillard (javadocs)
33 * @see XMLReporter#setPrintWriter(PrintWriter)
34 * @version $Revision: 155424 $
35 */
36 public class HtmlPrettyPrintWriter extends PrintWriter {
37
38 /*** number of characters written by the writer */
39 protected int _charsWritten = 0;
40
41 /***
42 * Create a HtmlPrettyPrintWriter wrapping an existing writer
43 * sends output to the wrapped writer
44 * @param writer any java.io.Writer
45 */
46 public HtmlPrettyPrintWriter(Writer writer) {
47 super(writer);
48 }
49
50 /***
51 * Write a string to the wrapped writer format it specially as per
52 * the class definition
53 * @param output a String to be written
54 */
55 public void print(String output) {
56
57 ++_charsWritten;
58
59 if (output == null) {
60 super.print(output);
61 } else if (output.equals(".")) {
62 super.print("<font color=\"green\">.</font>");
63 } else if (output.equals("S")) {
64 super.print("<font color=\"gray\">S</font>");
65 } else if (output.equals("F")) {
66 super.print("<font color=\"red\">F</font>");
67 } else if (output.equals("E")) {
68 super.print("<font color=\"red\">E</font>");
69 } else {
70 super.print(output);
71 }
72
73 if ((_charsWritten % 5) == 0) {
74 super.print("<wbr>");
75 }
76
77 }
78
79 }