001 /* 002 * Copyright 1999-2002,2004 The Apache Software Foundation. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.apache.commons.latka; 018 019 import java.io.PrintWriter; 020 import java.io.Writer; 021 022 /** 023 * Provides more attractive HTML formatting for the runtime 024 * output of Latka. The characters printed during test 025 * execution ("." for success, "F" for failure, "E" for 026 * error, "S" for skipped) will be color coded, 027 * and a <wbr> tag will be inserted roughly 028 * every five characters 029 * to allow for line wrapping. 030 * 031 * @author Morgan Delagrange 032 * @author dIon Gillard (javadocs) 033 * @see XMLReporter#setPrintWriter(PrintWriter) 034 * @version $Revision: 155424 $ 035 */ 036 public class HtmlPrettyPrintWriter extends PrintWriter { 037 038 /** number of characters written by the writer */ 039 protected int _charsWritten = 0; 040 041 /** 042 * Create a HtmlPrettyPrintWriter wrapping an existing writer 043 * sends output to the wrapped writer 044 * @param writer any java.io.Writer 045 */ 046 public HtmlPrettyPrintWriter(Writer writer) { 047 super(writer); 048 } 049 050 /** 051 * Write a string to the wrapped writer format it specially as per 052 * the class definition 053 * @param output a String to be written 054 */ 055 public void print(String output) { 056 057 ++_charsWritten; 058 059 if (output == null) { 060 super.print(output); 061 } else if (output.equals(".")) { 062 super.print("<font color=\"green\">.</font>"); 063 } else if (output.equals("S")) { 064 super.print("<font color=\"gray\">S</font>"); 065 } else if (output.equals("F")) { 066 super.print("<font color=\"red\">F</font>"); 067 } else if (output.equals("E")) { 068 super.print("<font color=\"red\">E</font>"); 069 } else { 070 super.print(output); 071 } 072 073 if ((_charsWritten % 5) == 0) { 074 super.print("<wbr>"); 075 } 076 077 } 078 079 }