• XML解析工具类


    package com.alibaba.otter.canal.utils;
    
    import com.alibaba.otter.canal.bo.FileUploadBO;
    import org.elasticsearch.common.xcontent.XContentBuilder;
    import org.elasticsearch.common.xcontent.XContentFactory;
    
    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;
    
    /**
     * @author kaikai_zheng
     * @version 1.0.0
     * @className XmlContentUtil
     * @description //XML模板解析
     * @data 2020-07-13 15:01
     */
    public class XmlContentUtil {
        /**
         * Log转化为ES标准数据
         *
         * @param object 要转化的实体类FileUploadBO
         * @return
         */
        public static XContentBuilder getXContentBuilder(Object object) {
            if (object.getClass().getName().contains("FileUploadBO")) {
                return getEsbMonitorXContentBuilder((FileUploadBO) object);
            }
            return null;
        }
    
        /**
         * FileUploadBO转化为ES标准数据
         *
         * @param fileUploadBO
         * @return
         */
        public static XContentBuilder getEsbMonitorXContentBuilder(FileUploadBO fileUploadBO) {
            XContentBuilder xContentBuilder = null;
            try {
                xContentBuilder = XContentFactory.jsonBuilder().startObject()// 标识开始设置值
                        .field("row_update_time", fileUploadBO.getRowUpdateTime())
                        .endObject();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return xContentBuilder;
        }
    
        /**
         * 生成ES标准数据
         *
         * @param clazz
         * @return
         * @throws IOException
         */
        @SuppressWarnings("rawtypes")
        public static XContentBuilder getXContentBuilderMapping(Class clazz) throws IOException {
            if (clazz.getName().contains("FileUploadBO")) {
                return XmlContentUtil.getEsbMonitorXContentBuilderMapping();
            }
            return null;
        }
    
        /**
         * 生成Monitor的ES标准数据模板
         *
         * @return
         * @throws IOException
         */
        public static XContentBuilder getEsbMonitorXContentBuilderMapping() throws IOException {
            Map<String, Object> keyword = new HashMap<String, Object>();
            keyword.put("type", "keyword");
            keyword.put("ignore_above", 256);
            XContentBuilder mapping = XContentFactory.jsonBuilder()
                    .startObject()//标识开始设置值
                    .startObject("row_update_time")
                    .startObject("date").field("type", "date").startObject("fields").field("keyword", keyword).endObject().endObject()
                    .endObject().endObject();
            return mapping;
        }
    
    }
  • 相关阅读:
    python tkinter坐标转换
    python tkinter画圆
    打开pycharm提示python已停止工作
    关于python读写文件的r+方式的坑
    pycharm的一个bug,pycharm 在debug时,会运行项目下的所有文件,而不是当前文件
    python tkinter实时显示曲线
    书上关于*(p++)表达式的几种变形形式的思考题
    lua 中的 loadfile、dofile和require的调用
    css控制字体线使用:text-decoration
    devpi 快速入门:上传,测试,推送发行版
  • 原文地址:https://www.cnblogs.com/zk-blog/p/13409770.html
Copyright © 2020-2023  润新知