ConfigConstants.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. package cn.keking.config;
  2. import cn.keking.utils.ConfigUtils;
  3. import org.springframework.beans.factory.annotation.Value;
  4. import org.springframework.stereotype.Component;
  5. import java.io.File;
  6. import java.util.Arrays;
  7. import java.util.Set;
  8. import java.util.concurrent.CopyOnWriteArraySet;
  9. /**
  10. * @author: chenjh
  11. * @since: 2019/4/10 17:22
  12. */
  13. @Component
  14. public class ConfigConstants {
  15. static {
  16. //pdfbox兼容低版本jdk
  17. System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider");
  18. }
  19. private static Boolean cacheEnabled;
  20. private static String[] simTexts = {};
  21. private static String[] medias = {};
  22. private static String[] convertMedias = {};
  23. private static String mediaConvertDisable;
  24. private static String officePreviewType;
  25. private static String officePreviewSwitchDisabled;
  26. private static String ftpUsername;
  27. private static String ftpPassword;
  28. private static String ftpControlEncoding;
  29. private static String baseUrl;
  30. private static String fileDir = ConfigUtils.getHomePath() + File.separator + "file" + File.separator;
  31. private static String localPreviewDir;
  32. private static CopyOnWriteArraySet<String> trustHostSet;
  33. private static String pdfPresentationModeDisable;
  34. private static String pdfOpenFileDisable;
  35. private static String pdfPrintDisable;
  36. private static String pdfDownloadDisable;
  37. private static String pdfBookmarkDisable;
  38. private static Boolean fileUploadDisable;
  39. private static String tifPreviewType;
  40. private static String BeiAn;
  41. private static String[] prohibit= {};
  42. private static String size;
  43. private static String password;
  44. private static Boolean deletesourcefile;
  45. public static final String DEFAULT_CACHE_ENABLED = "true";
  46. public static final String DEFAULT_TXT_TYPE = "txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd";
  47. public static final String DEFAULT_MEDIA_TYPE = "mp3,wav,mp4,flv";
  48. public static final String DEFAULT_OFFICE_PREVIEW_TYPE = "image";
  49. public static final String DEFAULT_OFFICE_PREVIEW_SWITCH_DISABLED = "false";
  50. public static final String DEFAULT_FTP_USERNAME = null;
  51. public static final String DEFAULT_FTP_PASSWORD = null;
  52. public static final String DEFAULT_FTP_CONTROL_ENCODING = "UTF-8";
  53. public static final String DEFAULT_BASE_URL = "default";
  54. public static final String DEFAULT_FILE_DIR_VALUE = "default";
  55. public static final String DEFAULT_LOCAL_PREVIEW_DIR_VALUE = "default";
  56. public static final String DEFAULT_TRUST_HOST = "default";
  57. public static final String DEFAULT_PDF_PRESENTATION_MODE_DISABLE = "true";
  58. public static final String DEFAULT_PDF_OPEN_FILE_DISABLE = "true";
  59. public static final String DEFAULT_PDF_PRINT_DISABLE = "true";
  60. public static final String DEFAULT_PDF_DOWNLOAD_DISABLE = "true";
  61. public static final String DEFAULT_PDF_BOOKMARK_DISABLE = "true";
  62. public static final String DEFAULT_FILE_UPLOAD_DISABLE = "false";
  63. public static final String DEFAULT_TIF_PREVIEW_TYPE = "tif";
  64. public static final String DEFAULT_BeiAn_DISABLE = "无";
  65. public static final String DEFAULT_size_DISABLE = "500MB";
  66. public static final String DEFAULT_prohibit_DISABLE = "exe,dll";
  67. public static final String DEFAULT_password_DISABLE = "123456";
  68. public static final String DEFAULT_Delete_Source_File_PREVIEW_TYPE = "true";
  69. public static Boolean isCacheEnabled() {
  70. return cacheEnabled;
  71. }
  72. @Value("${cache.enabled:true}")
  73. public void setCacheEnabled(String cacheEnabled) {
  74. setCacheEnabledValueValue(Boolean.parseBoolean(cacheEnabled));
  75. }
  76. public static void setCacheEnabledValueValue(Boolean cacheEnabled) {
  77. ConfigConstants.cacheEnabled = cacheEnabled;
  78. }
  79. public static String[] getSimText() {
  80. return simTexts;
  81. }
  82. @Value("${simText:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}")
  83. public void setSimText(String simText) {
  84. String[] simTextArr = simText.split(",");
  85. setSimTextValue(simTextArr);
  86. }
  87. public static void setSimTextValue(String[] simText) {
  88. ConfigConstants.simTexts = simText;
  89. }
  90. public static String[] getMedia() {
  91. return medias;
  92. }
  93. @Value("${media:mp3,wav,mp4,flv}")
  94. public void setMedia(String media) {
  95. String[] mediaArr = media.split(",");
  96. setMediaValue(mediaArr);
  97. }
  98. public static void setMediaValue(String[] Media) {
  99. ConfigConstants.medias = Media;
  100. }
  101. public static String[] getConvertMedias() {
  102. return convertMedias;
  103. }
  104. @Value("${convertMedias:avi,mov,wmv,mkv,3gp,rm}")
  105. public void setConvertMedias(String convertMedia) {
  106. String[] mediaArr = convertMedia.split(",");
  107. setConvertMediaValue(mediaArr);
  108. }
  109. public static void setConvertMediaValue(String[] ConvertMedia) {
  110. ConfigConstants.convertMedias = ConvertMedia;
  111. }
  112. public static String getMediaConvertDisable() {
  113. return mediaConvertDisable;
  114. }
  115. @Value("${media.convert.disable:true}")
  116. public void setMediaConvertDisable(String mediaConvertDisable) {
  117. setMediaConvertDisableValue(mediaConvertDisable);
  118. }
  119. public static void setMediaConvertDisableValue(String mediaConvertDisable) {
  120. ConfigConstants.mediaConvertDisable = mediaConvertDisable;
  121. }
  122. public static String getOfficePreviewType() {
  123. return officePreviewType;
  124. }
  125. @Value("${office.preview.type:image}")
  126. public void setOfficePreviewType(String officePreviewType) {
  127. setOfficePreviewTypeValue(officePreviewType);
  128. }
  129. public static void setOfficePreviewTypeValue(String officePreviewType) {
  130. ConfigConstants.officePreviewType = officePreviewType;
  131. }
  132. public static String getFtpUsername() {
  133. return ftpUsername;
  134. }
  135. @Value("${ftp.username:}")
  136. public void setFtpUsername(String ftpUsername) {
  137. setFtpUsernameValue(ftpUsername);
  138. }
  139. public static void setFtpUsernameValue(String ftpUsername) {
  140. ConfigConstants.ftpUsername = ftpUsername;
  141. }
  142. public static String getFtpPassword() {
  143. return ftpPassword;
  144. }
  145. @Value("${ftp.password:}")
  146. public void setFtpPassword(String ftpPassword) {
  147. setFtpPasswordValue(ftpPassword);
  148. }
  149. public static void setFtpPasswordValue(String ftpPassword) {
  150. ConfigConstants.ftpPassword = ftpPassword;
  151. }
  152. public static String getFtpControlEncoding() {
  153. return ftpControlEncoding;
  154. }
  155. @Value("${ftp.control.encoding:UTF-8}")
  156. public void setFtpControlEncoding(String ftpControlEncoding) {
  157. setFtpControlEncodingValue(ftpControlEncoding);
  158. }
  159. public static void setFtpControlEncodingValue(String ftpControlEncoding) {
  160. ConfigConstants.ftpControlEncoding = ftpControlEncoding;
  161. }
  162. public static String getBaseUrl() {
  163. return baseUrl;
  164. }
  165. @Value("${base.url:default}")
  166. public void setBaseUrl(String baseUrl) {
  167. setBaseUrlValue(baseUrl);
  168. }
  169. public static void setBaseUrlValue(String baseUrl) {
  170. ConfigConstants.baseUrl = baseUrl;
  171. }
  172. public static String getFileDir() {
  173. return fileDir;
  174. }
  175. @Value("${file.dir:default}")
  176. public void setFileDir(String fileDir) {
  177. setFileDirValue(fileDir);
  178. }
  179. public static void setFileDirValue(String fileDir) {
  180. if (!DEFAULT_FILE_DIR_VALUE.equalsIgnoreCase(fileDir)) {
  181. if (!fileDir.endsWith(File.separator)) {
  182. fileDir = fileDir + File.separator;
  183. }
  184. ConfigConstants.fileDir = fileDir;
  185. }
  186. }
  187. public static String getLocalPreviewDir() {
  188. return localPreviewDir;
  189. }
  190. @Value("${local.preview.dir:default}")
  191. public void setLocalPreviewDir(String localPreviewDir) {
  192. setLocalPreviewDirValue(localPreviewDir);
  193. }
  194. public static void setLocalPreviewDirValue(String localPreviewDir) {
  195. if (!DEFAULT_LOCAL_PREVIEW_DIR_VALUE.equals(localPreviewDir)) {
  196. if (!localPreviewDir.endsWith(File.separator)) {
  197. localPreviewDir = localPreviewDir + File.separator;
  198. }
  199. }
  200. ConfigConstants.localPreviewDir = localPreviewDir;
  201. }
  202. @Value("${trust.host:default}")
  203. public void setTrustHost(String trustHost) {
  204. setTrustHostValue(trustHost);
  205. }
  206. public static void setTrustHostValue(String trustHost) {
  207. CopyOnWriteArraySet<String> trustHostSet;
  208. if (DEFAULT_TRUST_HOST.equalsIgnoreCase(trustHost)) {
  209. trustHostSet = new CopyOnWriteArraySet<>();
  210. } else {
  211. String[] trustHostArray = trustHost.toLowerCase().split(",");
  212. trustHostSet = new CopyOnWriteArraySet<>(Arrays.asList(trustHostArray));
  213. setTrustHostSet(trustHostSet);
  214. }
  215. setTrustHostSet(trustHostSet);
  216. }
  217. public static Set<String> getTrustHostSet() {
  218. return trustHostSet;
  219. }
  220. private static void setTrustHostSet(CopyOnWriteArraySet<String> trustHostSet) {
  221. ConfigConstants.trustHostSet = trustHostSet;
  222. }
  223. public static String getPdfPresentationModeDisable() {
  224. return pdfPresentationModeDisable;
  225. }
  226. @Value("${pdf.presentationMode.disable:true}")
  227. public void setPdfPresentationModeDisable(String pdfPresentationModeDisable) {
  228. setPdfPresentationModeDisableValue(pdfPresentationModeDisable);
  229. }
  230. public static void setPdfPresentationModeDisableValue(String pdfPresentationModeDisable) {
  231. ConfigConstants.pdfPresentationModeDisable = pdfPresentationModeDisable;
  232. }
  233. public static String getPdfOpenFileDisable() {
  234. return pdfOpenFileDisable;
  235. }
  236. @Value("${pdf.openFile.disable:true}")
  237. public void setPdfOpenFileDisable(String pdfOpenFileDisable) {
  238. setPdfOpenFileDisableValue(pdfOpenFileDisable);
  239. }
  240. public static void setPdfOpenFileDisableValue(String pdfOpenFileDisable) {
  241. ConfigConstants.pdfOpenFileDisable = pdfOpenFileDisable;
  242. }
  243. public static String getPdfPrintDisable() {
  244. return pdfPrintDisable;
  245. }
  246. @Value("${pdf.print.disable:true}")
  247. public void setPdfPrintDisable(String pdfPrintDisable) {
  248. setPdfPrintDisableValue(pdfPrintDisable);
  249. }
  250. public static void setPdfPrintDisableValue(String pdfPrintDisable) {
  251. ConfigConstants.pdfPrintDisable = pdfPrintDisable;
  252. }
  253. public static String getPdfDownloadDisable() {
  254. return pdfDownloadDisable;
  255. }
  256. @Value("${pdf.download.disable:true}")
  257. public void setPdfDownloadDisable(String pdfDownloadDisable) {
  258. setPdfDownloadDisableValue(pdfDownloadDisable);
  259. }
  260. public static void setPdfDownloadDisableValue(String pdfDownloadDisable) {
  261. ConfigConstants.pdfDownloadDisable = pdfDownloadDisable;
  262. }
  263. public static String getPdfBookmarkDisable() {
  264. return pdfBookmarkDisable;
  265. }
  266. @Value("${pdf.bookmark.disable:true}")
  267. public void setPdfBookmarkDisable(String pdfBookmarkDisable) {
  268. setPdfBookmarkDisableValue(pdfBookmarkDisable);
  269. }
  270. public static void setPdfBookmarkDisableValue(String pdfBookmarkDisable) {
  271. ConfigConstants.pdfBookmarkDisable = pdfBookmarkDisable;
  272. }
  273. public static String getOfficePreviewSwitchDisabled() {
  274. return officePreviewSwitchDisabled;
  275. }
  276. @Value("${office.preview.switch.disabled:true}")
  277. public void setOfficePreviewSwitchDisabled(String officePreviewSwitchDisabled) {
  278. ConfigConstants.officePreviewSwitchDisabled = officePreviewSwitchDisabled;
  279. }
  280. public static void setOfficePreviewSwitchDisabledValue(String officePreviewSwitchDisabled) {
  281. ConfigConstants.officePreviewSwitchDisabled = officePreviewSwitchDisabled;
  282. }
  283. public static Boolean getFileUploadDisable() {
  284. return fileUploadDisable;
  285. }
  286. @Value("${file.upload.disable:false}")
  287. public void setFileUploadDisable(Boolean fileUploadDisable) {
  288. setFileUploadDisableValue(fileUploadDisable);
  289. }
  290. public static void setFileUploadDisableValue(Boolean fileUploadDisable) {
  291. ConfigConstants.fileUploadDisable = fileUploadDisable;
  292. }
  293. public static String getTifPreviewType() {
  294. return tifPreviewType;
  295. }
  296. @Value("${tif.preview.type:tif}")
  297. public void setTifPreviewType(String tifPreviewType) {
  298. setTifPreviewTypeValue(tifPreviewType);
  299. }
  300. public static void setTifPreviewTypeValue(String tifPreviewType) {
  301. ConfigConstants.tifPreviewType = tifPreviewType;
  302. }
  303. public static String getBeiAn() {
  304. return BeiAn;
  305. }
  306. @Value("${BeiAn:无}")
  307. public void setBeiAn(String BeiAn) {
  308. setBeiAnValue(BeiAn);
  309. }
  310. public static void setBeiAnValue(String BeiAn) {
  311. ConfigConstants.BeiAn = BeiAn;
  312. }
  313. public static String[] getprohibit() {
  314. return prohibit;
  315. }
  316. @Value("${prohibit:exe,dll}")
  317. public void setprohibit(String prohibit) {
  318. String[] prohibittArr = prohibit.split(",");
  319. setprohibitValue(prohibittArr);
  320. }
  321. public static void setprohibitValue(String[] prohibit) {
  322. ConfigConstants.prohibit = prohibit;
  323. }
  324. public static String maxsize() {
  325. return size;
  326. }
  327. @Value("${spring.servlet.multipart.max-file-size:500MB}")
  328. public void setsize(String size) {
  329. setsizeValue(size);
  330. }
  331. public static void setsizeValue(String size) {
  332. ConfigConstants.size = size;
  333. }
  334. public static String getpassword() {
  335. return password;
  336. }
  337. @Value("${sc.password:123456}")
  338. public void setpassword(String password) {
  339. setpasswordValue(password);
  340. }
  341. public static void setpasswordValue(String password) {
  342. ConfigConstants.password = password;
  343. }
  344. public static Boolean getdeletesourcefile() {
  345. return deletesourcefile;
  346. }
  347. @Value("${delete.source.file:true}")
  348. public void setdeletesourcefile(Boolean deletesourcefile) {
  349. setdeletesourcefileValue(deletesourcefile);
  350. }
  351. public static void setdeletesourcefileValue(Boolean deletesourcefile) {
  352. ConfigConstants.deletesourcefile = deletesourcefile;
  353. }
  354. }