java使用xstream框架生成xml文件

1 JAVA代码生成XML框架

主要依赖

        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.4.20</version>
        </dependency>

2 代码如下, 主要是内部标签嵌套规则, 还可以把XML对象转换成bean对象

java 复制代码
package cn.djrj.web.controller.indicatorManage.xml.module;

import cn.djrj.common.utils.StringUtils;
import cn.djrj.system.domain.SysUseModule;
import cn.djrj.system.domain.SysUseModuleParam;
import com.google.common.collect.ImmutableMap;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.naming.NoNameCoder;
import com.thoughtworks.xstream.io.xml.Xpp3Driver;

import java.util.*;
import java.util.stream.Collectors;

public class ModuleCombineUtil {

    public static void main(String args[]) {
        List<ItemSet> list = getSysIndicatorCombines();

        List<ShortbarItem> shortlist = getShortbar();

        List<UrlTag> weblist = getWebTag();

        toXML(list,shortlist,weblist);
    }


    //组装生成XML文件的功能配置
    public static String createXML(List<SysUseModule> list, Map<Long, SysUseModuleParam> configParam) {
        if (null == list || list.isEmpty()) {
            throw new RuntimeException("创建XML的参数为空,无法生成");
        }
        // 生成menu标签
        List<ItemSet> itemList = new ArrayList<>();
        // 生成shorbar标签
        List<ShortbarItem> shortBarList = new ArrayList<>();
        // 生成web标签
        List<UrlTag> webList = new ArrayList<>();

        // shortbar 一级目录
        ShortbarItem shortbarItem = new ShortbarItem();
        shortbarItem.setType(3);
        shortbarItem.setSort(100);
        shortBarList.add(shortbarItem);

        list.forEach(sysUseModule -> {

            Map<String, String> configParams;
            //menu标签 功能类型
            //if (null != sysUseModule.getUseType() && "0".equals(sysUseModule.getUseType()) || "3".equals(sysUseModule.getUseType()) ) {
                //导航区域,0=顶部
                if (null != sysUseModule.getNavigationArea() && "0".equals(sysUseModule.getNavigationArea())){
                    //menu 标签
                    extractedMenu(configParam, itemList, sysUseModule);
                } else if (null != sysUseModule.getNavigationArea() ) { // shortbar标签
                    //导航1
                    if ("1".equals(sysUseModule.getNavigationArea())) {
                        configParams = new HashMap<>();
                        getStrToMap(sysUseModule.getModuleParamId(), configParam,configParams);

                        ShortbarItem shortbarItem0 = new ShortbarItem();
                        shortbarItem0.setTitle(sysUseModule.getName());
                        shortbarItem0.setType(0);
                        shortbarItem0.setImage(configParams.getOrDefault("image", null));
                        shortbarItem0.setImageSel(configParams.getOrDefault("image_sel", null));
                        shortbarItem0.setCmd(configParams.getOrDefault("cmd", null));
                        shortbarItem0.setTip(sysUseModule.getCode());

                        //间距特殊处理
                        shortbarItem0.setSeparator(configParams.getOrDefault("separator", null) != null ? true : null);
                        shortbarItem0.setFunType(configParams.getOrDefault("funType", null) == null ? null : Integer.valueOf(configParams.get("funType")));
                        shortbarItem0.setType(configParams.getOrDefault("type", null) == null ? 0 : Integer.parseInt(configParams.get("type")));
                        shortbarItem0.setSort(0);
                        if (null != configParams.getOrDefault("separator", null) && configParams.getOrDefault("funType", null) == null) {
                            shortbarItem0.setType(1);
                            shortbarItem0.setTitle("");
                            shortbarItem0.setImage(null);
                            shortbarItem0.setImageSel(null);
                            shortbarItem0.setCmd(null);
                            shortbarItem0.setTip(null);
                            shortbarItem0.setSeparator(true);
                        }
                        shortbarItem0.setContext(configParam.getOrDefault(sysUseModule.getModuleParamId(), new SysUseModuleParam()).getContext());

                        shortBarList.add(shortbarItem0);
                    } else if (Arrays.asList(new String[]{"2", "3", "4"}).contains(sysUseModule.getNavigationArea())) {
                        Map<String, String> paramChildernMap = getStrToMapChildern(sysUseModule.getModuleParamId(), configParam,sysUseModule.getNavigationArea());
                        //二级目录
                        ShortbarItem shortbarItem2 = new ShortbarItem();
                        shortbarItem2.setTitle(sysUseModule.getName());
                        shortbarItem2.setType(1);
                        if (null != sysUseModule.getChildern() && sysUseModule.getChildern().size() > 0) {
                            shortbarItem2.setType(4);
                        }
                        shortbarItem2.setImage(paramChildernMap.getOrDefault("image", null));
                        shortbarItem2.setImageSel(paramChildernMap.getOrDefault("image_sel", null));
                        shortbarItem2.setCmd(paramChildernMap.getOrDefault("cmd", null));

                        //生成XML的CMD固定属性
                        if (null != sysUseModule.getUseType() && "3".equals(sysUseModule.getUseType())) {
                            shortbarItem2.setCmd("zbzh:" + sysUseModule.getName());
                        }
                        shortbarItem2.setImageHover(paramChildernMap.getOrDefault("image_hover", null));
                        shortbarItem2.setContext(configParam.getOrDefault(sysUseModule.getModuleParamId(), new SysUseModuleParam()).getContext());

                        shortbarItem.getItem().add(shortbarItem2);
                        if (null != sysUseModule.getChildern() && sysUseModule.getChildern().size() > 0) {
                            // 三级目录数据转换
                            for (SysUseModule module : sysUseModule.getChildern()) {
                                configParams = new HashMap<>();
                                getStrToMap(module.getModuleParamId(), configParam,configParams);
                                ShortbarItem shortChildern = new ShortbarItem();
                                shortChildern.setTitle(module.getName());
                                shortChildern.setTip(module.getCode());
                                shortChildern.setType(1);
                                //shortChildern.setImage(configParams.getOrDefault("image", null));
                                //shortChildern.setImageSel(configParams.getOrDefault("image_sel", null));
                                shortChildern.setCmd(configParams.getOrDefault("cmd", null));
                                //shortChildern.setImageHover(configParams.getOrDefault("image_hover", null));
                                shortChildern.setContext(configParam.getOrDefault(module.getModuleParamId(), new SysUseModuleParam()).getContext());

                                shortbarItem2.getItem().add(shortChildern);
                            }
                        }
                    }
                }

                // web标签
                if (null != sysUseModule.getUseType() && "1".equals(sysUseModule.getUseType())) {
                    extractedTOweb(configParam, webList, sysUseModule,false);
                }
                // 二级网页
                if (null != sysUseModule.getChildern() && sysUseModule.getChildern().size() > 0) {
                   for (SysUseModule module : sysUseModule.getChildern()) {
                        if (null != module.getUseType() && "1".equals(module.getUseType())) {
                            extractedTOweb(configParam, webList, module,false);
                        }
                    }
                }
        });

        return toXML(itemList, shortBarList.stream().sorted(Comparator.comparing(ShortbarItem::getSort)).collect(Collectors.toList()), webList);
    }

    // menu功能菜单
    private static void extractedMenu(Map<Long, SysUseModuleParam> configParam, List<ItemSet> itemList, SysUseModule sysUseModule) {
        Map<String, String> configParams;
        ItemSet itemSet = new ItemSet();
        itemSet.setTitle(sysUseModule.getName());
        itemSet.setTip(sysUseModule.getCode());

        configParams = new HashMap<>();
        getStrToMap(sysUseModule.getModuleParamId(), configParam,configParams);
        itemSet.setCmd(configParams.getOrDefault("cmd", null));
        if (null != configParams.getOrDefault("sel", null)) {
            itemSet.setSel(Integer.valueOf(configParams.get("sel")));
        }
        itemSet.setType(0);
        itemSet.setContext(configParam.getOrDefault(sysUseModule.getModuleParamId(), new SysUseModuleParam()).getContext());

        if (null != sysUseModule.getChildern() && sysUseModule.getChildern().size() > 0) {
            // 二级目录数据转换
            for (SysUseModule module : sysUseModule.getChildern()) {
                configParams = new HashMap<>();
                 getStrToMap(module.getModuleParamId(), configParam,configParams);
                ItemSet itemChildern = new ItemSet();
                itemChildern.setTitle(module.getName());
                itemChildern.setFunType(1);
                itemChildern.setTip(module.getCode());
                itemChildern.setCmd(configParams.getOrDefault("cmd", null));
                //生成XML的CMD固定属性
                if (null != module.getUseType() && "3".equals(module.getUseType())) {
                    itemChildern.setCmd("zbzh:" + module.getName());
                }
                //间距特殊处理
                itemChildern.setSeparator(configParams.getOrDefault("separator", null) != null ? true : null);
                itemChildern.setFunType(configParams.getOrDefault("funType", null) == null ? null : Integer.valueOf(configParams.get("funType")));
                //分隔符处理
                if (null != configParams.getOrDefault("separator", null) && configParams.getOrDefault("funType", null) == null) {
                    itemChildern.setType(1);
                    itemChildern.setFunType(null);
                    itemChildern.setTitle("");
                    itemChildern.setTip(null);
                    itemChildern.setCmd(null);
                    itemChildern.setSeparator(true);
                }

                itemChildern.setContext(configParam.getOrDefault(module.getModuleParamId(), new SysUseModuleParam()).getContext());

                itemSet.getItem().add(itemChildern);
            }
            itemSet.setFunType(2);
        }
        itemList.add(itemSet);
    }

    // web标签封装数据
    private static void extractedTOweb(Map<Long, SysUseModuleParam> configParam, List<UrlTag> webList, SysUseModule sysUseModule,boolean flag) {
        Map<String, String> paramWebMap = new HashMap<>();
        getStrToMap(sysUseModule.getModuleParamId(), configParam,paramWebMap);
        UrlTag web = new UrlTag();
        web.setTitle(sysUseModule.getName());
        web.setTip(sysUseModule.getCode());
        if ("1".equals(sysUseModule.getOpenType())) {
            web.setOpen(2);
        } else if ("2".equals(sysUseModule.getOpenType())) {
            web.setOpen(1);
        }
        web.setOpen(0);
        web.setWeb(sysUseModule.getUrl());
        web.setId(paramWebMap.getOrDefault("id", null));
        web.setContext(configParam.getOrDefault(sysUseModule.getModuleParamId(), new SysUseModuleParam()).getContext());

        if (StringUtils.isNotBlank(sysUseModule.getConfigXmlParam())) {
            String[] str = sysUseModule.getConfigXmlParam().split(",");
            for (String p : str) {
                Ptag ptag = new Ptag();
                ptag.setType(p);
                web.getP().add(ptag);
            }
        }
        webList.add(web);
        if (null != sysUseModule.getChildern() && sysUseModule.getChildern().size() > 0 && flag) {
            for (SysUseModule module : sysUseModule.getChildern()) {
                paramWebMap = new HashMap<>();
                getStrToMap(module.getModuleParamId(), configParam,paramWebMap);
                UrlTag webChildern = new UrlTag();
                webChildern.setTitle(module.getName());
                webChildern.setTip(module.getCode());
                if ("1".equals(module.getOpenType())) {
                    webChildern.setOpen(2);
                } else if ("2".equals(module.getOpenType())) {
                    webChildern.setOpen(1);
                }
                webChildern.setOpen(0);
                webChildern.setWeb(module.getUrl());
                webChildern.setContext(configParam.getOrDefault(module.getModuleParamId(), new SysUseModuleParam()).getContext());

                webChildern.setId(paramWebMap.getOrDefault("id", null));
                if (StringUtils.isNotBlank(module.getConfigXmlParam())) {
                    String[] str = module.getConfigXmlParam().split(",");
                    for (String p : str) {
                        Ptag ptag = new Ptag();
                        ptag.setType(p);
                        webChildern.getP().add(ptag);
                    }
                }
                webList.add(webChildern);
            }
        }
    }

    public static String toXML(List<ItemSet> list,List<ShortbarItem> shortbarItemList,List<UrlTag> weblist) {
        Config config = new Config();
        // menu标签
        Menu menu = new Menu();
        config.setMenu(menu);
        menu.setItem(list);

        // Shortbar标签
        Shortbar shortbar = new Shortbar();
        config.setShortbar(shortbar);
        shortbar.setItem(shortbarItemList);

        // Web标签
        Web web = new Web();
        config.setWeb(web);
        web.setUrl(weblist);

        //special 标签
        Special special = new Special();
        config.setSpecial(special);
        special.setZh(getSpecialZhTag());

        //fs_main 标签
        FsMain fsMain = new FsMain();
        config.setFs_main(fsMain);
        fsMain.setZh(getFsMainTag());

        //fs_sub 标签
        FsSub fsSub = new FsSub();
        config.setFs_sub(fsSub);
        fsSub.setZh(getfsSubZhTag());

        //kx_main 标签
        KxMain kxMain = new KxMain();
        config.setKx_main(kxMain);
        kxMain.setZh(getkxMainTag());

        //kx_sub 标签
        KxSub kxsub = new KxSub();
        config.setKx_sub(kxsub);
        kxsub.setZh(getKxSubZhTag());

        XStream xStream = new XStream(new Xpp3Driver(new NoNameCoder()));
        //不加设置, 注解别名不生效
        xStream.autodetectAnnotations(true);

        xStream.alias("config", Config.class);
        xStream.alias("menu", Menu.class);
        xStream.alias("item", ItemSet.class);
        /  ignore
/*        xStream.omitField(ItemSet.class, "draw");;*/

        // menu 标签 list数据属性
        xStream.addImplicitCollection(Menu.class, "item", "item", ItemSet.class);

        xStream.useAttributeFor(ItemSet.class, "title");
        xStream.useAttributeFor(ItemSet.class, "type");
        xStream.useAttributeFor(ItemSet.class, "sel");
        xStream.useAttributeFor(ItemSet.class, "funType");
        xStream.useAttributeFor(ItemSet.class, "tip");
        xStream.useAttributeFor(ItemSet.class, "cmd");
        xStream.useAttributeFor(ItemSet.class, "separator");
        xStream.useAttributeFor(ItemSet.class, "context");
        xStream.omitField(ItemSet.class, "context");

        xStream.addImplicitCollection(ItemSet.class, "item");

        // shortbar 标签
        xStream.addImplicitCollection(Shortbar.class, "item", "item", ShortbarItem.class);

        xStream.alias("shortbar", Shortbar.class);
        xStream.alias("item", ShortbarItem.class);
        //xStream.aliasField("image_sel",ShortbarItem.class,"image_sel");

        xStream.useAttributeFor(ShortbarItem.class, "title");
        xStream.useAttributeFor(ShortbarItem.class, "image");
        xStream.useAttributeFor(ShortbarItem.class, "imageSel");
        xStream.useAttributeFor(ShortbarItem.class, "type");
        xStream.useAttributeFor(ShortbarItem.class, "funType");
        xStream.useAttributeFor(ShortbarItem.class, "cmd");
        xStream.useAttributeFor(ShortbarItem.class, "tip");
        xStream.useAttributeFor(ShortbarItem.class, "separator");
        xStream.useAttributeFor(ShortbarItem.class, "imageHover");
        xStream.omitField(ShortbarItem.class, "sort");
        xStream.useAttributeFor(ShortbarItem.class, "context");
        xStream.omitField(ShortbarItem.class, "context");
        xStream.addImplicitCollection(ShortbarItem.class, "item");

        // web标签
        xStream.alias("web", Web.class);
        xStream.alias("url", UrlTag.class);
        xStream.useAttributeFor(UrlTag.class, "title");
        xStream.useAttributeFor(UrlTag.class, "web");
        xStream.useAttributeFor(UrlTag.class, "open");
        xStream.useAttributeFor(UrlTag.class, "fixed");
        xStream.useAttributeFor(UrlTag.class, "tip");
        xStream.useAttributeFor(UrlTag.class, "id");
        xStream.useAttributeFor(UrlTag.class, "context");
        xStream.omitField(UrlTag.class, "context");

        xStream.addImplicitCollection(Web.class, "url");
        xStream.addImplicitCollection(UrlTag.class, "p", "p", Ptag.class);
        xStream.useAttributeFor(Ptag.class, "type");

        //special 标签
        xStream.alias("special", Special.class);
        xStream.alias("zh", SpeZh.class);
        xStream.useAttributeFor(SpeZh.class, "title");
        xStream.useAttributeFor(SpeZh.class, "isMain");
        xStream.useAttributeFor(SpeZh.class, "type");

        xStream.addImplicitCollection(Special.class, "zh");

        //fs_main 标签
        xStream.alias("fs_main", FsMain.class);
        xStream.alias("zh", Title.class);
        xStream.useAttributeFor(Title.class,"title");
        xStream.useAttributeFor(Title.class,"context");
        //xStream.addImplicitCollection(Title.class, "title");

        xStream.addImplicitCollection(FsMain.class, "zh");

        //fs_sub 标签
        xStream.alias("fs_sub", FsSub.class);
        xStream.alias("zh", ZhSub.class);
        xStream.useAttributeFor(ZhSub.class, "title");
        xStream.addImplicitCollection(FsSub.class, "zh");

        //kx_main 标签
        xStream.alias("kx_main", KxMain.class);
        xStream.alias("zh", ZhSub.class);
        xStream.useAttributeFor(Title.class, "title");
        xStream.addImplicitCollection(KxMain.class, "zh");

        //kx_sub 标签
        xStream.alias("kx_sub", KxSub.class);
        xStream.alias("zh", ZhSub.class);
        xStream.useAttributeFor(Title.class, "title");
        xStream.addImplicitCollection(KxSub.class, "zh");

        String string = xStream.toXML(config);
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \n";
        //System.out.println(xml + string);
        return xml + string;
    }

    private static List<ItemSet> getSysIndicatorCombines() {
        ItemSet itemSet = new ItemSet();
        itemSet.setTitle("海王体验版");
        itemSet.setSel(100);
        itemSet.setFunType(1000);
        itemSet.setType(10000);

        ItemSet itemSet001 = new ItemSet();
        itemSet001.setSel(1100);
        itemSet001.setFunType(11000);
        itemSet001.setType(110000);
        itemSet.getItem().add(itemSet001);

        /
        ItemSet itemSet1 = new ItemSet();
        itemSet1.setTitle("赢家体验版");
        itemSet1.setSel(200);
        itemSet1.setFunType(2000);
        itemSet1.setType(20000);

        ItemSet itemSet002 = new ItemSet();
        itemSet002.setSel(2200);
        itemSet002.setFunType(22000);
        itemSet002.setType(220000);
        itemSet1.getItem().add(itemSet002);

        List<ItemSet> list = new ArrayList<>();
        list.add(itemSet);
        list.add(itemSet1);
        return list;
    }

    private static List<ShortbarItem> getShortbar() {
        //一级功能
        ShortbarItem itemSet = new ShortbarItem();
        itemSet.setTitle("交易");
        itemSet.setImageSel("100");
        itemSet.setFunType(1000);
        itemSet.setType(0);

        //二级功能
/*
        ShortbarItem itemSet001 = new ShortbarItem();
        itemSet001.setImageSel("1100");
        itemSet001.setFunType(11000);
        itemSet001.setType(110000);
        itemSet.getItem().add(itemSet001);
*/

        /一级功能
        ShortbarItem itemSet1 = new ShortbarItem();
        itemSet1.setType(3);
        itemSet1.setFunType(null);
        //二级功能
        ShortbarItem itemSet002 = new ShortbarItem();
        itemSet002.setImageSel("2200");
        itemSet002.setFunType(22000);
        itemSet002.setType(220000);
        itemSet1.getItem().add(itemSet002);

        //三级功能
        ShortbarItem itemSet003 = new ShortbarItem();
        itemSet003.setImageSel("3300");
        itemSet003.setFunType(33000);
        itemSet003.setType(330000);
        itemSet002.getItem().add(itemSet003);

        List<ShortbarItem> list = new ArrayList<>();
        list.add(itemSet);
        list.add(itemSet1);
        return list;
    }

    private static List<UrlTag> getWebTag() {
        //一级功能
        UrlTag itemSet = new UrlTag();
        itemSet.setTitle("F10");
        itemSet.setWeb("www.baidu.com");
        itemSet.setOpen(11);
        itemSet.setFixed("true");

        //二级功能
        Ptag itemSet001 = new Ptag();
        itemSet001.setType("broker");

        Ptag itemSet002 = new Ptag();
        itemSet002.setType("stock");

        itemSet.getP().add(itemSet001);
        itemSet.getP().add(itemSet002);

        /一级功能
        UrlTag itemSet1 = new UrlTag();
        itemSet1.setTitle("自选资讯");
        itemSet1.setWeb("http://basic.10jqka.com.cn/");
        itemSet1.setOpen(22);
        itemSet1.setFixed("false");

        //二级功能
 /*       Ptag itemSet002 = new Ptag();
        itemSet002.setImageSel("2200");
        itemSet002.setFunType(22000);
        itemSet002.setType(220000);
        itemSet1.getItem().add(itemSet002);*/

        List<UrlTag> list = new ArrayList<>();
        list.add(itemSet);
        list.add(itemSet1);
        return list;
    }

    private static List<SpeZh> getSpecialZhTag() {
        List<SpeZh> zhList = new ArrayList<>();
        zhList.add(new SpeZh("MACD","0"));
        zhList.add(new SpeZh("DMI","0"));
        zhList.add(new SpeZh("DMA","0"));
        zhList.add(new SpeZh("FSL","0"));
        zhList.add(new SpeZh("TRIX","0"));
        zhList.add(new SpeZh("BRAR","0"));
        zhList.add(new SpeZh("CR","0"));
        zhList.add(new SpeZh("VR","0"));
        zhList.add(new SpeZh("OBV","0"));
        zhList.add(new SpeZh("ASI","0"));
        zhList.add(new SpeZh("EMV","0"));
        zhList.add(new SpeZh("VOL","0"));
        zhList.add(new SpeZh("RSI","0"));
        zhList.add(new SpeZh("WR","0"));
        zhList.add(new SpeZh("KDJ","0"));
        zhList.add(new SpeZh("CCI","0"));
        zhList.add(new SpeZh("ROC","0"));
        zhList.add(new SpeZh("MTM","0"));
        zhList.add(new SpeZh("BOLL","0"));
        zhList.add(new SpeZh("PSY","0"));

        zhList.add(new SpeZh("MA", "1", "fxt"));
        zhList.add(new SpeZh("MA2", "1", "fxt"));
        zhList.add(new SpeZh("EXPMA", "1", "fxt"));
        zhList.add(new SpeZh("BBIBOLL", "1", "fxt"));
        return zhList;
    }

    private static List<ZhSub> getfsSubZhTag() {
        List<ZhSub> zhList = new ArrayList<>();
        zhList.add(new ZhSub("MACD"));
        zhList.add(new ZhSub("KDJ"));
        zhList.add(new ZhSub("BOLL"));
        zhList.add(new ZhSub("DMI"));
        zhList.add(new ZhSub("WR"));
        return zhList;
    }

    private static List<ZhSub> getkxMainTag() {
        List<ZhSub> zhList = new ArrayList<>();
        zhList.add(new ZhSub("MA"));
        zhList.add(new ZhSub("MA2"));
        zhList.add(new ZhSub("EXPMA"));
        zhList.add(new ZhSub("BBIBOLL"));
        return zhList;
    }

    private static List<ZhSub> getKxSubZhTag() {
        List<ZhSub> zhList = new ArrayList<>();
        zhList.add(new ZhSub("MACD"));
        zhList.add(new ZhSub("DMI"));
        zhList.add(new ZhSub("DMA"));
        zhList.add(new ZhSub("FSL"));
        zhList.add(new ZhSub("TRIX"));

        zhList.add(new ZhSub("BRAR"));
        zhList.add(new ZhSub("CR"));
        zhList.add(new ZhSub("VR"));
        zhList.add(new ZhSub("OBV"));
        zhList.add(new ZhSub("ASI"));
        zhList.add(new ZhSub("EMV"));

        zhList.add(new ZhSub("VOL"));
        zhList.add(new ZhSub("RSI"));
        zhList.add(new ZhSub("WR"));
        zhList.add(new ZhSub("KDJ"));
        zhList.add(new ZhSub("CCI"));
        zhList.add(new ZhSub("ROC"));
        zhList.add(new ZhSub("MTM"));
        zhList.add(new ZhSub("BOLL"));
        zhList.add(new ZhSub("PSY"));
        return zhList;
    }

    private static List<Title> getFsMainTag() {
        List<Title> titles = new ArrayList<>();
        Title ti = new Title();
        ti.setTitle("MA");
       // ti.setContext("name=MACD,isMain=0");
        titles.add(ti);
        return titles;
    }


    private static void getStrToMap(Long id,Map configParam,Map configParams) {
        if (null == id) {
            return;
        }
        Map<String, String> map = configParams == null || configParams.isEmpty() ? new HashMap<>() : configParams;
        SysUseModuleParam paramMap = (SysUseModuleParam) configParam.getOrDefault(id, null);
        if (null != paramMap && StringUtils.isNotBlank(paramMap.getContext())) {
            // 拼装固定参数
            // String str = "image=ShortBar,image_sel=ShortBar";
            String[] pairs = paramMap.getContext().split("&");
            for (String pair : pairs) {
                String[] keyValue = pair.split("=");
                configParams.put(keyValue[0], keyValue[1]);
            }
        }
    }

    private static Map<String,String> getStrToMapChildern(Long id,Map configParam,String areaValue) {
        if (null == id) {
            return new HashMap<>();
        }
        Map<String, String> map = new HashMap<>();
        SysUseModuleParam paramMap = (SysUseModuleParam) configParam.getOrDefault(id, null);
        if (null != paramMap && StringUtils.isNotBlank(paramMap.getContext())) {
            // 拼装固定参数
            if (StringUtils.isNotBlank(areaValue)) {
                if (null != PARAM_AREA_MAP.getOrDefault(areaValue, null)) {
                    paramMap.setContext(paramMap.getContext() + "&" + PARAM_AREA_MAP.getOrDefault(areaValue, null));
                }
            }
            // String str = "image=ShortBar,image_sel=ShortBar";
            String[] pairs = paramMap.getContext().split("&");
            for (String pair : pairs) {
                String[] keyValue = pair.split("=");
                map.put(keyValue[0], keyValue[1]);
            }
        }
        // System.out.println(map);
        return map;
    }

    public static Map<String, String> PARAM_AREA_MAP = ImmutableMap.<String, String>builder()
            .put("2","image=#B19659&image_sel=#FFC10A&image_hover=#FFDA88")
            .put("3","image=#926995&image_sel=#F7A1FF&image_hover=#F9AAFF")
            .put("4","image=#61709C&image_sel=#B5C8FF&image_hover=#94AFFF").build();

/*   手拼成XML生成方式
 private String createXML(List<ItemSet> list){
        String[] types = new String[]{"CONCEPT-概念", "FGBK-风格", "DYBK-地域", "HYBK-行业"};
            //创建document
            Document document = DocumentHelper.createDocument();
            //创建根节点
            Element root = DocumentHelper.createElement("config");
            document.setRootElement(root);
            //创建根节点下的子节点
            for (String type : types) {
                Element bigblock = root.addElement("bigblock");
                bigblock.addAttribute("code", type.split("-")[0]);
                bigblock.addAttribute("setcode", "");
                bigblock.addAttribute("name", "");
                }
            return document.getXMLEncoding();
    }*/


}

生成XML如下

XML 复制代码
<?xml version="1.0" encoding="UTF-8" ?>
<config>
	<menu>
		<item title="决策" funType=2>
			<item title="市场热点" funType=1 shortcut="SCRD" cmd="cmd:25"/>
			<item title="行情异动" funType=1 shortcut="HQYD"  cmd="cmd:65"/>
			<item title="" type=1 separator=true />
			<item title="龙头掘金" cmd="cmd:69" right="300"/>
			<item title="" type=1 separator=true />
			<item title="资金监控" cmd="zbzh:资金监控"/>
		</item>
		
		<item title="发现" funType=2>
			<item title="未来大事" funType=1 cmd="web"/>
			<item title="事件驱动" funType=1 cmd="web"/>
			<item title="盘口异动" funType=1 cmd="web"/>
			<item title="个股避雷" funType=1 cmd="web"/>
		</item>
		<item title="交易" cmd="trade"/>
	</menu>
	<shortbar>
		<item title="首页" image="ShortBar/new_sy" image_sel="ShortBar/new_sy" type=0 funType=0 cmd="cmd:3"/>
		<item title="" image="ShortBar/jy" image_sel="ShortBar/jy" type=-1 separator=true funType=6 />
		<item type =2>
			<item title="自选股" tip="自选股" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:16,9002,-1,0">
				<item title="自选股" tip="自选股" cmd="cmd:16,9002,-1,0"/>
				<item title="最近浏览" tip="最近浏览" cmd="cmd:16,9114,-1,0"/>
			</item>
			<item title="全景图" tip="全景图" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:3">
				<item title="全景图" tip="全景图" cmd="cmd:3"/>
			</item>
		</item>
		<item type =2>
			<item title="大盘" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:67">
				<item title="中证500" cmd="cmd:2,120"/>
				<item title="上证50" cmd="cmd:2,114"/>
			</item>
			<item title="B股" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:101,7,14,1">
				<item title="沪深B股" cmd="cmd:101,7,14,1"/>
				<item title="上证B股" cmd="cmd:101,1,14,1"/>
				<item title="深证B股" cmd="cmd:101,3,14,1"/>
			</item>
		</item>
		<item type =2>
			<item title="板块" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:9,36,-1,0">
				<item title="概念板块" cmd="cmd:9,37,-1,0"/>
			</item>
			<item title="基金" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:66,9,14,1">
				<item title="沪深基金" cmd="cmd:66,9,14,1"/>
				<item title="ETF基金" cmd="cmd:66,75,14,1"/>
			</item>
			
		</item>	
		<item type =2>
			<item title="个股" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:60,6,14,1">
				<item title="科创板" cmd="cmd:60,74,14,1"/>
				<item title="沪深300" cmd="cmd:2,119"/>
			</item>
			<item title="债券" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:102,8,14,1">
				<item title="可转债" cmd="cmd:102,28,14,1"/>
			</item>
			
		</item>	
		<item type =2>
			<item title="综合排名" image="#B19659" image_sel="#FFC10A" image_hover="#FFF078" type=4 cmd="cmd:8,6">
				<item title="综合排名" cmd="cmd:8,6"/>
				<item title="财务分析" cmd="cmd:62,6,50,1"/>
			</item>
		</item>	
		
		<item type =2>
			<item title="市场热点" type=1 image="#926995" image_sel="#F7A1FF" image_hover="#F67EFF"  shortcut="SCRD" cmd="cmd:25"/>
			<item title="行情异动" type=1 image="#926995" image_sel="#F7A1FF" image_hover="#F67EFF" shortcut="HQYD"  cmd="cmd:65"/>
		</item>
	</shortbar>
	<web>
		<url title="F10" web="http://basic.10jqka.com.cn/" open=0 >
			<p type="broker"/>
		</url>
		<url title="自选资讯"  web="https://cn/pc/#/index?active=3" id="73" />
		
		<url title="未来大事" web="https://-tt" id="74" />
		<url title="个股避雷" web="https://-tesan" id="77" />
		<url title="个股资讯" web="http://.1.1/hrhg/zxList">
			<p type="stock"/>
			<p type="bzs"/>
			<p type="skin"/>
		</url>
		
		<url title="研究报告" web="http://47..148.190/hrhg/yb">
			<p type="stock"/>
		</url>
		<url title="行业资讯" web="http://hrhg/blocklist">
			<p type="stock_hyblockcode"/>
			<p type="stock_hyblockname"/>
		</url>
		
		<url title="payInfo" web="http://47:80/course/pay">
		</url>
		<url title="SetDrawLine" web="http://16379/api/drawLines/set">
			<p type="phone"/>
			<p type="plaform"/>
			<p type="key"/>
		</url>

		<url title="webTest" web="https://win32/api/winuser/nc-winuser-wndproc" />
		<url title="今日最相似" web="http:49.:8880/klineRank" />
		<url title="commonShortcuts_jsp" web="web/.html" open=2/>
		<url title="helpManual_mqt" web="web/.html" open=2/>

		<url title="Register" web="http://16379/api/user/register?" open=0 >
			<p type="username"/>
			<p type="phone"/>
			<p type="code"/>
			<p type="password"/>
			<p type="confirmPassword"/>
			<p type="inviteCode"/>
		</url>

	<special>
		<!-- </zh> -->
		<zh title="MACD" isMain="0"/>
		<zh title="DMI" isMain="0"/>
		<zh title="MTM" isMain="0"/>
		<zh title="BOLL" isMain="0"/>
		<zh title="PSY" isMain="0"/>
	</special>
	
	<fs_main>
		<zh title="MA"/>
	</fs_main>
	<fs_sub>
		<zh title="MACD"/>
		<zh title="WR"/>
	</fs_sub>
	<kx_main>
		<zh title="MA"/>
		<zh title="MA2"/>
		<zh title="BBIBOLL"/>
	</kx_main>
	<kx_sub>
		<zh title="MACD"/>
		<zh title="MTM"/>
		<zh title="BOLL"/>
		<zh title="PSY"/>
	</kx_sub>
	
	<vip_zb_rights>
		<vip name="估值脉络线"  spell="GZMLX"/>
	</vip_zb_rights>
	<images>
	</images>
	<saveScheme save=1>
	</saveScheme>
	<tabBar hide=1>
	</tabBar>
	<skinVisible hide=0>
	</skinVisible>
</config>
相关推荐
xlsw_26 分钟前
java全栈day20--Web后端实战(Mybatis基础2)
java·开发语言·mybatis
神仙别闹1 小时前
基于java的改良版超级玛丽小游戏
java
梧桐树04291 小时前
python常用内建模块:collections
python
Dream_Snowar1 小时前
速通Python 第三节
开发语言·python
黄油饼卷咖喱鸡就味增汤拌孜然羊肉炒饭2 小时前
SpringBoot如何实现缓存预热?
java·spring boot·spring·缓存·程序员
暮湫2 小时前
泛型(2)
java
超爱吃士力架2 小时前
邀请逻辑
java·linux·后端
南宫生2 小时前
力扣-图论-17【算法学习day.67】
java·学习·算法·leetcode·图论
转码的小石2 小时前
12/21java基础
java
李小白662 小时前
Spring MVC(上)
java·spring·mvc