zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
 
package org.jeecg.modules.doc.util;
 
import java.io.File;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.doc.exception.UFOPException;
import org.springframework.util.ResourceUtils;
 
public class UFOPUtils {
    public static String LOCAL_STORAGE_PATH;
    public static String ROOT_PATH;
 
    public static String ENCRYPT_PATH;
    public static final String[] IMG_FILE = new String[]{"bmp", "jpg", "png", "tif", "gif", "jpeg"};
    public static final String[] DOC_FILE = new String[]{"doc", "docx", "ppt", "pptx", "xls", "xlsx", "txt", "hlp", "wps", "rtf", "html", "pdf"};
    public static final String[] VIDEO_FILE = new String[]{"avi", "mp4", "mpg", "mov", "swf"};
    public static final String[] MUSIC_FILE = new String[]{"wav", "aif", "au", "mp3", "ram", "wma", "mmf", "amr", "aac", "flac"};
    public static final String[] TXT_FILE = new String[]{"txt", "html", "java", "xml", "js", "css", "json"};
    public static final int IMAGE_TYPE = 1;
    public static final int DOC_TYPE = 2;
    public static final int VIDEO_TYPE = 3;
    public static final int MUSIC_TYPE = 4;
    public static final int OTHER_TYPE = 5;
    public static final int SHARE_FILE = 6;
    public static final int RECYCLE_FILE = 7;
 
    public UFOPUtils() {
    }
 
    public static boolean isImageFile(String extendName) {
        String[] var1 = IMG_FILE;
        int var2 = var1.length;
 
        for(int var3 = 0; var3 < var2; ++var3) {
            String extend = var1[var3];
            if (extendName.equalsIgnoreCase(extend)) {
                return true;
            }
        }
 
        return false;
    }
 
    public static boolean isVideoFile(String extendName) {
        String[] var1 = VIDEO_FILE;
        int var2 = var1.length;
 
        for(int var3 = 0; var3 < var2; ++var3) {
            String extend = var1[var3];
            if (extendName.equalsIgnoreCase(extend)) {
                return true;
            }
        }
 
        return false;
    }
 
    public static String pathSplitFormat(String filePath) {
        return filePath.replace("///", "/").replace("//", "/").replace("\\\\\\", "/").replace("\\\\", "/");
    }
 
    public static File getLocalSaveFile(String fileUrl) {
        String localSavePath = getStaticPath() + fileUrl;
        return new File(localSavePath);
    }
 
    public static File getCacheFile(String fileUrl) {
        String cachePath = getStaticPath() + "cache" + File.separator + fileUrl;
        return new File(cachePath);
    }
 
    public static File getTempFile(String fileUrl) {
        String tempPath = getStaticPath() + "temp" + File.separator + fileUrl;
        File tempFile = new File(tempPath);
        File parentFile = tempFile.getParentFile();
        if (!parentFile.exists()) {
            boolean result = parentFile.mkdirs();
            if (!result) {
                throw new UFOPException("创建temp目录失败:目录路径:" + parentFile.getPath());
            }
        }
 
        return tempFile;
    }
 
    public static File getProcessFile(String fileUrl) {
        String processPath = getStaticPath() + "temp" + File.separator + "process" + File.separator + fileUrl;
        File processFile = new File(processPath);
        File parentFile = processFile.getParentFile();
        if (!parentFile.exists()) {
            boolean result = parentFile.mkdirs();
            if (!result) {
                throw new UFOPException("创建process目录失败:目录路径:" + parentFile.getPath());
            }
        }
 
        return processFile;
    }
 
    public static String getProjectRootPath() {
        String absolutePath = null;
 
        try {
            String url = ResourceUtils.getURL("classpath:").getPath();
            absolutePath = urlDecode((new File(url)).getAbsolutePath()) + File.separator;
            return absolutePath;
        } catch (FileNotFoundException var2) {
            throw new UFOPException(var2);
        }
    }
 
    public static String urlDecode(String url) {
        String decodeUrl = null;
 
        try {
            decodeUrl = URLDecoder.decode(url, "utf-8");
            return decodeUrl;
        } catch (UnsupportedEncodingException var3) {
            throw new UFOPException("不支持的编码格式", var3);
        }
    }
 
    public static String getStaticPath() {
        String localStoragePath = LOCAL_STORAGE_PATH;
        if (StringUtils.isNotEmpty(localStoragePath)) {
            return (new File(localStoragePath)).getPath() + File.separator;
        } else {
            String projectRootAbsolutePath = getProjectRootPath();
            int index = projectRootAbsolutePath.indexOf("file:");
            if (index != -1) {
                projectRootAbsolutePath = projectRootAbsolutePath.substring(0, index);
            }
 
            return (new File(projectRootAbsolutePath + "static")).getPath() + File.separator;
        }
    }
 
    public static String getUploadFileUrl(String identifier, String extendName) {
        SimpleDateFormat formater = new SimpleDateFormat("yyyyMMdd");
        String path = ROOT_PATH + "/" + formater.format(new Date()) + "/";
        File dir = new File(getStaticPath() + path);
        if (!dir.exists()) {
            boolean result = dir.mkdirs();
            if (!result) {
                throw new UFOPException("创建upload目录失败:目录路径:" + dir.getPath());
            }
        }
 
        path = path + identifier + "." + extendName;
        return path;
    }
 
    public static String getAliyunObjectNameByFileUrl(String fileUrl) {
        if (fileUrl.startsWith("/") || fileUrl.startsWith("\\")) {
            fileUrl = fileUrl.substring(1);
        }
 
        return fileUrl;
    }
 
    public static String formatPath(String path) {
        path = pathSplitFormat(path);
        if ("/".equals(path)) {
            return path;
        } else if (path.endsWith("/")) {
            int length = path.length();
            return path.substring(0, length - 1);
        } else {
            return path;
        }
    }
}