Search in sources :

Example 1 with MenuParseException

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);
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Schema(javax.xml.validation.Schema) StreamSource(javax.xml.transform.stream.StreamSource) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) MenuParseException(org.mifos.framework.exceptions.MenuParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

IOException (java.io.IOException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Schema (javax.xml.validation.Schema)1 SchemaFactory (javax.xml.validation.SchemaFactory)1 MenuParseException (org.mifos.framework.exceptions.MenuParseException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1