Clover coverage report - PMD - 3.9 Coverage timestamp: Tue Dec 19 2006 09:38:44 EST FRAMES NO FRAMES |
file stats: | LOC: | 49 |  | Methods: | 1
| NCLOC: | 38 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
XMLRenderer.java | 83.3% | 100% | 100% | 97.1% |

1 |  | /**
2 |  | * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 |  | */
4 |  | package net.sourceforge.pmd.cpd;
5 |  |
6 |  | import net.sourceforge.pmd.PMD;
7 |  | import net.sourceforge.pmd.util.StringUtil;
8 |  |
9 |  | import java.util.Iterator;
10 |  |
11 |  | /**
12 |  | * @author Philippe T'Seyen
13 |  | */
14 |  | public class XMLRenderer implements Renderer {
15 |  |
16 | 3 | public String render(Iterator matches) {
17 | 3 | StringBuffer buffer = new StringBuffer(300);
18 | 3 | buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
19 | 3 | buffer.append("<pmd-cpd>").append(PMD.EOL);
20 | 3 | Match match;
21 | 3 | while (matches.hasNext()) {
22 | 3 | match = (Match) matches.next();
23 | 3 | buffer.append("<duplication lines=\"");
24 | 3 | buffer.append(match.getLineCount());
25 | 3 | buffer.append("\" tokens=\"");
26 | 3 | buffer.append(match.getTokenCount());
27 | 3 | buffer.append("\">").append(PMD.EOL);
28 |  |
29 | 3 | TokenEntry mark;
30 | 3 | for (Iterator iterator = match.iterator(); iterator.hasNext();) {
31 | 6 | mark = (TokenEntry) iterator.next();
32 | 6 | buffer.append("<file line=\"");
33 | 6 | buffer.append(mark.getBeginLine());
34 | 6 | buffer.append("\" path=\"");
35 | 6 | buffer.append(mark.getTokenSrcID());
36 | 6 | buffer.append("\"/>").append(PMD.EOL);
37 |  | }
38 | 3 | String codeFragment = match.getSourceCodeSlice();
39 | 3 | if (codeFragment != null) {
40 | 3 | buffer.append("<codefragment>").append(PMD.EOL);
41 | 3 | buffer.append("<![CDATA[").append(PMD.EOL);
42 | 3 | buffer.append(StringUtil.replaceString(codeFragment, "]]>", "]]&gt;")).append(PMD.EOL + "]]>" + PMD.EOL + "</codefragment>" + PMD.EOL);
43 |  | }
44 | 3 | buffer.append("</duplication>").append(PMD.EOL);
45 |  | }
46 | 3 | buffer.append("</pmd-cpd>");
47 | 3 | return buffer.toString();
48 |  | }
49 |  | }