1 package net.jaekl.cfb.analyze;
4 import java.io.IOException;
5 import java.io.PrintWriter;
7 import net.jaekl.cfb.CfbBundle;
8 import net.jaekl.cfb.store.Location;
9 import net.jaekl.cfb.util.Command;
10 import net.jaekl.cfb.xml.BugInstance;
11 import net.jaekl.cfb.xml.messages.BugPattern;
12 import net.jaekl.cfb.xml.messages.MessageCollection;
14 public class HtmlReport {
17 MessageCollection m_msgColl;
19 public HtmlReport(CfbBundle bundle, MessageCollection msgColl, Delta delta)
26 public Delta getDelta() { return m_delta; }
28 public void write(File output) throws IOException
30 try ( PrintWriter pw = new PrintWriter(output, Command.UTF_8) )
37 void write(PrintWriter pw)
42 void startPage(PrintWriter pw)
45 pw.println(" <BODY>");
47 pw.println(" </BODY>");
48 pw.println("</HTML>");
51 String trans(String key, Object... arguments) {
52 return m_bundle.get(key, arguments);
55 void writeBody(PrintWriter pw)
58 writeBugs(pw, CfbBundle.NEW_BUGS, m_delta.getNew());
59 writeBugs(pw, CfbBundle.FIXED_BUGS, m_delta.getFixed());
60 writeBugs(pw, CfbBundle.OLD_BUGS, m_delta.getCommon());
63 void writeBugLocations(PrintWriter pw, BugInstance bug)
65 for (Location loc : bug.getLocations()) {
66 StringBuffer sb = new StringBuffer();
69 if (null != loc.getClassName()) {
70 sb.append(loc.getClassName());
72 if ((null != loc.getMethodName()) && (loc.getMethodName().length() > 0)) {
73 sb.append(".").append(loc.getMethodName()).append("()");
75 int start = loc.getStart();
76 int end = loc.getEnd();
78 sb.append(":").append("" + start);
79 if ((end > 0) && (end > start)) {
80 sb.append("-").append("" + end);
84 if (null != loc.getMethodRole()) {
85 sb.append(" (" + loc.getMethodRole() + ")");
90 pw.write(" <TD COLSPAN=\"2\" CLASS=\"Loc\">" + sb.toString() + "</TD>");
95 void writeBugs(PrintWriter pw, String key, BugInstance[] bugs)
97 if (null == bugs || bugs.length < 1) {
101 writeSectionHeading(pw, trans(key));
103 for (BugInstance bug : bugs) {
104 BugPattern pattern = m_msgColl.getPattern(bug.getType());
107 pw.write(" <TABLE CLASS=\"bug\">");
109 pw.write(" <TD WIDTH=\"20%\">" + bug.getCategory() + "</TD>");
110 pw.write(" <TD>" + bug.getType() + "</TD>");
112 writeBugLocations(pw, bug);
114 pw.write(" <TD COLSPAN=\"2\">" + pattern.getShort() + "</TD>");
117 pw.write(" <TD COLSPAN=\"2\">" + pattern.getDetails() + "</TD>");
119 pw.write(" </TABLE>");
124 void writeHeader(PrintWriter pw)
126 String title = trans(CfbBundle.CFB_REPORT);
128 pw.println("<HTML>");
129 pw.println(" <HEAD>");
130 pw.println(" <META CHARSET=\"UTF-8\"/>");
131 pw.println(" <TITLE>" + title + "</TITLE>");
133 pw.println(" </HEAD>");
136 void writeSectionHeading(PrintWriter pw, String heading)
138 pw.println(" <P CLASS=\"SectionHead\">");
139 pw.println(" <TABLE WIDTH=\"100%\"><TR><TD>" + heading + "</TD></TR></TABLE>");
143 void writeSummary(PrintWriter pw)
145 final String SEP = ": ";
147 writeSectionHeading(pw, trans(CfbBundle.CFB_REPORT));
149 pw.println(" <TABLE>");
151 pw.println(" <TD CLASS=\"CategoryName\">" + trans(CfbBundle.NEW_VERSION) + SEP + "</TD>");
152 pw.println(" <TD CLASS=\"CategoryValue\">" + m_delta.getLater().constructVersionText(m_bundle) + "</TD>");
153 pw.println(" </TR>");
155 pw.println(" <TD CLASS=\"CategoryName\">" + trans(CfbBundle.OLD_VERSION) + SEP + "</TD>");
156 pw.println(" <TD CLASS=\"CategoryValue\">" + m_delta.getEarlier().constructVersionText(m_bundle) + "</TD>");
157 pw.println(" </TR>");
158 pw.println(" <TR><TD> </TD></TR>");
160 pw.println(" <TD CLASS=\"CategoryName\">" + trans(CfbBundle.NEW_BUGS) + SEP + "</TD>");
161 pw.println(" <TD CLASS=\"CategoryValue\">" + trans(CfbBundle.NUM_BUGS, m_delta.getNumNew()) + "</TD>");
162 pw.println(" </TR>");
164 pw.println(" <TD CLASS=\"CategoryName\">" + trans(CfbBundle.FIXED_BUGS) + SEP + "</TD>");
165 pw.println(" <TD CLASS=\"CategoryValue\">" + trans(CfbBundle.NUM_BUGS, m_delta.getNumFixed()) + "</TD>");
166 pw.println(" </TR>");
168 pw.println(" <TD CLASS=\"CategoryName\">" + trans(CfbBundle.OLD_BUGS) + SEP + "</TD>");
169 pw.println(" <TD CLASS=\"CategoryValue\">" + trans(CfbBundle.NUM_BUGS_OLD, m_delta.getNumCommon()) + "</TD>");
170 pw.println(" </TR>");
171 pw.println(" </TABLE>");
175 void writeStyle(PrintWriter pw)
177 pw.println(" <STYLE>");
178 pw.println(" body { background-color: #F0F0FF; }");
179 pw.println(" .CategoryName { text-align: right; }");
180 pw.println(" .CategoryValue { text-align: left; }");
181 pw.println(" .Loc { font-family: monospace; }");
182 pw.println(" .SectionHead td { background-color: #0000FF; color: #FFFFFF; font-size: 1.25em; font-weight: bold; }");
183 pw.println(" </STYLE>");