Add code to load bug categories and patterns from the FindBugs messages.xml file.
[cfb.git] / prod / net / jaekl / cfb / analyze / Analysis.java
index e8a938aa33c33ea710f7149da80c1078fd897d47..e2f090f32b0245c701532c27606d2c7b01c0d979 100644 (file)
@@ -1,5 +1,50 @@
 package net.jaekl.cfb.analyze;
 
-public class Analysis {
+// Copyright (C) 2015 Christian Jaekl
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Date;
+
+import net.jaekl.cfb.xml.BugCollection;
+import net.jaekl.qd.xml.ParseErrorHandler;
+import net.jaekl.qd.xml.ParseHandler;
 
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+public class Analysis {
+       BugCollection m_bugCollection;
+       String m_buildNumber;
+       Date m_date;    // Date/time when analysis was started
+       
+       public Analysis(String buildNumber) {
+               m_bugCollection = null;
+               m_buildNumber = buildNumber;
+               m_date = new Date();
+       }
+       
+       public BugCollection getBugCollection() { return m_bugCollection; }
+       
+       public void parse(InputSource xml) throws FileNotFoundException, IOException, SAXException 
+       {
+               m_bugCollection = new BugCollection();
+               
+           XMLReader reader = XMLReaderFactory.createXMLReader();
+           ParseHandler ph = new ParseHandler(m_bugCollection);
+           ParseErrorHandler peh = new ParseErrorHandler();
+           reader.setContentHandler(ph);
+           reader.setErrorHandler(peh);
+           reader.parse(xml);
+       }
+       
+       public void dump(PrintWriter pw)
+       {
+               if (null != m_bugCollection) {
+                       m_bugCollection.dump(pw, 2);
+               }
+       }
 }