File: HTMLComparisonWriter.java

package info (click to toggle)
mauve 20161030-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 44,628 kB
  • ctags: 35,425
  • sloc: java: 336,555; sh: 2,834; xml: 208; makefile: 72
file content (153 lines) | stat: -rw-r--r-- 5,660 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright (c) 2008 Fabien DUMINY (fduminy@jnode.org)

// This file is part of Mauve.

// Mauve is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.

// Mauve is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Mauve; see the file COPYING.  If not, write to
// the Free Software Foundation, 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.  */

package gnu.testlet.runner.compare;

import gnu.testlet.runner.XMLReportWriter;

import java.io.PrintWriter;
import java.util.List;

/**
 * Writer in HTML format for a {@link Comparison}
 * @author fabien
 *
 */
public class HTMLComparisonWriter extends ComparisonWriter {
    //@Override
    protected Visitor createVisitor(PrintWriter pw) {
        return new HTMLVisitor(pw);
    }
    
    protected static class HTMLVisitor extends Visitor { 
        private HTMLVisitor(PrintWriter pw) {
            super(pw);
        }
        
        //@Override
        protected void writeSummary(int nbRegressions, int nbProgressions, int nbStagnations) {
            pw.append("<h2>Summary</h2>");
            appendLink(nbRegressions, EvolutionType.REGRESSION, " regressions. ");            
            appendLink(nbProgressions, EvolutionType.PROGRESSION, " progressions. ");
            appendLink(nbStagnations, EvolutionType.STAGNATION, " stagnations. ");
        }
        
        protected void writeSystemProperties(List systemProperties, String result1Name, String result2Name) {
            pw.append("<br/><h2>System properties</h2><br/>");            
            pw.append("<table border=\"1\" cellspacing=\"1\" cellpadding=\"1\"><tr>");
            
            writeCell("th", 0, 1, "Name");            
            writeCell("th", 0, 1, result1Name);
            writeCell("th", 0, 1, result2Name);
            
            pw.append("</tr>\n");
            for (int i = 0; i < systemProperties.size(); ) {
                pw.append("<tr>");
                writeCell("td", 0, 1, (String) systemProperties.get(i++));
                writeCell("td", 0, 1, (String) systemProperties.get(i++));
                writeCell("td", 0, 1, (String) systemProperties.get(i++));
                pw.append("</tr>");
            }
            pw.append("</table><br/>");
        }
        
        private void appendLink(int value, EvolutionType type, String label) {
            pw.append("<a href=\"#").append(type.toString()).append("\">");
            pw.append(Integer.toString(value)).append(label);
            pw.append("</a>").append("&nbsp;&nbsp;&nbsp;");
        }
        
        public void writeBegin() {
            pw.append("<html><head></head><body>");
        }

        public void writeEnd() {
            pw.append("</body></html>\n");
        }

        public void writeBeginTable() {
            pw.append("<br/><h2 id=\"").append(type.toString()).append("\">");
            pw.append(evolutionLabel);
            pw.append("</h2><br/>");
            
            pw.append("<table border=\"1\" cellspacing=\"1\" cellpadding=\"1\"><tr>");
            
            writeCell("th", 0, Level.values().length, "Name");            
            writeCell("th", 0, 1, "Last reached checkpoint");
            
            pw.append("</tr>\n");
        }

        public void writeEndTable() {
            pw.append("\n</table>");
        }

        //@Override
        protected void writeBeginLine(Level level) {
            writeIndent(level);
            pw.write("<tr>");
        }
        
        //@Override
        protected void writeName(Level level, String name) {
            writeCell("td", level.getValue(), 1 + Level.MAX.getValue() - level.getValue(), name);
        }
        
        //@Override
        protected void writeEndLine() {
            pw.write("</tr>\n");
        }
        
        //@Override
        protected void writeCheckResult(String result) {
            writeCell("td", 0, 1, result);
        }

        private void writeCell(String tag, int nbColumnsBefore, int columnSpan, String value) {
            writeCell(tag, nbColumnsBefore, columnSpan, value, null);
        }

        private void writeCell(String tag, int nbColumnsBefore, int columnSpan, String value, String style) {
            writeCell(tag, nbColumnsBefore, columnSpan, value, style, null);
        }
        
        private void writeCell(String tag, int nbColumnsBefore, int columnSpan, String value, 
                               String style, String bgColor) {
            for (int i = 0; i < nbColumnsBefore; i++) {
                pw.append("<").append(tag).append(" width=\"30px\"></").append(tag).append(">");
            }
            
            pw.append("<").append(tag);
            if (style != null) {
                pw.append(" style=\"").append(style).append('\"');
            }
            if (columnSpan > 1) {
                pw.append(" colspan=\"").append(Integer.toString(columnSpan)).append('\"');
            }
            if (bgColor != null) {
                pw.append(" bgcolor=\"").append(bgColor).append('\"');
            }
            
            pw.append('>');
            
            pw.append(XMLReportWriter.protect(value));
            pw.append("</").append(tag).append(">");
        }
    };
}