Java XML NodeList parseSwitchers(NodeList switcherNodes)

Here you can find the source of parseSwitchers(NodeList switcherNodes)

Description

parse Switchers

License

Apache License

Declaration

private static Map<String, Map<String, String>> parseSwitchers(NodeList switcherNodes) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.HashMap;

import java.util.Map;

public class Main {
    private static Map<String, Map<String, String>> parseSwitchers(NodeList switcherNodes) {
        Map<String, Map<String, String>> switchers = new HashMap<>();
        for (int i = 0; i < switcherNodes.getLength(); ++i) {
            Node switcherNode = switcherNodes.item(i);
            NamedNodeMap switcherAttributes = switcherNode.getAttributes();
            if (switcherAttributes != null) {
                String switcherClassName = switcherAttributes.getNamedItem("class").getTextContent();
                Map<String, String> configs = parseSwitcherConfigs(switcherNode.getChildNodes());

                switchers.put(switcherClassName, configs);
            }/*from  w  w  w  . ja  va 2 s.c o m*/
        }

        return switchers;
    }

    private static Map<String, String> parseSwitcherConfigs(NodeList switcherConfigNodes) {
        Map<String, String> configs = new HashMap<>();
        for (int i = 0; i < switcherConfigNodes.getLength(); ++i) {
            NamedNodeMap attributes = switcherConfigNodes.item(i).getAttributes();
            if (attributes != null) {
                String[] keyValue = parseConfigAttr(attributes);
                configs.put(keyValue[0], keyValue[1]);
            }
        }

        return configs;
    }

    private static String[] parseConfigAttr(NamedNodeMap attributes) {
        String key = attributes.getNamedItem("key").getTextContent();
        String value = attributes.getNamedItem("value").getTextContent();
        return new String[] { key, value };
    }
}

Related

  1. mapNodeList(NodeList nodeList)
  2. mergeTextContent(final NodeList nodes)
  3. mergeTextContent(NodeList nodes)
  4. parserXml(NodeList employees, Class class_type)
  5. parseSwitcherConfigs(NodeList switcherConfigNodes)
  6. parseWidget(NodeList widgetList)
  7. prettyPrintLoop(NodeList nodes, StringBuilder string, String indentation)
  8. printNode(NodeList nodeList, int level)
  9. printNodeList(NodeList nodes)