1 package net.jaekl.cfb.analyze;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7 import java.util.Locale;
9 import net.jaekl.cfb.xml.messages.MessageCollection;
10 import net.jaekl.qd.xml.ParseErrorHandler;
11 import net.jaekl.qd.xml.ParseHandler;
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;
18 public class MessageMap {
19 static final String MESSAGES = "messages";
20 static final String XML = "xml";
22 MessageCollection m_msgColl;
30 public MessageCollection getColl() { return m_msgColl; }
31 public File getFindBugsDir() { return m_findBugsDir; }
33 public void load(File findBugsDir, Locale locale) throws FileNotFoundException, IOException, SAXException
35 m_findBugsDir = findBugsDir;
37 String langName = locale.getLanguage();
39 File msgXml = new File(findBugsDir.getAbsolutePath() + File.separator + MESSAGES + "_" + langName + "." + XML);
40 if (! msgXml.canRead()) {
41 msgXml = new File(findBugsDir.getAbsolutePath() + File.separator + MESSAGES + "." + XML);
44 if (! msgXml.canRead()) {
45 throw new FileNotFoundException(msgXml.getAbsolutePath());
48 parse(new InputSource(new FileInputStream(msgXml)));
52 void parse(InputSource xml) throws FileNotFoundException, IOException, SAXException
54 m_msgColl = new MessageCollection();
56 XMLReader reader = XMLReaderFactory.createXMLReader();
57 ParseHandler ph = new ParseHandler(m_msgColl);
58 ParseErrorHandler peh = new ParseErrorHandler();
59 reader.setContentHandler(ph);
60 reader.setErrorHandler(peh);