935090232@qq.com
2022-02-21 d2213e56167dcd77c967e996df7c73e104f019d1
fead:百度编辑器配置文件改造
8 files modified
4 files added
298 ■■■■ changed files
zq-erp/pom.xml 5 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/component/tools/JSONUtil.java 35 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/component/ueditor/ActionEnter.java 7 ●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/component/ueditor/ConfigManager.java 36 ●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/component/ueditor/UeditorProperties.java 64 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/core/tools/EnvironmentHolder.java 31 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/common/actions/UeditorController.java 8 ●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/common/constance/AppConstance.java 16 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/common/constance/PropertiesConstance.java 35 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/resources/config/application-test.properties 28 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/resources/config/application.properties 5 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/resources/config/config.json 28 ●●●● patch | view | raw | blame | history
zq-erp/pom.xml
@@ -374,6 +374,11 @@
            <artifactId>guava</artifactId>
            <version>26.0-jre</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>
    <build>
        <resources>
zq-erp/src/main/java/com/matrix/component/tools/JSONUtil.java
New file
@@ -0,0 +1,35 @@
package com.matrix.component.tools;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import java.util.Objects;
import java.util.Set;
public class JSONUtil {
    /**
     * 用第二个json对象覆盖第一个json对象的值,并返回一个新的json对象
     *
     * @param source
     * @param target
     * @return
     */
    public static JSONObject extend(JSONObject source, JSONObject target) {
        Objects.requireNonNull(source);
        Objects.requireNonNull(target);
        JSONObject jsonObject = JSON.parseObject(source.toJSONString());
        Set<String> set = target.keySet();
        set.stream().forEach(key -> {
            jsonObject.put(key, target.get(key));
        });
        return jsonObject;
    }
}
zq-erp/src/main/java/com/matrix/component/ueditor/ActionEnter.java
@@ -7,6 +7,7 @@
import com.matrix.component.ueditor.hunter.ImageHunter;
import com.matrix.component.ueditor.upload.Uploader;
import com.matrix.component.ueditor.define.State;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@@ -21,14 +22,16 @@
    private String actionType = null;
    
    private ConfigManager configManager = null;
    private UeditorProperties ueditorProperties = null;
    public ActionEnter ( HttpServletRequest request, String rootPath ) {
    public ActionEnter (HttpServletRequest request, String rootPath , UeditorProperties ueditorProperties) {
        
        this.request = request;
        this.rootPath = rootPath;
        this.actionType = request.getParameter( "action" );
        this.contextPath = request.getContextPath();
        this.configManager = ConfigManager.getInstance( this.rootPath, this.contextPath, request.getRequestURI() );
        this.ueditorProperties=ueditorProperties;
        this.configManager = ConfigManager.getInstance( this.rootPath, this.contextPath,  request.getRequestURI() ,ueditorProperties );
        
    }
    
zq-erp/src/main/java/com/matrix/component/ueditor/ConfigManager.java
@@ -10,14 +10,15 @@
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import com.alibaba.fastjson.JSON;
import com.matrix.component.tools.JSONUtil;
import com.matrix.component.ueditor.define.ActionMap;
import com.matrix.core.tools.EnvironmentHolder;
import com.matrix.system.common.constance.PropertiesConstance;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
/**
@@ -26,9 +27,8 @@
 * @author hancong03@baidu.com
 *
 */
public final class ConfigManager implements EnvironmentAware {
public final class ConfigManager {
    private Environment env;
    private final String rootPath;
    private final String originalPath;
    private final String contextPath;
@@ -40,22 +40,17 @@
    // 远程图片抓取filename定义
    private final static String REMOTE_FILE_NAME = "remote";
    private final static String FILES_TORAGE_PATH ="file_storage_path";
    @Override
    public void setEnvironment(Environment environment) {
        env = environment;
    }
    private UeditorProperties ueditorProperties = null;
    /*
     * 通过一个给定的路径构建一个配置管理器, 该管理器要求地址路径所在目录下必须存在config.properties文件
     */
    private ConfigManager(String rootPath, String contextPath, String uri) throws FileNotFoundException, IOException {
    private ConfigManager(String rootPath, String contextPath, String uri, UeditorProperties ueditorProperties ) throws FileNotFoundException, IOException {
        rootPath = rootPath.replace("\\", "/");
        this.ueditorProperties=ueditorProperties;
        this.rootPath = rootPath;
        this.contextPath = contextPath;
        if (contextPath.length() > 0) {
@@ -76,12 +71,13 @@
     *            服务器所在项目路径
     * @param uri
     *            当前访问的uri
     * @param ueditorProperties
     * @return 配置管理器实例或者null
     */
    public static ConfigManager getInstance(String rootPath, String contextPath, String uri) {
    public static ConfigManager getInstance(String rootPath, String contextPath, String uri, UeditorProperties ueditorProperties) {
        try {
            return new ConfigManager(rootPath, contextPath, uri);
            return new ConfigManager(rootPath, contextPath, uri,ueditorProperties);
        } catch (Exception e) {
            return null;
        }
@@ -162,7 +158,7 @@
        conf.put("savePath", savePath);
        String fileStoragePath = env.getProperty(FILES_TORAGE_PATH);
        String fileStoragePath = EnvironmentHolder.getPropertis(PropertiesConstance.FILE_STORAGE_PATH);
        conf.put("rootPath",fileStoragePath);
        return conf;
@@ -181,8 +177,14 @@
        //String configContent = this.readFile(this.getConfigPath());
        String configContent = this.filter(IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("config/config.json")));
        try {
            JSONObject jsonConfig = new JSONObject(configContent);
            com.alibaba.fastjson.JSONObject extend = JSONUtil.extend(
                    JSON.parseObject(configContent),
                    JSON.parseObject(JSON.toJSONString(ueditorProperties)));
            jsonConfig=new JSONObject(extend.toJSONString());
            this.jsonConfig = jsonConfig;
        } catch (Exception e) {
            this.jsonConfig = null;
zq-erp/src/main/java/com/matrix/component/ueditor/UeditorProperties.java
New file
@@ -0,0 +1,64 @@
package com.matrix.component.ueditor;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
@Component
@ConfigurationProperties(prefix = "ueditor")
public class UeditorProperties {
    /**
     * 图片访问路径前缀
     */
    private String imageUrlPrefix;
    /* 上传保存路径,可以自定义保存路径和文件名格式 */
    /* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */
    /* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */
    /* {time} 会替换成时间戳 */
    /* {yyyy} 会替换成四位年份 */
    /* {yy} 会替换成两位年份 */
    /* {mm} 会替换成两位月份 */
    /* {dd} 会替换成两位日期 */
    /* {hh} 会替换成两位小时 */
    /* {ii} 会替换成两位分钟 */
    /* {ss} 会替换成两位秒 */
    /* 非法字符 \ : * ? " < > | */
    /* 具请体看线上文档: fex.baidu.com/ueditor/#use-format_upload_filename */
    private String imagePathFormat;
    /* 涂鸦图片上传配置项 */
    private String scrawlPathFormat;
    private String scrawlUrlPrefix;
    /* 截图工具上传 */
    private String snapscreenPathFormat;
    private String snapscreenUrlPrefix;
    /* 抓取远程图片配置 */
    private String catcherPathFormat;
    private String catcherUrlPrefix;
    /* 上传视频配置 */
    private String videoPathFormat;
    private String videoUrlPrefix;
    /* 上传文件配置 */
    private String filePathFormat;
    private String fileUrlPrefix;
    /* 列出指定目录下的图片 */
    private String imageManagerListPath;
    /* 列出指定目录下的文件 */
    private String fileManagerListPath;
}
zq-erp/src/main/java/com/matrix/core/tools/EnvironmentHolder.java
New file
@@ -0,0 +1,31 @@
package com.matrix.core.tools;
import com.matrix.core.exception.GlobleException;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
public class EnvironmentHolder implements EnvironmentAware {
    private static Environment env;
    @Override
    public void setEnvironment(Environment environment) {
        env = environment;
    }
    /**
     * 获取配置文件中的值
     * @param key
     * @return
     */
    public static String getPropertis(String key) {
        if (env != null) {
            return env.getProperty(key);
        } else {
            throw new GlobleException("Environment 未初始化");
        }
    }
}
zq-erp/src/main/java/com/matrix/system/common/actions/UeditorController.java
@@ -4,8 +4,10 @@
package com.matrix.system.common.actions;
import com.matrix.component.ueditor.ActionEnter;
import com.matrix.component.ueditor.UeditorProperties;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.tools.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -24,6 +26,10 @@
@RequestMapping(value = "admin/beditor")
public class UeditorController {
    @Autowired
    UeditorProperties ueditorProperties;
    /**
     * 百度编辑器主入口方法
     * 
@@ -38,7 +44,7 @@
        response.setContentType("application/json");
        String rootPath = request.getSession().getServletContext().getRealPath("/");
        try {
            String exec = new ActionEnter(request, rootPath).exec();
            String exec = new ActionEnter(request, rootPath,ueditorProperties).exec();
            PrintWriter writer = response.getWriter();
            writer.write(exec);
            writer.flush();
zq-erp/src/main/java/com/matrix/system/common/constance/AppConstance.java
@@ -110,14 +110,6 @@
    public static final String SAFEPATH = "/su";
    public static final String TOKEN_KEY = "token";
    /**
     * nginx访问地址
     */
    public static final String NGINX_URL = "static_resource_url";
    /**
     * 存储路径
     */
    public static final String FILES_TORAGE_PATH = "file_storage_path";
    /**
     * 过滤特殊字符
@@ -601,14 +593,6 @@
     */
    public static final String WX_ORDER_NOTICE_DINGDING_TOKEN = "wxOrderNoticeDingdingToken";
    /**
     * 管理端小程序appid
     */
    public static final String MINI_PROGRAM_MANAGER_APP_ID = "xcx_manager_appid";
    /**
     * 管理端小程序secret
     */
    public static final String MINI_PROGRAM_MANAGER_SECRET = "xcx_manager_secret";
zq-erp/src/main/java/com/matrix/system/common/constance/PropertiesConstance.java
New file
@@ -0,0 +1,35 @@
package com.matrix.system.common.constance;
/**
 * 属性配置文件
 *
 * @author JIANGYOUYAO
 * @email 935090232@qq.com
 * @date Dec 10, 2017
 */
public class PropertiesConstance {
    private PropertiesConstance() {
    }
    /**
     * nginx访问地址
     */
    public static final String NGINX_URL = "static_resource_url";
    /**
     * 存储路径
     */
    public static final String FILE_STORAGE_PATH = "file_storage_path";
}
zq-erp/src/main/resources/config/application-test.properties
@@ -48,4 +48,30 @@
#是否启用异常上报
is_open_exception_report=true
showExcptionUrl=http://test.hive.jyymatrix.cc/showException
showExcptionUrl=http://test.hive.jyymatrix.cc/showException
#百度编辑器,覆盖默认配置
ueditor.imageUrlPrefix=http://testfile.hive.jyymatrix.cc/uploadeFile
ueditor.imagePathFormat=/image/{yyyy}{mm}{dd}/{time}{rand:6}
ueditor.scrawlPathFormat=/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}
ueditor.scrawlUrlPrefix=http://testfile.hive.jyymatrix.cc/uploadeFile
ueditor.snapscreenPathFormat=/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}
ueditor.snapscreenUrlPrefix=http://testfile.hive.jyymatrix.cc/uploadeFile
ueditor.catcherPathFormat=/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}
ueditor.catcherUrlPrefix=http://testfile.hive.jyymatrix.cc/uploadeFile
ueditor.videoPathFormat=/ueditor/jsp/upload/video/{yyyy}{mm}{dd}/{time}{rand:6}
ueditor.videoUrlPrefix=http://127.0.0.1:1088/uploadeFile/
ueditor.filePathFormat=/ueditor/jsp/upload/file/{yyyy}{mm}{dd}/{time}{rand:6}
ueditor.fileUrlPrefix=http://127.0.0.1:1088/uploadeFile/
ueditor.imageManagerListPath=http://127.0.0.1:1088/uploadeFile/
ueditor.fileManagerListPath=http://127.0.0.1:1088/uploadeFile/
zq-erp/src/main/resources/config/application.properties
@@ -125,3 +125,8 @@
zq-erp/src/main/resources/config/config.json
@@ -8,8 +8,8 @@
    "imageCompressEnable": true, /* 是否压缩图片,默认是true */
    "imageCompressBorder": 1600, /* 图片压缩最长边限制 */
    "imageInsertAlign": "none", /* 插入的图片浮动方式 */
    "imageUrlPrefix": "http://testfile.hive.jyymatrix.cc/uploadeFile", /* 图片访问路径前缀 */
    "imagePathFormat": "/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
    "imageUrlPrefix": "", /* 图片访问路径前缀 */
    "imagePathFormat": "", /* 上传保存路径,可以自定义保存路径和文件名格式 */
                                /* {filename} 会替换成原文件名,配置这项需要注意中文乱码问题 */
                                /* {rand:6} 会替换成随机数,后面的数字是随机数的位数 */
                                /* {time} 会替换成时间戳 */
@@ -26,31 +26,31 @@
    /* 涂鸦图片上传配置项 */
    "scrawlActionName": "uploadscrawl", /* 执行上传涂鸦的action名称 */
    "scrawlFieldName": "upfile", /* 提交的图片表单名称 */
    "scrawlPathFormat": "/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
    "scrawlPathFormat": "", /* 上传保存路径,可以自定义保存路径和文件名格式 */
    "scrawlMaxSize": 2048000, /* 上传大小限制,单位B */
    "scrawlUrlPrefix": "http://testfile.hive.jyymatrix.cc/uploadeFile", /* 图片访问路径前缀 */
    "scrawlUrlPrefix": "", /* 图片访问路径前缀 */
    "scrawlInsertAlign": "none",
    /* 截图工具上传 */
    "snapscreenActionName": "uploadimage", /* 执行上传截图的action名称 */
    "snapscreenPathFormat": "/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
    "snapscreenUrlPrefix": "http://testfile.hive.jyymatrix.cc/uploadeFile", /* 图片访问路径前缀 */
    "snapscreenPathFormat": "", /* 上传保存路径,可以自定义保存路径和文件名格式 */
    "snapscreenUrlPrefix": "", /* 图片访问路径前缀 */
    "snapscreenInsertAlign": "none", /* 插入的图片浮动方式 */
    /* 抓取远程图片配置 */
    "catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"],
    "catcherActionName": "catchimage", /* 执行抓取远程图片的action名称 */
    "catcherFieldName": "source", /* 提交的图片列表表单名称 */
    "catcherPathFormat": "/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
    "catcherUrlPrefix": "http://testfile.hive.jyymatrix.cc/uploadeFile", /* 图片访问路径前缀 */
    "catcherPathFormat": "", /* 上传保存路径,可以自定义保存路径和文件名格式 */
    "catcherUrlPrefix": "", /* 图片访问路径前缀 */
    "catcherMaxSize": 2048000, /* 上传大小限制,单位B */
    "catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 抓取图片格式显示 */
    /* 上传视频配置 */
    "videoActionName": "uploadvideo", /* 执行上传视频的action名称 */
    "videoFieldName": "upfile", /* 提交的视频表单名称 */
    "videoPathFormat": "/ueditor/jsp/upload/video/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
    "videoUrlPrefix": "http://127.0.0.1:1088/uploadeFile/", /* 视频访问路径前缀 */
    "videoPathFormat": "", /* 上传保存路径,可以自定义保存路径和文件名格式 */
    "videoUrlPrefix": "", /* 视频访问路径前缀 */
    "videoMaxSize": 102400000, /* 上传大小限制,单位B,默认100MB */
    "videoAllowFiles": [
        ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
@@ -59,8 +59,8 @@
    /* 上传文件配置 */
    "fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */
    "fileFieldName": "upfile", /* 提交的文件表单名称 */
    "filePathFormat": "/ueditor/jsp/upload/file/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
    "fileUrlPrefix": "http://127.0.0.1:1088/uploadeFile/", /* 文件访问路径前缀 */
    "filePathFormat": "", /* 上传保存路径,可以自定义保存路径和文件名格式 */
    "fileUrlPrefix": "", /* 文件访问路径前缀 */
    "fileMaxSize": 51200000, /* 上传大小限制,单位B,默认50MB */
    "fileAllowFiles": [
        ".png", ".jpg", ".jpeg", ".gif", ".bmp",
@@ -72,7 +72,7 @@
    /* 列出指定目录下的图片 */
    "imageManagerActionName": "listimage", /* 执行图片管理的action名称 */
    "imageManagerListPath": "http://127.0.0.1:1088/uploadeFile/", /* 指定要列出图片的目录 */
    "imageManagerListPath": "", /* 指定要列出图片的目录 */
    "imageManagerListSize": 20, /* 每次列出文件数量 */
    "imageManagerUrlPrefix": "", /* 图片访问路径前缀 */
    "imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */
@@ -80,7 +80,7 @@
    /* 列出指定目录下的文件 */
    "fileManagerActionName": "listfile", /* 执行文件管理的action名称 */
    "fileManagerListPath": "http://127.0.0.1:1088/uploadeFile/", /* 指定要列出文件的目录 */
    "fileManagerListPath": "", /* 指定要列出文件的目录 */
    "fileManagerUrlPrefix": "", /* 文件访问路径前缀 */
    "fileManagerListSize": 20, /* 每次列出文件数量 */
    "fileManagerAllowFiles": [