4e289e2366c4816a679dd0b39019b118b90fb2b7
[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.File;
6 import java.io.FileInputStream;
7 import java.io.FileNotFoundException;
8 import java.io.IOException;
9 import java.io.PrintWriter;
10
11 import org.xml.sax.InputSource;
12 import org.xml.sax.SAXException;
13 import org.xml.sax.XMLReader;
14 import org.xml.sax.helpers.XMLReaderFactory;
15
16 import net.jaekl.cfb.xml.BugCollection;
17 import net.jaekl.qd.util.InputStreamWrapper;
18 import net.jaekl.qd.xml.ParseErrorHandler;
19 import net.jaekl.qd.xml.ParseHandler;
20
21 public class Analysis {
22         BugCollection m_bugCollection;
23         
24         public Analysis() {
25                 m_bugCollection = null;
26         }
27         
28         public BugCollection getBugCollection() { return m_bugCollection; }
29         
30         public void parse(File xml) throws FileNotFoundException, IOException, SAXException 
31         {
32                 m_bugCollection = new BugCollection();
33                 
34                 try (InputStreamWrapper isw = new InputStreamWrapper(new FileInputStream(xml))) 
35                 {
36                     XMLReader reader = XMLReaderFactory.createXMLReader();
37                     ParseHandler ph = new ParseHandler(m_bugCollection);
38                     ParseErrorHandler peh = new ParseErrorHandler();
39                     reader.setContentHandler(ph);
40                     reader.setErrorHandler(peh);
41                     reader.parse(new InputSource(isw));
42                 }
43         }
44         
45         public void dump(PrintWriter pw)
46         {
47                 if (null != m_bugCollection) {
48                         m_bugCollection.dump(pw, 2);
49                 }
50         }
51 }