KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > clirr > core > XmlDiffListener


1 //////////////////////////////////////////////////////////////////////////////
2
// Clirr: compares two versions of a java library for binary compatibility
3
// Copyright (C) 2003 - 2005 Lars Kühne
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation; either
8
// version 2.1 of the License, or (at your option) any later version.
9
//
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 JavaDoc;
23 import java.io.PrintStream JavaDoc;
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 {
34     private static final String JavaDoc DIFFREPORT = "diffreport";
35     private static final String JavaDoc DIFFERENCE = "difference";
36
37     private MessageTranslator translator = new MessageTranslator();
38
39     public XmlDiffListener(String JavaDoc outFile) throws IOException JavaDoc
40     {
41         super(outFile);
42     }
43
44     public void reportDiff(ApiDifference difference)
45     {
46         PrintStream JavaDoc out = getOutputStream();
47         out.print(" <" + DIFFERENCE);
48         out.print(" binseverity=\"" + difference.getBinaryCompatibilitySeverity() + "\"");
49         out.print(" srcseverity=\"" + difference.getSourceCompatibilitySeverity() + "\"");
50         out.print(" class=\"" + difference.getAffectedClass() + "\"");
51         if (difference.getAffectedMethod() != null)
52         {
53             out.print(" method=\"" + difference.getAffectedMethod() + "\"");
54         }
55         if (difference.getAffectedField() != null)
56         {
57             out.print(" field=\"" + difference.getAffectedField() + "\"");
58         }
59         out.print(">");
60         out.print(difference.getReport(translator)); // TODO: XML escapes??
61
out.println("</" + DIFFERENCE + '>');
62     }
63
64     /**
65      * Writes an XML header and toplevel tag to the xml stream.
66      *
67      * @see DiffListener#start()
68      */

69     public void start()
70     {
71         PrintStream JavaDoc out = getOutputStream();
72         out.println("<?xml version=\"1.0\"?>");
73         out.println('<' + DIFFREPORT + '>');
74     }
75
76
77     /**
78      * Closes the toplevel tag that was opened in start.
79      *
80      * @see DiffListener#stop()
81      */

82     protected void writeFooter()
83     {
84         PrintStream JavaDoc out = getOutputStream();
85         out.println("</" + DIFFREPORT + '>');
86     }
87 }
88
Popular Tags