Improve XML parsing to handle attributes as well.
[cfb.git] / prod / net / jaekl / cfb / analyze / Analysis.java
index e8a938aa33c33ea710f7149da80c1078fd897d47..4e289e2366c4816a679dd0b39019b118b90fb2b7 100644 (file)
@@ -1,5 +1,51 @@
 package net.jaekl.cfb.analyze;
 
-public class Analysis {
+// Copyright (C) 2015 Christian Jaekl
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
 
+import net.jaekl.cfb.xml.BugCollection;
+import net.jaekl.qd.util.InputStreamWrapper;
+import net.jaekl.qd.xml.ParseErrorHandler;
+import net.jaekl.qd.xml.ParseHandler;
+
+public class Analysis {
+       BugCollection m_bugCollection;
+       
+       public Analysis() {
+               m_bugCollection = null;
+       }
+       
+       public BugCollection getBugCollection() { return m_bugCollection; }
+       
+       public void parse(File xml) throws FileNotFoundException, IOException, SAXException 
+       {
+               m_bugCollection = new BugCollection();
+               
+               try (InputStreamWrapper isw = new InputStreamWrapper(new FileInputStream(xml))) 
+               {
+                   XMLReader reader = XMLReaderFactory.createXMLReader();
+                   ParseHandler ph = new ParseHandler(m_bugCollection);
+                   ParseErrorHandler peh = new ParseErrorHandler();
+                   reader.setContentHandler(ph);
+                   reader.setErrorHandler(peh);
+                   reader.parse(new InputSource(isw));
+               }
+       }
+       
+       public void dump(PrintWriter pw)
+       {
+               if (null != m_bugCollection) {
+                       m_bugCollection.dump(pw, 2);
+               }
+       }
 }