01: //////////////////////////////////////////////////////////////////////////////
02: // Clirr: compares two versions of a java library for binary compatibility
03: // Copyright (C) 2003 - 2005 Lars Kühne
04: //
05: // This library is free software; you can redistribute it and/or
06: // modify it under the terms of the GNU Lesser General Public
07: // License as published by the Free Software Foundation; either
08: // version 2.1 of the License, or (at your option) any later version.
09: //
10: // This library is distributed in the hope that it will be useful,
11: // but WITHOUT ANY WARRANTY; without even the implied warranty of
12: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: // Lesser General Public License for more details.
14: //
15: // You should have received a copy of the GNU Lesser General Public
16: // License along with this library; if not, write to the Free Software
17: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: //////////////////////////////////////////////////////////////////////////////
19:
20: package net.sf.clirr.core;
21:
22: import java.io.IOException;
23: import java.io.PrintStream;
24:
25: /**
26: * A DiffListener that reports any detected difference to
27: * an XML file. That file can be used by subsequent processing steps
28: * to create nice looking reports in HTML, PDF, etc.
29: *
30: * @author lkuehne
31: */
32: public final class XmlDiffListener extends FileDiffListener {
33: private static final String DIFFREPORT = "diffreport";
34: private static final String DIFFERENCE = "difference";
35:
36: private MessageTranslator translator = new MessageTranslator();
37:
38: public XmlDiffListener(String outFile) throws IOException {
39: super (outFile);
40: }
41:
42: public void reportDiff(ApiDifference difference) {
43: PrintStream out = getOutputStream();
44: out.print(" <" + DIFFERENCE);
45: out.print(" binseverity=\""
46: + difference.getBinaryCompatibilitySeverity() + "\"");
47: out.print(" srcseverity=\""
48: + difference.getSourceCompatibilitySeverity() + "\"");
49: out.print(" class=\"" + difference.getAffectedClass() + "\"");
50: if (difference.getAffectedMethod() != null) {
51: out.print(" method=\"" + difference.getAffectedMethod()
52: + "\"");
53: }
54: if (difference.getAffectedField() != null) {
55: out.print(" field=\"" + difference.getAffectedField()
56: + "\"");
57: }
58: out.print(">");
59: out.print(difference.getReport(translator)); // TODO: XML escapes??
60: out.println("</" + DIFFERENCE + '>');
61: }
62:
63: /**
64: * Writes an XML header and toplevel tag to the xml stream.
65: *
66: * @see DiffListener#start()
67: */
68: public void start() {
69: PrintStream out = getOutputStream();
70: out.println("<?xml version=\"1.0\"?>");
71: out.println('<' + DIFFREPORT + '>');
72: }
73:
74: /**
75: * Closes the toplevel tag that was opened in start.
76: *
77: * @see DiffListener#stop()
78: */
79: protected void writeFooter() {
80: PrintStream out = getOutputStream();
81: out.println("</" + DIFFREPORT + '>');
82: }
83: }
|