Search in sources :

Example 31 with Element

use of org.w3c.dom.Element in project head by mifos.

the class TableTagParser method createActionParams.

protected ActionParam[] createActionParams(Node linkDetail) throws TableTagParseException {
    NodeList actionParamNodeList = ((Element) linkDetail).getElementsByTagName(TableTagConstants.ACTIONPARAM);
    if (actionParamNodeList.getLength() == 0) {
        throw new TableTagParseException(actionParamNodeList.toString());
    }
    ActionParam[] actionParam = new ActionParam[actionParamNodeList.getLength()];
    for (int i = 0; i < actionParamNodeList.getLength(); i++) {
        actionParam[i] = new ActionParam();
        actionParam[i].setName(actionParamNodeList.item(i).getAttributes().getNamedItem(TableTagConstants.NAME).getNodeValue());
        actionParam[i].setValueType(actionParamNodeList.item(i).getAttributes().getNamedItem(TableTagConstants.VALUETYPE).getNodeValue());
        if (!actionParam[i].getValueType().equalsIgnoreCase(TableTagConstants.INBUILD)) {
            actionParam[i].setValue(actionParamNodeList.item(i).getAttributes().getNamedItem(TableTagConstants.VALUE).getNodeValue());
        }
    }
    return actionParam;
}
Also used : TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 32 with Element

use of org.w3c.dom.Element in project head by mifos.

the class TableTagParser method createColumn.

protected Column[] createColumn(Node row) throws TableTagParseException {
    NodeList columnNodeList = ((Element) row).getElementsByTagName(TableTagConstants.COLUMN);
    if (columnNodeList.getLength() == 0) {
        throw new TableTagParseException(columnNodeList.toString());
    }
    Column[] column = new Column[columnNodeList.getLength()];
    for (int i = 0; i < columnNodeList.getLength(); i++) {
        column[i] = new Column();
        setColumnAttributes(column[i], columnNodeList.item(i).getAttributes());
        column[i].setColumnDetials(createColumnDetails(columnNodeList.item(i)));
        if (TableTagConstants.LINK.equalsIgnoreCase(column[i].getColumnType())) {
            column[i].setLinkDetails(createLinkDetails(columnNodeList.item(i)));
        }
    }
    return column;
}
Also used : TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 33 with Element

use of org.w3c.dom.Element in project head by mifos.

the class TableTagParser method createLinkDetails.

protected LinkDetails createLinkDetails(Node column) throws TableTagParseException {
    NodeList linkDetailsNodeList = ((Element) column).getElementsByTagName(TableTagConstants.LINKDETAILS);
    if (linkDetailsNodeList.getLength() == 0) {
        throw new TableTagParseException(linkDetailsNodeList.toString());
    }
    LinkDetails linkDetails = new LinkDetails();
    if (linkDetailsNodeList.item(0).getAttributes().getNamedItem(TableTagConstants.ACTION).getNodeValue() == null) {
        throw new TableTagParseException(linkDetailsNodeList.toString());
    }
    linkDetails.setAction(linkDetailsNodeList.item(0).getAttributes().getNamedItem(TableTagConstants.ACTION).getNodeValue());
    linkDetails.setActionParam(createActionParams(linkDetailsNodeList.item(0)));
    return linkDetails;
}
Also used : TableTagParseException(org.mifos.framework.exceptions.TableTagParseException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 34 with Element

use of org.w3c.dom.Element in project head by mifos.

the class MenuParser method createMenuItems.

/**
     * Method to build crude MenuItem objects for a MenuGroup
     *
     * @param menuGroup
     *            is the root node for MenuGroup.
     * @return array of MenuItem objects
     */
static MenuItem[] createMenuItems(Node menuGroup) throws SystemException {
    NodeList menuItemNodeList = ((Element) menuGroup).getElementsByTagName(MenuConstants.MENUITEM);
    MenuItem[] menuItem = new MenuItem[menuItemNodeList.getLength()];
    int hiddenItems = 0;
    for (int i = 0, j = 0; i < menuItemNodeList.getLength(); i++) {
        if (isMenuItemVisible((Element) menuItemNodeList.item(i))) {
            menuItem[j] = new MenuItem();
            menuItem[j].setDisplayName(getDisplayName((Element) menuItemNodeList.item(i)));
            menuItem[j].setLinkValue(getLinkValue((Element) menuItemNodeList.item(i)));
            j++;
        } else {
            hiddenItems++;
        }
    }
    if (hiddenItems > 0) {
        menuItem = removeEmptyMenuItems(menuItem, hiddenItems);
    }
    return menuItem;
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 35 with Element

use of org.w3c.dom.Element in project head by mifos.

the class StateXMLParser method loadMapFromXml.

public Map<StateEntity, List<StateEntity>> loadMapFromXml(String filename, String configurationName) {
    Map<StateEntity, List<StateEntity>> transitionMap = new HashMap<StateEntity, List<StateEntity>>();
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(true);
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
        // Specify our own schema - this overrides the schemaLocation in the
        // xml file
        factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "StateMachine.xsd");
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setErrorHandler(null);
        Document document = builder.parse(MifosResourceUtil.getClassPathResourceAsStream(filename));
        Node mapToprocess = null;
        /*
             * String configurationName = ""; if
             * (stateConfiguration=="configuration1") configurationName = "1";
             * else configurationName = "2";
             */
        NodeList configMaps = document.getElementsByTagName("stateConfiguration");
        for (int m = 0; m < configMaps.getLength(); m++) {
            Node stateConfiguration = configMaps.item(m);
            if (configurationName.equals(stateConfiguration.getAttributes().getNamedItem("configurationName").getNodeValue())) {
                mapToprocess = stateConfiguration;
            }
        }
        // NodeList stateList = firstChild.getChildNodes();
        NodeList stateList = mapToprocess.getChildNodes();
        for (int i = 0; i < stateList.getLength(); i++) {
            // each state has state id and possiblestates as childern
            Node state = stateList.item(i);
            // iterate for each child of state
            NodeList stateInfoList = state.getChildNodes();
            StateEntity currentState = null;
            List<StateEntity> currntPossibleStates = new ArrayList<StateEntity>();
            for (int j = 0; j < stateInfoList.getLength(); j++) {
                Node info = stateInfoList.item(j);
                if ("stateid".equals(info.getLocalName())) {
                    Element ele = (Element) info;
                    currentState = new StateEntity(Short.valueOf(((Text) ele.getFirstChild()).getData()));
                }
                if ("possiblestates".equals(info.getLocalName())) {
                    // get all the childern
                    NodeList allStates = info.getChildNodes();
                    currntPossibleStates = new ArrayList<StateEntity>();
                    for (int k = 0; k < allStates.getLength(); k++) {
                        Node infoState = allStates.item(k);
                        NodeList eachPossiblechild = infoState.getChildNodes();
                        for (int l = 0; l < eachPossiblechild.getLength(); l++) {
                            Node eachPossiblechildelement = eachPossiblechild.item(l);
                            if ("stateid".equals(eachPossiblechildelement.getLocalName())) {
                                Element element = (Element) eachPossiblechildelement;
                                Short possibleTrantionId = Short.valueOf(((Text) element.getFirstChild()).getData());
                                currntPossibleStates.add(new StateEntity(possibleTrantionId));
                            }
                        }
                    }
                }
            }
            if (currentState != null) {
                transitionMap.put(currentState, currntPossibleStates);
            }
        }
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (SAXParseException e) {
        throw new RuntimeException(e);
    } catch (SAXException e) {
        throw new RuntimeException(e);
    }
    return transitionMap;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HashMap(java.util.HashMap) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) StateEntity(org.mifos.application.master.business.StateEntity) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

Element (org.w3c.dom.Element)9072 Document (org.w3c.dom.Document)2651 NodeList (org.w3c.dom.NodeList)2103 Node (org.w3c.dom.Node)1855 ArrayList (java.util.ArrayList)957 DocumentBuilder (javax.xml.parsers.DocumentBuilder)793 IOException (java.io.IOException)732 Test (org.junit.Test)693 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)591 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)489 HashMap (java.util.HashMap)434 SAXException (org.xml.sax.SAXException)406 File (java.io.File)358 Attr (org.w3c.dom.Attr)333 InputStream (java.io.InputStream)309 QName (javax.xml.namespace.QName)292 Map (java.util.Map)285 JAXBElement (javax.xml.bind.JAXBElement)285 NamedNodeMap (org.w3c.dom.NamedNodeMap)266 List (java.util.List)264