source: local/greenstone3/darwin-64bit/apache-ant-1.9.6/etc/checkstyle/checkstyle-frames-sortby-check.xsl@ 30383

Last change on this file since 30383 was 30383, checked in by davidb, 8 years ago

Newer version of ant needed to compile GS3

File size: 11.9 KB
Line 
1<?xml version="1.0"?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
3 xmlns:lxslt="http://xml.apache.org/xslt"
4 xmlns:redirect="http://xml.apache.org/xalan/redirect"
5 extension-element-prefixes="redirect">
6
7<!--
8 Licensed to the Apache Software Foundation (ASF) under one or more
9 contributor license agreements. See the NOTICE file distributed with
10 this work for additional information regarding copyright ownership.
11 The ASF licenses this file to You under the Apache License, Version 2.0
12 (the "License"); you may not use this file except in compliance with
13 the License. You may obtain a copy of the License at
14
15 http://www.apache.org/licenses/LICENSE-2.0
16
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22-->
23
24 <xsl:output method="html" indent="yes" encoding="US-ASCII"/>
25 <xsl:decimal-format decimal-separator="." grouping-separator="," />
26
27 <xsl:param name="output.dir" select="'.'"/>
28 <xsl:param name="basedir" select="'.'"/>
29
30
31
32 <!--
33 Matches the root element of the data and starts the generation.
34 -->
35 <xsl:template match="checkstyle">
36 <!-- create the sorted.html with the data -->
37 <redirect:write file="{$output.dir}/sorted.html">
38 <xsl:call-template name="sorted.html"/>
39 </redirect:write>
40
41 <!-- create the stylesheet.css with layout -->
42 <redirect:write file="{$output.dir}/sorted.css">
43 <xsl:call-template name="sorted.css"/>
44 </redirect:write>
45
46 <!-- create the switch.js for collepsing the data -->
47 <redirect:write file="{$output.dir}/switch.js">
48 <xsl:call-template name="switch.js"/>
49 </redirect:write>
50 </xsl:template>
51
52
53
54 <!--
55 Generates the HTML page with the data.
56 -->
57 <xsl:template name="sorted.html">
58 <html>
59 <head>
60 <title>CheckStyle Audit</title>
61 <script language="JavaScript" src="switch.js" type="text/javascript"></script>
62 <link rel="stylesheet" type="text/css" href="sorted.css"/>
63 </head>
64 <body onload="javascript:openFirst();">
65 <h1>CheckStyle Audit</h1>
66 <p>Designed for use with
67 <a href='http://checkstyle.sourceforge.net/'>CheckStyle</a> and
68 <a href='http://ant.apache.org/'>Ant</a>.
69 </p>
70 <xsl:apply-templates select="." mode="navigation"/>
71 <xsl:apply-templates select="." mode="data"/>
72 </body>
73 </html>
74 </xsl:template>
75
76
77
78 <!--
79 Key for detecting duplicate CheckModules
80 -->
81 <xsl:key name="module" match="file/error" use="@source"/>
82
83
84
85 <!--
86 Generates the navagation bar.
87 -->
88 <xsl:template match="checkstyle" mode="navigation">
89 <ul id="navigation">
90 <xsl:for-each select="file/error[generate-id() = generate-id(key('module',@source))]">
91 <xsl:sort select="@source"/>
92 <xsl:variable name="last-index">
93 <xsl:call-template name="last-index-of">
94 <xsl:with-param name="txt" select="@source"/>
95 <xsl:with-param name="delimiter" select="'.'"></xsl:with-param>
96 </xsl:call-template>
97 </xsl:variable>
98 <li><a href="javascript:change('{@source}');">
99 <xsl:value-of select="substring(@source, $last-index+1)"/>
100 </a></li>
101 </xsl:for-each>
102 </ul>
103 </xsl:template>
104
105
106
107 <!--
108 Generates the data part.
109 -->
110 <xsl:template match="checkstyle" mode="data">
111 <div id="content">
112 <xsl:for-each select="file/error[generate-id() = generate-id(key('module',@source))]">
113 <xsl:sort select="@source"/>
114 <div class="hideable" id="{@source}">
115 <xsl:variable name="module" select="@source"/>
116 <h2><xsl:value-of select="@source"/></h2>
117 <xsl:call-template name="data">
118 <xsl:with-param name="filter" select="$module"/>
119 </xsl:call-template>
120 </div>
121 </xsl:for-each>
122 </div>
123 </xsl:template>
124
125
126
127 <!--
128 Generates the content table for the given check module.
129 @param filter full qualified module name
130 -->
131 <xsl:template name="data">
132 <xsl:param name="filter"/>
133
134 <table>
135 <tr>
136 <th>file</th>
137 <th>line</th>
138 <th>severity</th>
139 <th>message</th>
140 </tr>
141 <xsl:for-each select="/checkstyle/file">
142 <xsl:choose>
143 <xsl:when test="error/@source=$filter">
144 <xsl:call-template name="data-rows">
145 <xsl:with-param name="node" select="."/>
146 <xsl:with-param name="filter" select="$filter"/>
147 </xsl:call-template>
148 </xsl:when>
149 </xsl:choose>
150 </xsl:for-each>
151 </table>
152 </xsl:template>
153
154
155
156 <!--
157 Generates the data rows for the current check module.
158 Ignores errors in the current file from other modules.
159 @param node the file with the errors
160 @param filter full qualified module name
161 -->
162 <xsl:template name="data-rows">
163 <xsl:param name="node"/>
164 <xsl:param name="filter"/>
165
166 <xsl:for-each select="$node/error">
167 <xsl:choose>
168 <xsl:when test="@source=$filter">
169 <tr>
170 <!-- Hide the basdir. First char of the result is a path separator so remove that. -->
171 <td><xsl:value-of select="substring(substring-after($node/@name, $basedir),2)"/></td>
172 <td><xsl:value-of select="@line"/></td>
173 <td><xsl:value-of select="@severity"/></td>
174 <td><xsl:value-of select="@message"/></td>
175 </tr>
176 </xsl:when>
177 </xsl:choose>
178 </xsl:for-each>
179 </xsl:template>
180
181
182
183 <!--
184 Generates the CSS with the layout instructions.
185 Generated so this XSL is the single source of the whole report.
186 -->
187 <xsl:template name="sorted.css">
188 body {
189 font:normal 80% arial,helvetica,sanserif;
190 color: black;
191 background-color: white;
192 margin: 0;
193 padding: 1em;
194 min-width: 41em;
195 }
196 h1 {
197 font-weight:bold;
198 font-size:140%;
199 margin: 0 0 0.7em;
200 padding: 0.3em;
201 text-align: center;
202 background-color: #eee;
203 border: 2px ridge silver;
204 }
205 html<xsl:text disable-output-escaping="yes">&gt;</xsl:text>body h1 {
206 border-color: gray;
207 }
208
209 ul#navigation {
210 font-size: 0.83em;
211 float: left; width: 18em;
212 margin: 0 0 1.2em; padding: 0;
213 border: 1px dashed silver;
214 }
215 ul#navigation li {
216 list-style: none;
217 margin: 0; padding: 0.2em;
218 }
219 ul#navigation a {
220 display: block;
221 padding: 0.2em;
222 font-weight: bold;
223 }
224 ul#navigation a:link {
225 color: black; background-color: #eee;
226 }
227 ul#navigation a:visited {
228 color: #666; background-color: #eee;
229 }
230 ul#navigation a:hover {
231 color: red; background-color: white;
232 }
233 ul#navigation a:active {
234 color: white; background-color: gray;
235 }
236
237 div#content {
238 margin: 0 1em 1em 16em;
239 padding: 0 1em;
240 }
241 * html div#content {
242 height: 1em; /* Workaround 3-Pixel-Bug of Internet Explorers */
243 }
244 div#content h2 {
245 font-size:100%;
246 font-weight:bold;
247 background: #525D76;
248 color: white;
249 text-decoration: none;
250 padding: 5px;
251 margin-right: 2px;
252 margin-left: 2px;
253 margin-bottom: 0;
254 }
255 div#content p {
256 font-size: 1em;
257 margin: 1em 0;
258 }
259 table {
260 width:100%;
261 border-collapse:collapse;
262 }
263 table td, table th {
264 border:1px solid #000;
265 padding:3px 7px 2px 7px;
266 }
267 table th {
268 font-weight:bold;
269 background: #ccc;
270 color: black;
271 }
272 table tr:nth-child(odd) td {
273 background: #efefef;
274 }
275 table tr:nth-child(even) td {
276 background: #fff;
277 }
278 </xsl:template>
279
280
281
282 <!--
283 Generates the JavaScript for the dynamic style.
284 Generated so this XSL is the single source of the whole report.
285 -->
286 <xsl:template name="switch.js">
287 /*
288 * Hides all "hideable" div-containers
289 */
290 function hideAll() {
291 allElements = document.getElementsByTagName("div");
292 for (i = 0; i <xsl:text disable-output-escaping="yes">&lt;</xsl:text> allElements.length; i++) {
293 if (allElements[i].className=="hideable") {
294 allElements[i].style.display="none";
295 }
296 }
297 return;
298 }
299
300 /*
301 * Shows one div-container and hides the other.
302 * @param id id of the element to show
303 */
304 function change(id) {
305 hideAll();
306 e = document.getElementById(id);
307 if (e.style.display=="none") {
308 e.style.display="";
309 }
310 window.scrollTo(0, 0);
311 return;
312 }
313
314 /*
315 * Shows only the first data row.
316 * Used in body:onload so the user could directly see some messages.
317 */
318 function openFirst() {
319 hideAll();
320 for (i = 0; i <xsl:text disable-output-escaping="yes">&lt;</xsl:text> allElements.length; i++) {
321 if (allElements[i].className=="hideable") {
322 allElements[i].style.display="";
323 return;
324 }
325 }
326 return;
327 }
328 </xsl:template>
329
330
331
332 <!--
333 Calculates the index of the last occurence of a substring in a string.
334 @param txt the whole string in which to search
335 @delimiter the substring to search
336 -->
337 <xsl:template name="last-index-of">
338 <xsl:param name="txt"/>
339 <xsl:param name="remainder" select="$txt"/>
340 <xsl:param name="delimiter" select="' '"/>
341
342 <xsl:choose>
343 <xsl:when test="contains($remainder, $delimiter)">
344 <xsl:call-template name="last-index-of">
345 <xsl:with-param name="txt" select="$txt"/>
346 <xsl:with-param name="remainder" select="substring-after($remainder, $delimiter)"/>
347 <xsl:with-param name="delimiter" select="$delimiter"/>
348 </xsl:call-template>
349 </xsl:when>
350 <xsl:otherwise>
351 <xsl:variable name="lastIndex" select="string-length(substring($txt, 1, string-length($txt)-string-length($remainder)))+1"/>
352 <xsl:choose>
353 <xsl:when test="string-length($remainder)=0">
354 <xsl:value-of select="string-length($txt)"/>
355 </xsl:when>
356 <xsl:when test="$lastIndex>0">
357 <xsl:value-of select="($lastIndex - string-length($delimiter))"/>
358 </xsl:when>
359 <xsl:otherwise>
360 <xsl:value-of select="0"/>
361 </xsl:otherwise>
362 </xsl:choose>
363 </xsl:otherwise>
364 </xsl:choose>
365 </xsl:template>
366
367</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.