DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource inputSource = new InputSource(categoriesFilePath);
Document dom = builder.parse(inputSource);
Categories categories = new Categories();
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList ctgNodes =
(NodeList) xpath.evaluate("category", dom.getFirstChild(),
XPathConstants.NODESET);
for (int i = 0; i < ctgNodes.getLength(); i++) {
Node ctgNode = ctgNodes.item(i);
String key = (String) xpath.evaluate("@key", ctgNode,
XPathConstants.STRING);
String value = (String) xpath.evaluate("@value", ctgNode,
XPathConstants.STRING);
categories.put(key, value);
}
context.setCategories(categories);
log.info("Categories initialized.");