1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
public static Hashtable readXMLConfFile(String fileName, UI ui) {
final Hashtable hUICC = new Hashtable();
final UI ui1 = ui;
try {
// create a SAX parser factory
SAXParserFactory factory = SAXParserFactory.newInstance();
// create SAX parser
SAXParser parser = factory.newSAXParser();
// XML file reading with a DefaultHandler
// File file = new File(fileName);
InputStream is = ui.getClass().getResourceAsStream(fileName);
DefaultHandler handler = new DefaultHandler() {
public void startDocument() throws SAXException {
ui1.insertText("Configuration file opened, start parsing...", "info");
}
public void endDocument() throws SAXException {
ui1.insertText("End of configuration : " + hUICC.size()
+ " efs set. File closed", "info");
}
public void startElement(String uri, String localName,
String qName, Attributes attributes)
throws SAXException {
if (qName.equalsIgnoreCase("ef")) {
String efName, efId;
if (attributes != null && attributes.getLength() == 2) {
efName = attributes.getValue("name").toLowerCase();
efId = attributes.getValue("id").toLowerCase();
EF currentEF = new EF(efName, efId);
hUICC.put(efId, currentEF);
}
}
}
public void endElement(String uri, String localName,
String qName) throws SAXException {
}
public void characters(char[] ch, int start, int length)
throws SAXException {
}
};
parser.parse(is, handler);
is.close();
//parser.parse(file, handler);
} catch (ParserConfigurationException pce) {
ui1
.insertText(
"Error : parser configuration",
"error");
} catch (SAXException se) {
ui1.insertText("Parsing error", "error");
} catch (IOException ioe) {
JOptionPane
.showMessageDialog(
null,
"Configuration file (conf.xml) has not been found. \nSorry for the convenience.\nPlease get the file and restart the application.",
"Error", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
return hUICC;
} |
Partager