Document d = null;
try {
d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(fs.open(new Path(qfile)));
} catch (SAXException e) {
throw new ConfigurationException(e.getMessage());
} catch (IOException e) {
throw new ConfigurationException(e.getMessage());
} catch (ParserConfigurationException e) {
throw new ConfigurationException(e.getMessage());
}
Map<String, String> grammarPaths = Maps.newLinkedHashMap();
NodeList queryNodes = d.getElementsByTagName("query");
for (int i = 0; i < queryNodes.getLength(); i++) {
// Get query XML node.
Node node = queryNodes.item(i);
// Get query id.
String qid = XMLTools.getAttributeValueOrThrowException(node, "id",
"Must specify a query id attribute for every query!");
String grammar = XMLTools.getAttributeValue(node, "grammar");
// Add query to internal map.
if (grammarPaths.get(qid) != null) {
throw new ConfigurationException(
"Duplicate query ids not allowed! Already parsed query with id=" + qid);
}
grammarPaths.put(qid, grammar);
}