1 19 20 package edu.umd.cs.findbugs; 21 22 import java.io.BufferedInputStream ; 23 import java.io.FileInputStream ; 24 import java.io.FileNotFoundException ; 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 28 import javax.xml.transform.Transformer ; 29 import javax.xml.transform.TransformerFactory ; 30 import javax.xml.transform.stream.StreamResult ; 31 import javax.xml.transform.stream.StreamSource ; 32 33 import org.dom4j.Document; 34 import org.dom4j.io.DocumentSource; 35 36 public class HTMLBugReporter extends BugCollectionBugReporter { 37 private String stylesheet; 38 39 public HTMLBugReporter(Project project, String stylesheet) { 40 super(project); 41 this.stylesheet = stylesheet; 42 } 43 44 public void finish() { 45 try { 46 BugCollection bugCollection = getBugCollection(); 47 bugCollection.setWithMessages(true); 48 Document document = bugCollection.toDocument(getProject()); 50 52 InputStream xslInputStream; 56 if (FindBugs.DEBUG) System.out.println("Attempting to load stylesheet " + stylesheet); 57 try { 58 xslInputStream = new BufferedInputStream (new FileInputStream (stylesheet)); 59 } catch (FileNotFoundException fnfe) { 60 xslInputStream = this.getClass().getClassLoader().getResourceAsStream(stylesheet); 61 if (xslInputStream == null) 62 throw new IOException ("Could not load HTML generation stylesheet " + stylesheet); 63 } 64 StreamSource xsl = new StreamSource (xslInputStream); 65 xsl.setSystemId(stylesheet); 66 67 TransformerFactory factory = TransformerFactory.newInstance(); 69 Transformer transformer = factory.newTransformer(xsl); 70 71 DocumentSource source = new DocumentSource(document); 73 74 StreamResult result = new StreamResult (outputStream); 76 77 transformer.transform(source, result); 79 } catch (Exception e) { 80 logError("Could not generate HTML output", e); 81 if (FindBugs.DEBUG) e.printStackTrace(); 82 } 83 } 84 } 85 86 | Popular Tags |