Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
HtmlPrettyPrintWriter |
|
| 4.0;4 |
1 | /* | |
2 | * Copyright 1999-2002,2004 The Apache Software Foundation. | |
3 | * | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
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 | 0 | 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 | 0 | super(writer); |
48 | 0 | } |
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 | 0 | ++_charsWritten; |
58 | ||
59 | 0 | if (output == null) { |
60 | 0 | super.print(output); |
61 | 0 | } else if (output.equals(".")) { |
62 | 0 | super.print("<font color=\"green\">.</font>"); |
63 | 0 | } else if (output.equals("S")) { |
64 | 0 | super.print("<font color=\"gray\">S</font>"); |
65 | 0 | } else if (output.equals("F")) { |
66 | 0 | super.print("<font color=\"red\">F</font>"); |
67 | 0 | } else if (output.equals("E")) { |
68 | 0 | super.print("<font color=\"red\">E</font>"); |
69 | } else { | |
70 | 0 | super.print(output); |
71 | } | |
72 | ||
73 | 0 | if ((_charsWritten % 5) == 0) { |
74 | 0 | super.print("<wbr>"); |
75 | } | |
76 | ||
77 | 0 | } |
78 | ||
79 | } |