Unit testing: confirm that Analyzer can parse some sample XML
[cfb.git] / prod / net / jaekl / cfb / analyze / Analysis.java
1 package net.jaekl.cfb.analyze;
2
3 // Copyright (C) 2015 Christian Jaekl
4
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7 import java.io.PrintWriter;
8
9 import net.jaekl.cfb.xml.BugCollection;
10 import net.jaekl.qd.xml.ParseErrorHandler;
11 import net.jaekl.qd.xml.ParseHandler;
12
13 import org.xml.sax.InputSource;
14 import org.xml.sax.SAXException;
15 import org.xml.sax.XMLReader;
16 import org.xml.sax.helpers.XMLReaderFactory;
17
18 public class Analysis {
19         BugCollection m_bugCollection;
20         
21         public Analysis() {
22                 m_bugCollection = null;
23         }
24         
25         public BugCollection getBugCollection() { return m_bugCollection; }
26         
27         public void parse(InputSource xml) throws FileNotFoundException, IOException, SAXException 
28         {
29                 m_bugCollection = new BugCollection();
30                 
31             XMLReader reader = XMLReaderFactory.createXMLReader();
32             ParseHandler ph = new ParseHandler(m_bugCollection);
33             ParseErrorHandler peh = new ParseErrorHandler();
34             reader.setContentHandler(ph);
35             reader.setErrorHandler(peh);
36             reader.parse(xml);
37         }
38         
39         public void dump(PrintWriter pw)
40         {
41                 if (null != m_bugCollection) {
42                         m_bugCollection.dump(pw, 2);
43                 }
44         }
45 }