1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3  FindBugs - Find bugs in Java programs
4  Copyright (C) 2004,2005 University of Maryland
5  Copyright (C) 2005, Chris Nappin
6
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  Lesser General Public License for more details.
16
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20-->
21<xsl:stylesheet version="1.0"
22	xmlns="http://www.w3.org/1999/xhtml"
23	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
24
25<xsl:output
26	method="xml"
27	omit-xml-declaration="yes"
28	standalone="yes"
29         doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
30         doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
31	indent="yes"
32	encoding="UTF-8"/>
33
34<xsl:variable name="bugTableHeader">
35	<tr class="tableheader">
36		<th align="left">Warning</th>
37		<th align="left">Priority</th>
38		<th align="left">Details</th>
39	</tr>
40</xsl:variable>
41
42<xsl:template match="/">
43	<html>
44	<head>
45		<title>FindBugs Report</title>
46		<style type="text/css">
47		.tablerow0 {
48			background: #EEEEEE;
49		}
50
51		.tablerow1 {
52			background: white;
53		}
54
55		.detailrow0 {
56			background: #EEEEEE;
57		}
58
59		.detailrow1 {
60			background: white;
61		}
62
63		.tableheader {
64			background: #b9b9fe;
65			font-size: larger;
66		}
67		</style>
68	</head>
69
70	<xsl:variable name="unique-catkey" select="/BugCollection/BugCategory/@category"/>
71
72	<body>
73
74	<h1>FindBugs Report</h1>
75		<p>Produced using <a href="http://findbugs.sourceforge.net">FindBugs</a> <xsl:value-of select="/BugCollection/@version"/>.</p>
76		<p>Project:
77			<xsl:choose>
78				<xsl:when test='string-length(/BugCollection/Project/@projectName)>0'><xsl:value-of select="/BugCollection/Project/@projectName" /></xsl:when>
79				<xsl:otherwise><xsl:value-of select="/BugCollection/Project/@filename" /></xsl:otherwise>
80			</xsl:choose>
81		</p>
82	<h2>Metrics</h2>
83	<xsl:apply-templates select="/BugCollection/FindBugsSummary"/>
84
85	<h2>Summary</h2>
86	<table width="500" cellpadding="5" cellspacing="2">
87	    <tr class="tableheader">
88			<th align="left">Warning Type</th>
89			<th align="right">Number</th>
90		</tr>
91
92	<xsl:for-each select="$unique-catkey">
93		<xsl:sort select="." order="ascending"/>
94		<xsl:variable name="catkey" select="."/>
95		<xsl:variable name="catdesc" select="/BugCollection/BugCategory[@category=$catkey]/Description"/>
96		<xsl:variable name="styleclass">
97			<xsl:choose><xsl:when test="position() mod 2 = 1">tablerow0</xsl:when>
98				<xsl:otherwise>tablerow1</xsl:otherwise>
99			</xsl:choose>
100		</xsl:variable>
101
102		<tr class="{$styleclass}">
103			<td><a href="#Warnings_{$catkey}"><xsl:value-of select="$catdesc"/> Warnings</a></td>
104			<td align="right"><xsl:value-of select="count(/BugCollection/BugInstance[(@category=$catkey) and (not(@last))])"/></td>
105		</tr>
106	</xsl:for-each>
107
108	<xsl:variable name="styleclass">
109		<xsl:choose><xsl:when test="count($unique-catkey) mod 2 = 0">tablerow0</xsl:when>
110			<xsl:otherwise>tablerow1</xsl:otherwise>
111		</xsl:choose>
112	</xsl:variable>
113		<tr class="{$styleclass}">
114		    <td><b>Total</b></td>
115		    <td align="right"><b><xsl:value-of select="count(/BugCollection/BugInstance[not(@last)])"/></b></td>
116		</tr>
117	</table>
118	<p><br/><br/></p>
119
120	<h1>Warnings</h1>
121
122	<p>Click on each warning link to see a full description of the issue, and
123	    details of how to resolve it.</p>
124
125	<xsl:for-each select="$unique-catkey">
126		<xsl:sort select="." order="ascending"/>
127		<xsl:variable name="catkey" select="."/>
128		<xsl:variable name="catdesc" select="/BugCollection/BugCategory[@category=$catkey]/Description"/>
129
130		<xsl:call-template name="generateWarningTable">
131			<xsl:with-param name="warningSet" select="/BugCollection/BugInstance[(@category=$catkey) and (not(@last))]"/>
132			<xsl:with-param name="sectionTitle"><xsl:value-of select="$catdesc"/> Warnings</xsl:with-param>
133			<xsl:with-param name="sectionId">Warnings_<xsl:value-of select="$catkey"/></xsl:with-param>
134		</xsl:call-template>
135	</xsl:for-each>
136
137    <p><br/><br/></p>
138	<h1><a name="Details">Warning Types</a></h1>
139
140	<xsl:apply-templates select="/BugCollection/BugPattern">
141		<xsl:sort select="@abbrev"/>
142		<xsl:sort select="ShortDescription"/>
143	</xsl:apply-templates>
144
145	</body>
146	</html>
147</xsl:template>
148
149<xsl:template match="BugInstance[not(@last)]">
150	<xsl:variable name="warningId"><xsl:value-of select="generate-id()"/></xsl:variable>
151
152	<tr class="tablerow{position() mod 2}">
153		<td width="20%" valign="top">
154			<a href="#{@type}"><xsl:value-of select="ShortMessage"/></a>
155		</td>
156		<td width="10%" valign="top">
157			<xsl:choose>
158				<xsl:when test="@priority = 1">High</xsl:when>
159				<xsl:when test="@priority = 2">Medium</xsl:when>
160				<xsl:when test="@priority = 3">Low</xsl:when>
161				<xsl:otherwise>Unknown</xsl:otherwise>
162			</xsl:choose>
163		</td>
164		<td width="70%">
165		    <p><xsl:value-of select="LongMessage"/><br/><br/>
166
167		    	<!--  add source filename and line number(s), if any -->
168				<xsl:if test="SourceLine">
169					<br/>In file <xsl:value-of select="SourceLine/@sourcefile"/>,
170					<xsl:choose>
171						<xsl:when test="SourceLine/@start = SourceLine/@end">
172						line <xsl:value-of select="SourceLine/@start"/>
173						</xsl:when>
174						<xsl:otherwise>
175						lines <xsl:value-of select="SourceLine/@start"/>
176						    to <xsl:value-of select="SourceLine/@end"/>
177						</xsl:otherwise>
178					</xsl:choose>
179				</xsl:if>
180
181				<xsl:for-each select="./*/Message">
182					<br/><xsl:value-of select="text()"/>
183				</xsl:for-each>
184		    </p>
185		</td>
186	</tr>
187</xsl:template>
188
189<xsl:template match="BugPattern">
190	<h2><a name="{@type}"><xsl:value-of select="ShortDescription"/></a></h2>
191	<xsl:value-of select="Details" disable-output-escaping="yes"/>
192	<p><br/><br/></p>
193</xsl:template>
194
195<xsl:template name="generateWarningTable">
196	<xsl:param name="warningSet"/>
197	<xsl:param name="sectionTitle"/>
198	<xsl:param name="sectionId"/>
199
200	<h2><a name="{$sectionId}"><xsl:value-of select="$sectionTitle"/></a></h2>
201	<table class="warningtable" width="100%" cellspacing="2" cellpadding="5">
202		<xsl:copy-of select="$bugTableHeader"/>
203		<xsl:choose>
204		    <xsl:when test="count($warningSet) &gt; 0">
205				<xsl:apply-templates select="$warningSet">
206					<xsl:sort select="@priority"/>
207					<xsl:sort select="@abbrev"/>
208					<xsl:sort select="Class/@classname"/>
209				</xsl:apply-templates>
210		    </xsl:when>
211		    <xsl:otherwise>
212		        <tr><td colspan="2"><p><i>None</i></p></td></tr>
213		    </xsl:otherwise>
214		</xsl:choose>
215	</table>
216	<p><br/><br/></p>
217</xsl:template>
218
219<xsl:template match="FindBugsSummary">
220    <xsl:variable name="kloc" select="@total_size div 1000.0"/>
221    <xsl:variable name="format" select="'#######0.00'"/>
222
223	<p><xsl:value-of select="@total_size"/> lines of code analyzed,
224	in <xsl:value-of select="@total_classes"/> classes,
225	in <xsl:value-of select="@num_packages"/> packages.</p>
226	<table width="500" cellpadding="5" cellspacing="2">
227	    <tr class="tableheader">
228			<th align="left">Metric</th>
229			<th align="right">Total</th>
230			<th align="right">Density*</th>
231		</tr>
232		<tr class="tablerow0">
233			<td>High Priority Warnings</td>
234			<td align="right"><xsl:value-of select="@priority_1"/></td>
235			<td align="right">
236                <xsl:choose>
237                    <xsl:when test= "number($kloc) &gt; 0.0">
238       			        <xsl:value-of select="format-number(@priority_1 div $kloc, $format)"/>
239                    </xsl:when>
240                    <xsl:otherwise>
241      		            <xsl:value-of select="format-number(0.0, $format)"/>
242                    </xsl:otherwise>
243		        </xsl:choose>
244			</td>
245		</tr>
246		<tr class="tablerow1">
247			<td>Medium Priority Warnings</td>
248			<td align="right"><xsl:value-of select="@priority_2"/></td>
249			<td align="right">
250                <xsl:choose>
251                    <xsl:when test= "number($kloc) &gt; 0.0">
252       			        <xsl:value-of select="format-number(@priority_2 div $kloc, $format)"/>
253                    </xsl:when>
254                    <xsl:otherwise>
255      		            <xsl:value-of select="format-number(0.0, $format)"/>
256                    </xsl:otherwise>
257		        </xsl:choose>
258			</td>
259		</tr>
260
261    <xsl:choose>
262		<xsl:when test="@priority_3">
263			<tr class="tablerow1">
264				<td>Low Priority Warnings</td>
265				<td align="right"><xsl:value-of select="@priority_3"/></td>
266				<td align="right">
267	                <xsl:choose>
268	                    <xsl:when test= "number($kloc) &gt; 0.0">
269	       			        <xsl:value-of select="format-number(@priority_3 div $kloc, $format)"/>
270	                    </xsl:when>
271	                    <xsl:otherwise>
272	      		            <xsl:value-of select="format-number(0.0, $format)"/>
273	                    </xsl:otherwise>
274			        </xsl:choose>
275				</td>
276			</tr>
277			<xsl:variable name="totalClass" select="tablerow0"/>
278		</xsl:when>
279		<xsl:otherwise>
280		    <xsl:variable name="totalClass" select="tablerow1"/>
281		</xsl:otherwise>
282	</xsl:choose>
283
284		<tr class="$totalClass">
285			<td><b>Total Warnings</b></td>
286			<td align="right"><b><xsl:value-of select="@total_bugs"/></b></td>
287			<td align="right">
288				<b>
289                <xsl:choose>
290                    <xsl:when test= "number($kloc) &gt; 0.0">
291       			        <xsl:value-of select="format-number(@total_bugs div $kloc, $format)"/>
292                    </xsl:when>
293                    <xsl:otherwise>
294      		            <xsl:value-of select="format-number(0.0, $format)"/>
295                    </xsl:otherwise>
296		        </xsl:choose>
297				</b>
298			</td>
299		</tr>
300	</table>
301	<p><i>(* Defects per Thousand lines of non-commenting source statements)</i></p>
302	<p><br/><br/></p>
303
304</xsl:template>
305
306</xsl:stylesheet>
307