Example usage for org.w3c.dom Document getChildNodes

List of usage examples for org.w3c.dom Document getChildNodes

Introduction

In this page you can find the example usage for org.w3c.dom Document getChildNodes.

Prototype

public NodeList getChildNodes();

Source Link

Document

A NodeList that contains all children of this node.

Usage

From source file:cz.tyr.android.currencyrates.bank.UniCreditBank.java

@Override
public int downloadData() {
    if (mCurrency == null) {
        mCurrency = getDefaultCurrencyValue();
    }/*from ww  w. j  a v  a2 s  . c o  m*/

    String dateStr = null;
    String rateStr = null;

    String url = getDataUrl();

    if (DEBUG > 0) {
        Log.d(TAG, "Download data for UCB_CZ");
        Log.d(TAG, " * url = : " + url);
        Log.d(TAG, " * currency = " + mCurrency);
        Log.d(TAG, " * exchange = " + mExchangeType);
        Log.d(TAG, " * direction = " + mExchangeDirection);
    }

    HttpClient sClient = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);
    InputStream stream = null;

    try {
        stream = sClient.execute(request).getEntity().getContent();
    } catch (IOException e) {
        Log.d(TAG, "Problem downloading the XML data.");
        return 1;
    }

    try {
        if (DEBUG > 1)
            Log.d(TAG, " - Factory start");
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        Document doc = dbf.newDocumentBuilder().parse(stream);
        if (DEBUG > 1)
            Log.d(TAG, " - Factory end");

        if (doc != null && doc.hasChildNodes()) {
            if (DEBUG > 1)
                Log.d(TAG, " - Parse start");

            // find the root element
            for (int i = 0; i < doc.getChildNodes().getLength(); i++) {
                Node root = doc.getChildNodes().item(i);

                if (root.getNodeType() == Node.ELEMENT_NODE || root.getNodeName().equals("exchange_rates")) {
                    NodeList list = doc.getChildNodes().item(i).getChildNodes();

                    // find first node
                    for (int j = 0; j < list.getLength(); j++) {
                        Node n = list.item(j);

                        // check the attributes of this element
                        if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals("exchange_rate")) {
                            boolean go = false;

                            if (DEBUG > 1)
                                Log.d(TAG, " # Got EXCHANGE_RATE element!");

                            for (int k = 0; k < n.getAttributes().getLength(); k++) {
                                Node a = n.getAttributes().item(k);

                                if (a.getNodeName().equals("type") && a.getNodeValue().equals(
                                        "XML_RATE_TYPE_UCB_" + mExchangeDirection + "_" + mExchangeType)) {
                                    if (DEBUG > 1)
                                        Log.d(TAG, " - CORRECT ELEMENT! TAKE THE DATE!");

                                    go = true;
                                } else if (go && a.getNodeName().equals("valid_from")) {
                                    if (DEBUG > 1)
                                        Log.d(TAG, " - GOT DATE! " + a.getNodeValue());

                                    DateFormat formatter = new SimpleDateFormat("HH:mm");
                                    String time = formatter.format(new Date());
                                    formatter = new SimpleDateFormat("dd.MM.yyyy HH:mm");
                                    Date fdate = (Date) formatter.parse(a.getNodeValue() + " " + time);
                                    formatter = new SimpleDateFormat(
                                            mResources.getString(R.string.date_time_format));

                                    dateStr = formatter.format(fdate);

                                    // stop the loop
                                    break;
                                }
                            }

                            // if it is correct element, go for the rate
                            if (go) {
                                if (DEBUG > 1)
                                    Log.d(TAG, " - Searching for the rate!");

                                NodeList currencies = n.getChildNodes();

                                // check the attributes
                                for (int k = 0; k < currencies.getLength(); k++) {
                                    Node c = currencies.item(k);

                                    if (c.getNodeType() == Node.ELEMENT_NODE
                                            && c.getNodeName().equals("currency")) {
                                        boolean bool = false;
                                        String rateTmp = null;

                                        for (int l = 0; l < c.getAttributes().getLength(); l++) {
                                            Node a = c.getAttributes().item(l);

                                            if (a.getNodeName().equals("name")
                                                    && a.getNodeValue().equals(mCurrency)) {
                                                if (DEBUG > 1)
                                                    Log.d(TAG, " -- Got the Currency!!!");

                                                bool = true;
                                            } else if (a.getNodeName().equals("rate")) {
                                                if (DEBUG > 1)
                                                    Log.d(TAG, " -- Got the RATE!!!" + a.getNodeValue());
                                                rateTmp = a.getNodeValue();
                                            }

                                            if (bool && rateTmp != null) {
                                                rateStr = rateTmp;

                                                if (DEBUG > 1)
                                                    Log.d(TAG, " -- Got the Currency VALUE: " + rateStr);

                                                // stop the loop
                                                break;
                                            }
                                        }
                                    }

                                    // stop the loop
                                    if (rateStr != null) {
                                        break;
                                    }
                                }
                            }
                        }

                        // stop the loop
                        if (rateStr != null) {
                            break;
                        }
                    }
                }

                // stop the loop
                if (rateStr != null) {
                    break;
                }
            }

            if (DEBUG > 1)
                Log.d(TAG, " - Parse end");
        }
    } catch (Exception e) {
        e.printStackTrace();
        return 1;
    }

    // Check the values
    if (dateStr == null || rateStr == null) {
        Log.d(TAG, " # One of the values is null!");
        return 1;
    }

    setCurrencyDate(dateStr);
    setCurrencyRate(Float.parseFloat(rateStr));

    return 0;
}

From source file:com.zoho.creator.jframework.XMLParser.java

private static String parseForTokenForExternalField(Document rootDocument) {
    // TODO Auto-generated method stub
    String accessToken = "";
    NodeList nl = rootDocument.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node responseNode = nl.item(i);
        if (responseNode.getNodeName().equals("OAuth")) {
            NodeList responseNodes = responseNode.getChildNodes();
            for (int j = 0; j < responseNodes.getLength(); j++) {
                Node responseChildNode = responseNodes.item(j);
                if (responseChildNode.getNodeName().equals("access_token")) {
                    accessToken = getChildNodeValue(responseChildNode, "access_token");//No I18N
                }//from w w w  .j ava2 s.  co m
            }
        }
    }
    return accessToken;
}

From source file:com.distrimind.madkit.kernel.MadkitProperties.java

@Override
public Node getRootNode(Document _document) {
    for (int i = 0; i < _document.getChildNodes().getLength(); i++) {
        Node n = _document.getChildNodes().item(i);
        if (n.getNodeName().equals(XMLUtilities.MDK))
            return n;
    }/* ww  w.j  a  va2 s  .c  om*/
    return null;
}

From source file:com.esri.gpt.server.csw.provider3.GetRecordsProvider.java

/**
 * Builds an ogc:SortBy node from HTTP GET parameters.
 * @param sortBy the sortBy parameter values
 * @throws Exception if a processing exception occurs
 *///from w  w  w.j a va2  s .c  o m
protected Node buildSortByNode(String[] sortBy) throws Exception {

    // parse sort by parameters
    // pattern: sortby=property1:A,property2:D...

    if (sortBy != null) {
        StringBuilder sbXml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        sbXml.append("\r\n<ogc:SortBy xmlns:ogc=\"http://www.opengis.net/ogc\">");
        boolean hadProperty = false;
        for (String param : sortBy) {
            param = Val.chkStr(param);
            String name = null;
            String dir = null;
            if (param.toLowerCase().endsWith(":a")) {
                name = Val.chkStr(param.substring(0, param.length() - 2));
                dir = "ASC";
            } else if (param.toLowerCase().endsWith(":d")) {
                name = Val.chkStr(param.substring(0, param.length() - 2));
                dir = "DESC";
            } else {
                name = Val.chkStr(param);
            }
            if ((name == null) || (name.length() == 0)) {
                // we'll ignore this condition without an exception
            } else {
                hadProperty = true;
                sbXml.append("\r\n<ogc:SortProperty>");
                sbXml.append("\r\n<ogc:PropertyName>").append(Val.escapeXml(name))
                        .append("</ogc:PropertyName>");
                if (dir != null) {
                    sbXml.append("\r\n<ogc:SortOrder>").append(Val.escapeXml(dir)).append("</ogc:SortOrder>");
                }
                sbXml.append("\r\n</ogc:SortProperty>");
            }
        }
        sbXml.append("\r\n</ogc:SortBy>");
        if (hadProperty) {
            Document dom = DomUtil.makeDomFromString(sbXml.toString(), true);
            NodeList nl = dom.getChildNodes();
            for (int i = 0; i < nl.getLength(); i++) {
                if (nl.item(i).getNodeType() == Node.ELEMENT_NODE) {
                    return nl.item(i);
                }
            }
        }
    }
    return null;
}

From source file:com.zoho.creator.jframework.XMLParser.java

static List<ZCApplication> parseForApplicationList(Document rootDocument) throws ZCException {
    List<ZCApplication> toReturn = new ArrayList<ZCApplication>();
    NodeList nl = rootDocument.getChildNodes();
    String remainingDays = "";
    boolean licenceEnabled = true;
    String appOwner = "";
    for (int i = 0; i < nl.getLength(); i++) {
        Node responseNode = nl.item(i);
        if (responseNode.getNodeName().equals("response")) {
            NodeList responseNodes = responseNode.getChildNodes();

            for (int j = 0; j < responseNodes.getLength(); j++) {
                Node resultNode = responseNodes.item(j);
                if (resultNode.getNodeName().equals("result")) {
                    NodeList resultNodes = resultNode.getChildNodes();
                    for (int k = 0; k < resultNodes.getLength(); k++) {
                        Node resultNodeChild = resultNodes.item(k);
                        if (resultNodeChild.getNodeName().equals("application_owner")) {
                            appOwner = getStringValue(resultNodeChild, ""); //No I18N
                        } else if (resultNodeChild.getNodeName().equals("application_list")) {
                            NodeList appListNodes = resultNodeChild.getChildNodes();
                            for (int l = 0; l < appListNodes.getLength(); l++) {
                                Node applicationsNode = appListNodes.item(l);
                                if (applicationsNode.getNodeName().equals("applications")) {
                                    NodeList applicationsNodes = applicationsNode.getChildNodes();
                                    for (int m = 0; m < applicationsNodes.getLength(); m++) {
                                        Node applicationNode = applicationsNodes.item(m);
                                        if (applicationNode.getNodeName().equals("application")) {
                                            NodeList applicationNodes = applicationNode.getChildNodes();
                                            String appName = null;
                                            String linkName = null;
                                            Date createdTime = null;
                                            boolean isPrivate = true;
                                            for (int n = 0; n < applicationNodes.getLength(); n++) {
                                                Node appPropertyNode = applicationNodes.item(n);
                                                String nodeName = appPropertyNode.getNodeName();
                                                if (nodeName.equals("application_name")) {
                                                    appName = getStringValue(appPropertyNode, appName); //No I18N
                                                } else if (nodeName.equals("link_name")) {
                                                    linkName = getStringValue(appPropertyNode, linkName); //No I18N
                                                } else if (nodeName.equals("access")) {
                                                    isPrivate = getStringValue(appPropertyNode, "private")
                                                            .equals("private"); //No I18N
                                                } else if (nodeName.equals("created_time")) {
                                                    // 2013-04-01 14:28:58.0
                                                    createdTime = getDateValue(appPropertyNode, createdTime,
                                                            "yyyy-MM-dd HH:mm:ss.S"); //No I18N
                                                } else if (nodeName.equals("sharedBy")) {
                                                    appOwner = getStringValue(appPropertyNode, appOwner);
                                                }
                                            }
                                            ZCApplication zcApp = new ZCApplication(appOwner, appName, linkName,
                                                    isPrivate, createdTime);
                                            toReturn.add(zcApp);
                                        }
                                    }//ww  w . j a  va  2 s .com
                                }
                            }
                        } else if (resultNodeChild.getNodeName().equals("license_enabled")) {
                            licenceEnabled = getBooleanValue(resultNodeChild, false);
                        } else if (resultNodeChild.getNodeName().equals("evaluationDays")) {
                            remainingDays = getStringValue(resultNodeChild, "");
                        }
                        ZOHOCreator.setUserProperty("evaluationDays", remainingDays);//No I18N
                    }
                }
            }
        }
    }

    if (!licenceEnabled) {
        throw new ZCException(
                resourceString.getString("please_subscribe_to_professional_edition_and_get_access"),
                ZCException.LICENCE_ERROR); //No I18N
    }
    return toReturn;
}

From source file:com.zoho.creator.jframework.XMLParser.java

static ZCNavList parseForNavigationListForApps(Document rootDocument) {

    List<ZCSharedGroup> sharedWithGroupList = new ArrayList<ZCSharedGroup>();
    List<String> sharedWithWorkSpaceList = new ArrayList<String>();
    NodeList nl = rootDocument.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node resultNode = nl.item(i);
        if (resultNode.getNodeName().equals("result")) {
            NodeList resultNodes = resultNode.getChildNodes();
            for (int j = 0; j < resultNodes.getLength(); j++) {
                Node resultNodeChild = resultNodes.item(j);
                if (resultNodeChild.getNodeName().equals("allworkspaces")) {
                    NodeList workspacesNodes = resultNodeChild.getChildNodes();
                    for (int k = 0; k < workspacesNodes.getLength(); k++) {
                        Node workspacesNode = workspacesNodes.item(k);
                        if (workspacesNode.getNodeName().equals("workspaces")) {
                            NodeList workspaceNodes = workspacesNode.getChildNodes();
                            for (int l = 0; l < workspaceNodes.getLength(); l++) {
                                Node workspaceNode = workspaceNodes.item(l);
                                if (workspaceNode.getNodeName().equals("workspace")) {
                                    NodeList workspaceownerNodes = workspaceNode.getChildNodes();
                                    for (int m = 0; m < workspaceownerNodes.getLength(); m++) {
                                        Node workspaceownerNode = workspaceownerNodes.item(m);
                                        if (workspaceownerNode.getNodeName().equals("workspaceowner")) {
                                            String workspaceowner = getStringValue(workspaceownerNode, null);
                                            sharedWithWorkSpaceList.add(workspaceowner);
                                        }
                                    }/*w ww .  ja va2  s .  c om*/
                                }
                            }
                        }
                    }
                } else if (resultNodeChild.getNodeName().equals("allsharedcategory")) {
                    NodeList groupsNodes = resultNodeChild.getChildNodes();
                    for (int k = 0; k < groupsNodes.getLength(); k++) {
                        Node groupsNode = groupsNodes.item(k);
                        if (groupsNode.getNodeName().equals("groups")) {
                            NodeList groupNodes = groupsNode.getChildNodes();
                            for (int l = 0; l < groupNodes.getLength(); l++) {
                                Node groupNode = groupNodes.item(l);
                                if (groupNode.getNodeName().equals("group")) {
                                    NodeList groupNodeChildNodes = groupNode.getChildNodes();
                                    String groupName = null;
                                    Long groupId = -1L;
                                    for (int m = 0; m < groupNodeChildNodes.getLength(); m++) {
                                        Node groupNodeChildNode = groupNodeChildNodes.item(m);
                                        if (groupNodeChildNode.getNodeName().equals("groupname")) {
                                            groupName = getStringValue(groupNodeChildNode, groupName);
                                        } else if (groupNodeChildNode.getNodeName().equals("groupid")) {
                                            groupId = getLongValue(groupNodeChildNode, groupId);
                                        }
                                    }
                                    sharedWithGroupList.add(new ZCSharedGroup(groupName, groupId));
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return new ZCNavList(sharedWithGroupList, sharedWithWorkSpaceList);
}

From source file:com.zoho.creator.jframework.XMLParser.java

static List<ZCSection> parseForSectionList(Document rootDocument, String appLinkName, String appOwner)
        throws ZCException {
    List<ZCSection> toReturn = new ArrayList<ZCSection>();
    NodeList nl = rootDocument.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node responseNode = nl.item(i);
        if (responseNode.getNodeName().equals("Response")) {

            NodeList responseNodes = responseNode.getChildNodes();
            for (int j = 0; j < responseNodes.getLength(); j++) {
                Node responseNodeChild = responseNodes.item(j);
                if (responseNodeChild.getNodeName().equals("error")) {
                    throw new ZCException(getStringValue(responseNodeChild, "error"), ZCException.ERROR_OCCURED,
                            "");//No I18N
                } else if (responseNodeChild.getNodeName().equals("Sections")) {

                    NodeList sectionsNodes = responseNodeChild.getChildNodes();

                    for (int k = 0; k < sectionsNodes.getLength(); k++) {
                        Node sectionNode = sectionsNodes.item(k);
                        if (sectionNode.getNodeName().equals("Section")) {
                            NodeList sectionNodes = sectionNode.getChildNodes();
                            String sectionName = null;
                            boolean isHidden = false;
                            String sectionLinkName = null;
                            long sectionID = -1L;
                            Date modifiedTime = null;
                            List<ZCComponent> comps = new ArrayList<ZCComponent>();
                            for (int l = 0; l < sectionNodes.getLength(); l++) {
                                Node sectionNodeChild = sectionNodes.item(l);
                                String nodeName = sectionNodeChild.getNodeName();
                                if (nodeName.equals("Display_Name")) {
                                    sectionName = getStringValue(sectionNodeChild, ""); //No I18N
                                } else if (nodeName.equals("Is_Hidden")) {
                                    isHidden = getBooleanValue(sectionNodeChild, isHidden); //No I18N
                                } else if (nodeName.equals("Link_Name")) {
                                    sectionLinkName = getStringValue(sectionNodeChild, ""); //No I18N
                                } else if (nodeName.equals("Section_ID")) {
                                    sectionID = getLongValue(sectionNodeChild, sectionID); //No I18N
                                } else if (nodeName.equals("Modified_Time")) {
                                    modifiedTime = getDateValue(sectionNodeChild, modifiedTime,
                                            "yyyy-MM-dd HH:mm:ss.S"); //No I18N
                                    // 2013-04-01 14:28:58.0
                                } else if (nodeName.equals("Components")) {
                                    NodeList ComponentsNodes = sectionNodeChild.getChildNodes();
                                    for (int m = 0; m < ComponentsNodes.getLength(); m++) {
                                        Node componentNode = ComponentsNodes.item(m);
                                        if (componentNode.getNodeName().equals("Component")) {
                                            NamedNodeMap attrMap = componentNode.getAttributes();
                                            Node typeNode = attrMap.getNamedItem("type");//No I18N
                                            String type = typeNode.getNodeValue();
                                            NodeList componentNodes = componentNode.getChildNodes();
                                            String componentName = null;
                                            String componentLinkName = null;
                                            int sequenceNumber = -1;
                                            long componentID = -1L;
                                            for (int n = 0; n < componentNodes.getLength(); n++) {
                                                Node componentNodeChild = componentNodes.item(n);
                                                String componentNodeName = componentNodeChild.getNodeName();
                                                String nodeValue = getStringValue(componentNodeChild, "");
                                                if (componentNodeName.equals("Display_Name")) {
                                                    componentName = nodeValue;
                                                } else if (componentNodeName.equals("Link_Name")) {
                                                    componentLinkName = nodeValue;
                                                } else if (componentNodeName.equals("Secquence")) {
                                                    sequenceNumber = Integer.parseInt(nodeValue);
                                                } else if (componentNodeName.equals("Component_ID")) {
                                                    componentID = Long.valueOf(nodeValue);
                                                }
                                            }

                                            if (ZCComponent.isCompTypeSupported(type)) {

                                                comps.add(new ZCComponent(appOwner, appLinkName, type,
                                                        componentName, componentLinkName, sequenceNumber));
                                            }
                                        }
                                    }// ww  w .j a  va  2s  . c om
                                }
                            }
                            ZCSection zcSection = new ZCSection(appOwner, appLinkName, sectionName,
                                    sectionLinkName, isHidden, sectionID, modifiedTime);
                            zcSection.addComponents(comps);
                            toReturn.add(zcSection);
                        }
                    }
                }
            }
        } else if (responseNode.getNodeName().equals("license_enabled")) { //No I18N
            if (!getBooleanValue(responseNode, false)) {
                throw new ZCException(
                        resourceString.getString("please_subscribe_to_professional_edition_and_get_access"),
                        ZCException.LICENCE_ERROR); //No I18N
            }
        } else if (responseNode.getNodeName().equals("evaluationDays")) { //No I18N
            ZOHOCreator.setUserProperty("evaluationDays", getStringValue(responseNode, ""));//No I18N
        }
    }
    return toReturn;
}

From source file:com.zoho.creator.jframework.XMLParser.java

static ZCForm parseForForm(Document rootDocument, String appLinkName, String appOwner, String queryString,
        boolean isEditForm) throws ZCException {
    NodeList nl = rootDocument.getChildNodes();
    ZCForm toReturn = null;//from   w  w w .  jav  a  2 s  .c om
    Hashtable<String, String> queryStringTable = new Hashtable<String, String>();
    //      if(queryString!=null)
    //      {
    //         String[] stringValues = queryString.split("&");
    //         for(int p=0;p<stringValues.length;p++)
    //         {
    //            String[] fieldNameAndValueString = stringValues[p].split("=");
    //            queryStringTable.put(fieldNameAndValueString[0],fieldNameAndValueString[1]);
    //         }
    //      }
    for (int i = 0; i < nl.getLength(); i++) {
        Node responseNode = nl.item(i);
        if (responseNode.getNodeName().equals("errorlist")) {
            NodeList errorListNodes = responseNode.getChildNodes();
            for (int j = 0; j < errorListNodes.getLength(); j++) {
                Node errorNode = errorListNodes.item(j);
                if (errorNode.getNodeName().equals("error")) {
                    NodeList messageNodes = errorNode.getChildNodes();
                    for (int k = 0; k < messageNodes.getLength(); k++) {
                        Node messageNode = messageNodes.item(k);
                        if (messageNode.getNodeName().equals("message")) {
                            throw new ZCException(getStringValue(messageNode, ""), ZCException.ERROR_OCCURED,
                                    "");
                        }
                    }
                }
            }
        } else if (responseNode.getNodeName().equals("response")) {
            boolean hasAddOnLoad = false;
            boolean hasEditOnLoad = false;
            String successMessage = "";
            String dateFormat = "";
            List<ZCField> fields = new ArrayList<ZCField>();
            List<ZCButton> buttons = new ArrayList<ZCButton>();
            boolean isStateLess = false;
            int formLinkId = -1;

            String componentName = null;
            String componentLinkName = null;
            int sequenceNumber = -1;
            Long componentID = -1L;
            String openurlType = "";
            String openurlValue = "";

            NodeList responseNodes = responseNode.getChildNodes();
            for (int j = 0; j < responseNodes.getLength(); j++) {
                Node responseNodeChild = responseNodes.item(j);
                if (responseNodeChild.getNodeName().equals("result")) {

                    NodeList resultNodes = responseNodeChild.getChildNodes();
                    for (int k = 0; k < resultNodes.getLength(); k++) {

                        Node resultNodeChild = resultNodes.item(k);
                        if (resultNodeChild.getNodeName().equalsIgnoreCase("hasAddOnLoad")) {
                            String nodeValue = getStringValue(resultNodeChild, "");
                            hasAddOnLoad = Boolean.valueOf(nodeValue);
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("hasEditOnLoad")) {
                            String nodeValue = getStringValue(resultNodeChild, "");
                            hasEditOnLoad = Boolean.valueOf(nodeValue);
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("captcha")) {
                            throw new ZCException(
                                    resourceString
                                            .getString("captcha_enabled_forms_are_currently_not_supported"),
                                    ZCException.ERROR_OCCURED, "");
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("successMessage")) {
                            successMessage = getStringValue(resultNodeChild, "");
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("dateFormat")) {
                            dateFormat = getStringValue(resultNodeChild, "");
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("errorlist")) {
                            throw new ZCException(parseErrorMessage(resultNodeChild), ZCException.ACCESS_ERROR);
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("type")) {
                            int type = getIntValue(resultNodeChild, 1);
                            if (type == 2) {
                                isStateLess = true;
                            }
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("formLinkId")) {
                            formLinkId = getIntValue(resultNodeChild, formLinkId);
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("DisplayName")) {
                            componentName = getStringValue(resultNodeChild, "");
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("nexturl")) {
                            NodeList openurlNodes = resultNodeChild.getChildNodes();
                            for (int l = 0; l < openurlNodes.getLength(); l++) {
                                Node openurlChildNode = openurlNodes.item(l);
                                if (openurlChildNode.getNodeName().equals("value")) {
                                    openurlValue = getStringValue(openurlChildNode, openurlValue);
                                } else if (openurlChildNode.getNodeName().equals("type")) {
                                    openurlType = getStringValue(openurlChildNode, openurlType);
                                }
                            }
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("labelname")) {
                            componentLinkName = getStringValue(resultNodeChild, "");
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("formid")) {
                            componentID = getLongValue(resultNodeChild, componentID);
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("Fields")) {
                            NodeList fieldNodes = resultNodeChild.getChildNodes();
                            for (int l = 0; l < fieldNodes.getLength(); l++) {
                                Node fieldNode = fieldNodes.item(l);
                                if (fieldNode.getNodeName().equalsIgnoreCase("field")) {
                                    ZCField field = parseField(fieldNode, appLinkName, componentLinkName,
                                            appOwner, false, queryStringTable);
                                    if (field != null) {
                                        if (!isEditForm) {
                                            for (int m = 0; m < field.getDefaultRows(); m++) {
                                                field.addAndGetNewSubFormEntry();
                                            }
                                        }
                                        fields.add(field);
                                    }
                                }

                            }
                        } else if (resultNodeChild.getNodeName().equalsIgnoreCase("buttons")) {

                            NodeList buttonNodes = resultNodeChild.getChildNodes();
                            for (int m = 0; m < buttonNodes.getLength(); m++) {
                                Node buttonNode = buttonNodes.item(m);
                                if (buttonNode.getNodeName().equals("button")) {
                                    NodeList buttonPropetyNodes = buttonNode.getChildNodes();
                                    String buttonDisplayName = null;
                                    String buttonLinkName = null;
                                    ZCButtonType buttonType = null;
                                    int buttonSequenceNumber = -1;
                                    int actiontype = 1;
                                    boolean isOnClickExists = false;
                                    for (int l = 0; l < buttonPropetyNodes.getLength(); l++) {
                                        Node buttonPropetyNode = buttonPropetyNodes.item(l);
                                        if (buttonPropetyNode.getNodeName().equalsIgnoreCase("labelname")) {
                                            buttonLinkName = getStringValue(buttonPropetyNode, buttonLinkName);
                                        } else if (buttonPropetyNode.getNodeName()
                                                .equalsIgnoreCase("sequencenumber")) {
                                            buttonSequenceNumber = getIntValue(buttonPropetyNode,
                                                    buttonSequenceNumber);
                                        } else if (buttonPropetyNode.getNodeName()
                                                .equalsIgnoreCase("actiontype")) {
                                            actiontype = getIntValue(buttonPropetyNode, actiontype);
                                        } else if (buttonPropetyNode.getNodeName().equalsIgnoreCase("type")) {
                                            buttonType = ZCButtonType
                                                    .getButtonType(getIntValue(buttonPropetyNode, 62));
                                        } else if (buttonPropetyNode.getNodeName()
                                                .equalsIgnoreCase("displayname")) {
                                            buttonDisplayName = getStringValue(buttonPropetyNode,
                                                    buttonDisplayName);
                                        } else if (buttonPropetyNode.getNodeName()
                                                .equalsIgnoreCase("onclickexists")) {
                                            isOnClickExists = getBooleanValue(buttonPropetyNode,
                                                    isOnClickExists);
                                        }
                                    }

                                    ZCButton button = new ZCButton(buttonDisplayName, buttonLinkName,
                                            buttonType);
                                    if (isStateLess) {
                                        button.setOnClickExists(isOnClickExists);
                                    }
                                    buttons.add(button);
                                }
                            }
                        }
                    }
                    Collections.sort(buttons);

                    // String appOwner, String appLinkName, String type, String componentName, String componentLinkName, int sequenceNumber, Long componentID, boolean hasAddOnLoad, boolean hasEditOnLoad, String successMessage, String tableName, int formLinkId
                    toReturn = new ZCForm(appOwner, appLinkName, componentName, componentLinkName,
                            sequenceNumber, hasAddOnLoad, hasEditOnLoad, successMessage, dateFormat,
                            isStateLess, openurlType, openurlValue);
                    toReturn.addFields(fields);
                    if (buttons.size() > 0) {
                        toReturn.addButtons(buttons);
                    }
                }
            }
        }
    }
    return toReturn;
}

From source file:it.unibo.alchemist.language.EnvironmentBuilder.java

/**
 * Actually builds the environment given the AST built in the constructor.
 * /*from w w w.jav a 2 s  . co m*/
 * @throws InstantiationException
 *             malformed XML
 * @throws IllegalAccessException
 *             malformed XML
 * @throws InvocationTargetException
 *             malformed XML
 * @throws ClassNotFoundException
 *             your classpath does not include all the classes you are using
 * @throws IOException
 *             if there is an error reading the file
 * @throws SAXException
 *             if the XML is not correctly formatted
 * @throws ParserConfigurationException
 *             should not happen.
 */
private void buildEnvironment()
        throws InstantiationException, IllegalAccessException, InvocationTargetException,
        ClassNotFoundException, SAXException, IOException, ParserConfigurationException {
    final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder builder = factory.newDocumentBuilder();
    final Document doc = builder.parse(xmlFile);
    L.debug("Starting processing");
    random = null;
    final Node root = doc.getFirstChild();
    if (root.getNodeName().equals("environment") && doc.getChildNodes().getLength() == 1) {
        final NamedNodeMap atts = root.getAttributes();
        String type = atts.getNamedItem(TYPE).getNodeValue();
        type = type.contains(".") ? type : "it.unibo.alchemist.model.implementations.environments." + type;
        result = coreOperations(new ConcurrentHashMap<String, Object>(), root, type, null);
        synchronized (result) {
            final Node nameNode = atts.getNamedItem(NAME);
            final String name = nameNode == null ? "" : nameNode.getNodeValue();
            final Map<String, Object> env = new ConcurrentHashMap<String, Object>();
            env.put("ENV", result);
            if (!name.equals("")) {
                env.put(name, result);
            }
            final NodeList children = root.getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                final Node son = children.item(i);
                final String kind = son.getNodeName();
                L.debug(kind);
                if (!kind.equals(TEXT)) {
                    final Node sonNameAttr = son.getAttributes().getNamedItem(NAME);
                    final String sonName = sonNameAttr == null ? "" : sonNameAttr.getNodeValue();
                    Object sonInstance = null;
                    if (kind.equals("molecule")) {
                        sonInstance = buildMolecule(son, env);
                    } else if (kind.equals("concentration")) {
                        if (concentrationClass == null) {
                            setConcentration(son);
                        }
                    } else if (kind.equals("position")) {
                        if (positionClass == null) {
                            setPosition(son);
                        }
                    } else if (kind.equals("random")) {
                        setRandom(son, env);
                    } else if (kind.equals("linkingrule")) {
                        result.setLinkingRule(buildLinkingRule(son, env));
                    } else if (kind.equals("condition")) {
                        sonInstance = buildCondition(son, env);
                    } else if (kind.equals("action")) {
                        sonInstance = buildAction(son, env);
                    } else if (kind.equals("reaction")) {
                        sonInstance = buildReaction(son, env);
                    } else if (kind.equals("node")) {
                        final it.unibo.alchemist.model.interfaces.Node<T> node = buildNode(son, env);
                        final Position pos = buildPosition(son, env);
                        sonInstance = node;
                        result.addNode(node, pos);
                    } else if (kind.equals("time")) {
                        sonInstance = buildTime(son, env);
                    }
                    if (sonInstance != null) {
                        env.put(sonName, sonInstance);
                    }
                }
            }
            /*
             * This operation forces a reset to the random generator. It
             * ensures that if the user reloads the same random seed she
             * passed in the specification, the simulation will still be
             * reproducible.
             */
            random.setSeed(seed);
        }
    } else {
        L.error("XML does not contain one and one only environment.");
    }
}

From source file:com.zoho.creator.jframework.XMLParser.java

public static ZCView parseForView(Document rootDocument, String appLinkName, String appOwner,
        String componentType, int month, int year) throws ZCException {
    NodeList nl = rootDocument.getChildNodes();

    ZCView toReturn = null;//  ww  w  .j a va  2 s .  com
    for (int i = 0; i < nl.getLength(); i++) {

        Node responseNode = nl.item(i);
        if (responseNode.getNodeName().equals("response")) {
            NodeList responseNodes = responseNode.getChildNodes();
            for (int j = 0; j < responseNodes.getLength(); j++) {
                Node responseChildNode = responseNodes.item(j);

                if (responseChildNode.getNodeName().equals("errorlist")) {
                    NodeList errorListNodes = responseChildNode.getChildNodes();
                    for (int o = 0; o < errorListNodes.getLength(); o++) {
                        Node errorlistNode = errorListNodes.item(o);
                        if (errorlistNode.getNodeName().equals("error")) {
                            NodeList errorlistchildNodes = errorlistNode.getChildNodes();
                            int code = 0;
                            boolean hasErrorOcured = false;
                            String errorMessage = "";
                            for (int p = 0; p < errorlistchildNodes.getLength(); p++) {
                                Node errorlistchildNode = errorlistchildNodes.item(p);
                                if (errorlistchildNode.getNodeName().equals("code")) {
                                    code = getIntValue(errorlistchildNode, code);
                                } else if (errorlistchildNode.getNodeName().equals("message")) {
                                    hasErrorOcured = true;
                                    errorMessage = getDecodedString(getStringValue(errorlistchildNode, ""));

                                }
                            }

                            if (hasErrorOcured) {
                                ZCException exception = new ZCException(errorMessage, ZCException.ERROR_OCCURED,
                                        "");
                                exception.setCode(code);
                                throw exception;
                            }
                        }
                    }
                }

                if (responseChildNode.getNodeName().equals("metadata")) {
                    NodeList viewNodes = responseChildNode.getChildNodes();
                    for (int k = 0; k < viewNodes.getLength(); k++) {
                        Node viewNode = viewNodes.item(k);
                        if (viewNode.getNodeName().equals("View")) {
                            NamedNodeMap attrMap = viewNode.getAttributes();
                            String componentLinkName = getDecodedString(
                                    attrMap.getNamedItem("LinkName").getNodeValue());//No I18N

                            String componentName = getDecodedString(getChildNodeValue(viewNode, "DisplayName")); //No I18N
                            String dateFormat = getDecodedString(
                                    attrMap.getNamedItem("DateFormat").getNodeValue());//No I18N
                            //String appOwner, String appLinkName, String componentName, String componentLinkName
                            toReturn = new ZCView(appOwner, appLinkName, componentType, componentName,
                                    componentLinkName);
                            toReturn.setDateFormat(dateFormat);
                            NodeList viewChildNodes = viewNode.getChildNodes();
                            for (int l = 0; l < viewChildNodes.getLength(); l++) {
                                Node viewChildNode = viewChildNodes.item(l);
                                if (viewChildNode.getNodeName().equals("BaseForm")) {
                                    NamedNodeMap baseFormAttrMap = viewChildNode.getAttributes();
                                    String baseFormLinkName = getDecodedString(
                                            baseFormAttrMap.getNamedItem("linkname").getNodeValue()); //No I18N
                                    toReturn.setBaseFormLinkName(baseFormLinkName);
                                } else if (viewChildNode.getNodeName().equals("customFilters")) {
                                    NodeList customFilterNodeList = viewChildNode.getChildNodes();
                                    List<ZCCustomFilter> customFilters = new ArrayList<ZCCustomFilter>();
                                    for (int m = 0; m < customFilterNodeList.getLength(); m++) {
                                        Node customFilterNode = customFilterNodeList.item(m);
                                        NamedNodeMap customFilterAttrMap = customFilterNode.getAttributes();
                                        long id = Long.parseLong(
                                                customFilterAttrMap.getNamedItem("Id").getNodeValue()); //No I18N                                 
                                        String customFilterName = getDecodedString(
                                                getChildNodeValue(customFilterNode, "DisplayName"));//No I18N
                                        ZCCustomFilter customFilter = new ZCCustomFilter(customFilterName, id);
                                        customFilters.add(customFilter);
                                    }
                                    toReturn.addCustomFilters(customFilters);
                                } else if (viewChildNode.getNodeName().equals("filters")) {
                                    NodeList filterNodeList = viewChildNode.getChildNodes();
                                    List<ZCFilter> filters = new ArrayList<ZCFilter>();
                                    for (int m = 0; m < filterNodeList.getLength(); m++) {
                                        Node filterNode = filterNodeList.item(m);
                                        NamedNodeMap filterAttrMap = filterNode.getAttributes();
                                        String FilterLinkName = getDecodedString(
                                                filterAttrMap.getNamedItem("name").getNodeValue()); //No I18N
                                        String filterName = getDecodedString(
                                                getChildNodeValue(filterNode, "displayname")); //filterAttrMap.getNamedItem("displayname").getNodeValue(); //No I18N
                                        ZCFilter filter = new ZCFilter(FilterLinkName, filterName);
                                        NodeList filterValuesList = filterNode.getChildNodes();
                                        List<ZCFilterValue> filterValues = new ArrayList<ZCFilterValue>();
                                        for (int n = 0; n < filterValuesList.getLength(); n++) {
                                            Node filterValueNode = filterValuesList.item(n);
                                            if (filterValueNode.getNodeName().equals("value")) {

                                                String filterValue = getDecodedString(
                                                        getStringValue(filterValueNode, "")); //No I18N
                                                filterValue = filterValue
                                                        .substring(filterValue.indexOf(":") + 1);
                                                String displayValue = filterValue;
                                                NamedNodeMap filterValAttrMap = filterValueNode.getAttributes();
                                                if (filterValAttrMap.getLength() > 0) {
                                                    displayValue = getDecodedString(filterValAttrMap
                                                            .getNamedItem("display").getNodeValue());//No I18N
                                                }
                                                filterValues.add(new ZCFilterValue(filterValue, displayValue));
                                            }
                                        }
                                        filter.addValues(filterValues);
                                        filters.add(filter);
                                    }
                                    toReturn.addFilters(filters);
                                    //                           } else if(viewChildNode.getNodeName().equals("rec_filter")) {

                                    //                           } else if(viewChildNode.getNodeName().equals("groupby")) {

                                    //                           } else if(viewChildNode.getNodeName().equals("opensearch")) {

                                } else if (viewChildNode.getNodeName().equals("permissions")) {
                                    NamedNodeMap permissionAttrMap = viewChildNode.getAttributes();
                                    boolean isAddAllowed = Boolean
                                            .parseBoolean(permissionAttrMap.getNamedItem("add").getNodeValue()); //No I18N
                                    boolean isEditAllowed = Boolean.parseBoolean(
                                            permissionAttrMap.getNamedItem("edit").getNodeValue()); //No I18N
                                    boolean isDeleteAllowed = Boolean.parseBoolean(
                                            permissionAttrMap.getNamedItem("delete").getNodeValue()); //No I18N
                                    boolean isDuplicateAllowed = Boolean.parseBoolean(
                                            permissionAttrMap.getNamedItem("duplicate").getNodeValue()); //No I18N
                                    boolean isBulkEditAllowed = Boolean.parseBoolean(
                                            permissionAttrMap.getNamedItem("bulkedit").getNodeValue()); //No I18N
                                    toReturn.setAddAllowed(isAddAllowed);
                                    toReturn.setEditAllowed(isEditAllowed);
                                    toReturn.setDeleteAllowed(isDeleteAllowed);
                                    toReturn.setDuplicateAllowed(isDuplicateAllowed);
                                    toReturn.setBulkEditAllowed(isBulkEditAllowed);
                                } else if (viewChildNode.getNodeName().equals("Actions")) {
                                    NodeList actionList = viewChildNode.getChildNodes();
                                    List<ZCCustomAction> headerCustomActions = new ArrayList<ZCCustomAction>();
                                    List<ZCCustomAction> recordCustomActions = new ArrayList<ZCCustomAction>();
                                    for (int m = 0; m < actionList.getLength(); m++) {
                                        Node actionNode = actionList.item(m);
                                        NamedNodeMap actionAttrMap = actionNode.getAttributes();
                                        String actionType = getDecodedString(
                                                actionAttrMap.getNamedItem("type").getNodeValue()); //No I18N
                                        String actionName = getDecodedString(
                                                getChildNodeValue(actionNode, "name")); //actionAttrMap.getNamedItem("name").getNodeValue(); //No I18N
                                        String headerAction = getDecodedString(
                                                getChildNodeValue(actionNode, "isHeaderAction"));//No I18N
                                        Long actionId = Long
                                                .parseLong(actionAttrMap.getNamedItem("id").getNodeValue()); //No I18N
                                        ZCCustomAction action = new ZCCustomAction(actionType, actionName,
                                                actionId);
                                        if (actionType.equals("row")) {
                                            recordCustomActions.add(action);
                                        }
                                        if (headerAction.equals("true")) {
                                            headerCustomActions.add(action);
                                        }
                                    }
                                    toReturn.addHeaderCustomActions(headerCustomActions);
                                    toReturn.addRecordCustomActions(recordCustomActions);
                                } else if (viewChildNode.getNodeName().equals("Fields")) {
                                    // String fieldName, int type, String displayName, String delugeType, long compID
                                    List<ZCColumn> columns = new ArrayList<ZCColumn>();
                                    NodeList fieldList = viewChildNode.getChildNodes();
                                    for (int m = 0; m < fieldList.getLength(); m++) {
                                        Node fieldNode = fieldList.item(m);
                                        NamedNodeMap fieldAttrMap = fieldNode.getAttributes();
                                        String displayName = getDecodedString(
                                                getChildNodeValue(fieldNode, "DisplayName")); //fieldAttrMap.getNamedItem("DisplayName").getNodeValue(); //No I18N
                                        String fieldName = getDecodedString(
                                                fieldAttrMap.getNamedItem("BaseLabelName").getNodeValue()); //No I18N
                                        String compType = getDecodedString(
                                                fieldAttrMap.getNamedItem("ComponentType").getNodeValue()); //No I18N
                                        FieldType fieldType = FieldType.getFieldType(compType);
                                        int seqNo = Integer.parseInt(
                                                fieldAttrMap.getNamedItem("SequenceNumber").getNodeValue()); //No I18N
                                        ZCColumn column = new ZCColumn(fieldName, fieldType, displayName);
                                        column.setSequenceNumber(seqNo);
                                        columns.add(column);
                                    }
                                    Collections.sort(columns);
                                    toReturn.addColumns(columns);
                                }
                            }
                        }
                    }
                } else if (responseChildNode.getNodeName().equals("records")) {
                    parseAndSetRecords(toReturn, responseChildNode);
                } else if (responseChildNode.getNodeName().equals("calendar")) {
                    toReturn.setRecordsMonthYear(new ZCPair<Integer, Integer>(month, year));
                    parseAndSetCalendarRecords(toReturn, responseChildNode);
                }
            }
        }
    }
    //printDocument(rootDocument);      
    return toReturn;
}