package com.mortals.xhx.daemon.applicationservice.model;

import cn.hutool.core.util.XmlUtil;
import lombok.Data;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import java.io.InputStream;
import java.util.*;

/**
 * 目标服务信息
 *
 * @author: zxfei
 * @date: 2021/11/2 20:12
 * @description:
 **/
@Data
public class DestInfo {

    private String SendServerIp;

    private Integer SendServerPort;

    private String SendServerPath;


    public static Map<String, Set<String>> build() {

        Map<String, Set<String>> filterMap = new HashMap<>();
        List<DestInfo> destInfos = new ArrayList<>();
        ClassLoader classLoader = DestInfo.class.getClassLoader();
        InputStream in = classLoader.getResourceAsStream("capture.xml");
        //解析
        Document document = XmlUtil.readXML(in);
        NodeList nodeListByXPath = XmlUtil.getNodeListByXPath("/Captures//Capture//SendServerIp", document);
        NodeList nodeListByXPath1 = XmlUtil.getNodeListByXPath("/Captures//Capture//SendServerPort", document);
        NodeList nodeListByXPath2 = XmlUtil.getNodeListByXPath("/Captures//Capture//SendServerPath", document);

        Set<String> set = new HashSet<>();
        Set<String> set1 = new HashSet<>();
        Set<String> set2 = new HashSet<>();
        for (int i = 0; i < nodeListByXPath.getLength(); i++) {
            set.add(nodeListByXPath.item(i).getTextContent());
            set1.add(nodeListByXPath1.item(i).getTextContent());
            set2.add(nodeListByXPath2.item(i).getTextContent());

        }
        filterMap.put("SendServerIp", set);
        filterMap.put("SendServerPort", set1);
        filterMap.put("SendServerPath", set2);
        return filterMap;
    }

}
