You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

checkstyle-frames-sortby-check.xsl 12 kB

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