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 String basePath = findBugsDir.getAbsolutePath() + File.separator + "etc" + File.separator;
41 File msgXml = new File(basePath + MESSAGES + "_" + langName + "." + XML);
42 if (! msgXml.canRead()) {
43 msgXml = new File(basePath + MESSAGES + "." + XML);
46 if (! msgXml.canRead()) {
47 throw new FileNotFoundException(msgXml.getAbsolutePath());
50 parse(new InputSource(new FileInputStream(msgXml)));
54 void parse(InputSource xml) throws FileNotFoundException, IOException, SAXException
56 m_msgColl = new MessageCollection();
58 XMLReader reader = XMLReaderFactory.createXMLReader();
59 ParseHandler ph = new ParseHandler(m_msgColl);
60 ParseErrorHandler peh = new ParseErrorHandler();
61 reader.setContentHandler(ph);
62 reader.setErrorHandler(peh);