use of org.mifos.framework.exceptions.MenuParseException in project head by mifos.
the class MenuParser method parse.
/**
* Method to parse xml and return crude menu
*
* @return array of crude Menu objects
*/
public static Menu[] parse() throws SystemException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
SchemaFactory schfactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schfactory.setErrorHandler(null);
Schema schema = schfactory.newSchema(new StreamSource(MifosResourceUtil.getClassPathResourceAsStream(FilePaths.MENUSCHEMA)));
factory.setNamespaceAware(false);
factory.setValidating(false);
factory.setSchema(schema);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream(FilePaths.MENUPATH));
NodeList tabNodeList = document.getElementsByTagName(MenuConstants.TOPMENUTAB);
Menu[] leftMenus = new Menu[tabNodeList.getLength()];
for (int i = 0; i < tabNodeList.getLength(); i++) {
leftMenus[i] = new Menu();
leftMenus[i].setTopMenuTabName(((Element) tabNodeList.item(i)).getAttribute(MenuConstants.NAME));
leftMenus[i].setMenuGroups(createMenuGroup(tabNodeList.item(i)));
String menuHeading = ((Element) tabNodeList.item(i)).getElementsByTagName(MenuConstants.LEFTMENULABEL).item(0).getFirstChild().getTextContent().trim();
leftMenus[i].setMenuHeading(menuHeading);
}
return leftMenus;
} catch (SAXParseException spe) {
throw new MenuParseException(spe);
} catch (SAXException sxe) {
throw new MenuParseException(sxe);
} catch (ParserConfigurationException pce) {
throw new MenuParseException(pce);
} catch (IOException ioe) {
throw new MenuParseException(ioe);
}
}
Aggregations