View Javadoc
1 ////////////////////////////////////////////////////////////////////////////// 2 // Clirr: compares two versions of a java library for binary compatibility 3 // Copyright (C) 2003 - 2004 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.event; 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 { 34 private static final String DIFFREPORT = "diffreport"; 35 private static final String DIFFERENCE = "difference"; 36 37 public XmlDiffListener(String outFile) throws IOException 38 { 39 super(outFile); 40 } 41 42 public void reportDiff(ApiDifference difference) 43 { 44 PrintStream out = getOutputStream(); 45 out.print(" <" + DIFFERENCE); 46 out.print(" severity=\"" + difference.getSeverity() + "\""); 47 out.print(" class=\"" + difference.getAffectedClass() + "\">"); 48 if (difference.getAffectedMethod() != null) 49 { 50 out.print(" method=\"" + difference.getAffectedMethod() + "\""); 51 } 52 if (difference.getAffectedField() != null) 53 { 54 out.print(" field=\"" + difference.getAffectedField() + "\""); 55 } 56 out.print(difference.getReport()); // TODO: XML escapes?? 57 out.println("</" + DIFFERENCE + '>'); 58 } 59 60 /*** 61 * Writes an XML header and toplevel tag to the xml stream. 62 * 63 * @see DiffListener#start() 64 */ 65 public void start() 66 { 67 PrintStream out = getOutputStream(); 68 out.println("<?xml version=\"1.0\"?>"); 69 out.println('<' + DIFFREPORT + '>'); 70 } 71 72 73 /*** 74 * Closes the toplevel tag that was opened in start. 75 * 76 * @see DiffListener#stop() 77 */ 78 protected void writeFooter() 79 { 80 PrintStream out = getOutputStream(); 81 out.println("</" + DIFFREPORT + '>'); 82 } 83 }

This page was automatically generated by Maven