Unit testing: confirm that Analyzer can parse some sample XML
[cfb.git] / prod / net / jaekl / cfb / analyze / Analysis.java
index e8a938aa33c33ea710f7149da80c1078fd897d47..ab9fffbe798e90b8d23d52a3347008ec931316e3 100644 (file)
@@ -1,5 +1,45 @@
 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 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;
+       
+       public Analysis() {
+               m_bugCollection = null;
+       }
+       
+       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);
+               }
+       }
 }