package cn.keking.config; import cn.keking.utils.ConfigUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.io.File; import java.util.Arrays; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; /** * @author: chenjh * @since: 2019/4/10 17:22 */ @Component public class ConfigConstants { static { //pdfbox兼容低版本jdk System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider"); } private static Boolean cacheEnabled; private static String[] simTexts = {}; private static String[] medias = {}; private static String[] convertMedias = {}; private static String mediaConvertDisable; private static String officePreviewType; private static String officePreviewSwitchDisabled; private static String ftpUsername; private static String ftpPassword; private static String ftpControlEncoding; private static String baseUrl; private static String fileDir = ConfigUtils.getHomePath() + File.separator + "file" + File.separator; private static String localPreviewDir; private static CopyOnWriteArraySet trustHostSet; private static String pdfPresentationModeDisable; private static String pdfOpenFileDisable; private static String pdfPrintDisable; private static String pdfDownloadDisable; private static String pdfBookmarkDisable; private static Boolean fileUploadDisable; private static String tifPreviewType; private static String BeiAn; private static String[] prohibit= {}; private static String size; private static String password; private static Boolean deletesourcefile; public static final String DEFAULT_CACHE_ENABLED = "true"; 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"; public static final String DEFAULT_MEDIA_TYPE = "mp3,wav,mp4,flv"; public static final String DEFAULT_OFFICE_PREVIEW_TYPE = "image"; public static final String DEFAULT_OFFICE_PREVIEW_SWITCH_DISABLED = "false"; public static final String DEFAULT_FTP_USERNAME = null; public static final String DEFAULT_FTP_PASSWORD = null; public static final String DEFAULT_FTP_CONTROL_ENCODING = "UTF-8"; public static final String DEFAULT_BASE_URL = "default"; public static final String DEFAULT_FILE_DIR_VALUE = "default"; public static final String DEFAULT_LOCAL_PREVIEW_DIR_VALUE = "default"; public static final String DEFAULT_TRUST_HOST = "default"; public static final String DEFAULT_PDF_PRESENTATION_MODE_DISABLE = "true"; public static final String DEFAULT_PDF_OPEN_FILE_DISABLE = "true"; public static final String DEFAULT_PDF_PRINT_DISABLE = "true"; public static final String DEFAULT_PDF_DOWNLOAD_DISABLE = "true"; public static final String DEFAULT_PDF_BOOKMARK_DISABLE = "true"; public static final String DEFAULT_FILE_UPLOAD_DISABLE = "false"; public static final String DEFAULT_TIF_PREVIEW_TYPE = "tif"; public static final String DEFAULT_BeiAn_DISABLE = "无"; public static final String DEFAULT_size_DISABLE = "500MB"; public static final String DEFAULT_prohibit_DISABLE = "exe,dll"; public static final String DEFAULT_password_DISABLE = "123456"; public static final String DEFAULT_Delete_Source_File_PREVIEW_TYPE = "true"; public static Boolean isCacheEnabled() { return cacheEnabled; } @Value("${cache.enabled:true}") public void setCacheEnabled(String cacheEnabled) { setCacheEnabledValueValue(Boolean.parseBoolean(cacheEnabled)); } public static void setCacheEnabledValueValue(Boolean cacheEnabled) { ConfigConstants.cacheEnabled = cacheEnabled; } public static String[] getSimText() { return simTexts; } @Value("${simText:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}") public void setSimText(String simText) { String[] simTextArr = simText.split(","); setSimTextValue(simTextArr); } public static void setSimTextValue(String[] simText) { ConfigConstants.simTexts = simText; } public static String[] getMedia() { return medias; } @Value("${media:mp3,wav,mp4,flv}") public void setMedia(String media) { String[] mediaArr = media.split(","); setMediaValue(mediaArr); } public static void setMediaValue(String[] Media) { ConfigConstants.medias = Media; } public static String[] getConvertMedias() { return convertMedias; } @Value("${convertMedias:avi,mov,wmv,mkv,3gp,rm}") public void setConvertMedias(String convertMedia) { String[] mediaArr = convertMedia.split(","); setConvertMediaValue(mediaArr); } public static void setConvertMediaValue(String[] ConvertMedia) { ConfigConstants.convertMedias = ConvertMedia; } public static String getMediaConvertDisable() { return mediaConvertDisable; } @Value("${media.convert.disable:true}") public void setMediaConvertDisable(String mediaConvertDisable) { setMediaConvertDisableValue(mediaConvertDisable); } public static void setMediaConvertDisableValue(String mediaConvertDisable) { ConfigConstants.mediaConvertDisable = mediaConvertDisable; } public static String getOfficePreviewType() { return officePreviewType; } @Value("${office.preview.type:image}") public void setOfficePreviewType(String officePreviewType) { setOfficePreviewTypeValue(officePreviewType); } public static void setOfficePreviewTypeValue(String officePreviewType) { ConfigConstants.officePreviewType = officePreviewType; } public static String getFtpUsername() { return ftpUsername; } @Value("${ftp.username:}") public void setFtpUsername(String ftpUsername) { setFtpUsernameValue(ftpUsername); } public static void setFtpUsernameValue(String ftpUsername) { ConfigConstants.ftpUsername = ftpUsername; } public static String getFtpPassword() { return ftpPassword; } @Value("${ftp.password:}") public void setFtpPassword(String ftpPassword) { setFtpPasswordValue(ftpPassword); } public static void setFtpPasswordValue(String ftpPassword) { ConfigConstants.ftpPassword = ftpPassword; } public static String getFtpControlEncoding() { return ftpControlEncoding; } @Value("${ftp.control.encoding:UTF-8}") public void setFtpControlEncoding(String ftpControlEncoding) { setFtpControlEncodingValue(ftpControlEncoding); } public static void setFtpControlEncodingValue(String ftpControlEncoding) { ConfigConstants.ftpControlEncoding = ftpControlEncoding; } public static String getBaseUrl() { return baseUrl; } @Value("${base.url:default}") public void setBaseUrl(String baseUrl) { setBaseUrlValue(baseUrl); } public static void setBaseUrlValue(String baseUrl) { ConfigConstants.baseUrl = baseUrl; } public static String getFileDir() { return fileDir; } @Value("${file.dir:default}") public void setFileDir(String fileDir) { setFileDirValue(fileDir); } public static void setFileDirValue(String fileDir) { if (!DEFAULT_FILE_DIR_VALUE.equalsIgnoreCase(fileDir)) { if (!fileDir.endsWith(File.separator)) { fileDir = fileDir + File.separator; } ConfigConstants.fileDir = fileDir; } } public static String getLocalPreviewDir() { return localPreviewDir; } @Value("${local.preview.dir:default}") public void setLocalPreviewDir(String localPreviewDir) { setLocalPreviewDirValue(localPreviewDir); } public static void setLocalPreviewDirValue(String localPreviewDir) { if (!DEFAULT_LOCAL_PREVIEW_DIR_VALUE.equals(localPreviewDir)) { if (!localPreviewDir.endsWith(File.separator)) { localPreviewDir = localPreviewDir + File.separator; } } ConfigConstants.localPreviewDir = localPreviewDir; } @Value("${trust.host:default}") public void setTrustHost(String trustHost) { setTrustHostValue(trustHost); } public static void setTrustHostValue(String trustHost) { CopyOnWriteArraySet trustHostSet; if (DEFAULT_TRUST_HOST.equalsIgnoreCase(trustHost)) { trustHostSet = new CopyOnWriteArraySet<>(); } else { String[] trustHostArray = trustHost.toLowerCase().split(","); trustHostSet = new CopyOnWriteArraySet<>(Arrays.asList(trustHostArray)); setTrustHostSet(trustHostSet); } setTrustHostSet(trustHostSet); } public static Set getTrustHostSet() { return trustHostSet; } private static void setTrustHostSet(CopyOnWriteArraySet trustHostSet) { ConfigConstants.trustHostSet = trustHostSet; } public static String getPdfPresentationModeDisable() { return pdfPresentationModeDisable; } @Value("${pdf.presentationMode.disable:true}") public void setPdfPresentationModeDisable(String pdfPresentationModeDisable) { setPdfPresentationModeDisableValue(pdfPresentationModeDisable); } public static void setPdfPresentationModeDisableValue(String pdfPresentationModeDisable) { ConfigConstants.pdfPresentationModeDisable = pdfPresentationModeDisable; } public static String getPdfOpenFileDisable() { return pdfOpenFileDisable; } @Value("${pdf.openFile.disable:true}") public void setPdfOpenFileDisable(String pdfOpenFileDisable) { setPdfOpenFileDisableValue(pdfOpenFileDisable); } public static void setPdfOpenFileDisableValue(String pdfOpenFileDisable) { ConfigConstants.pdfOpenFileDisable = pdfOpenFileDisable; } public static String getPdfPrintDisable() { return pdfPrintDisable; } @Value("${pdf.print.disable:true}") public void setPdfPrintDisable(String pdfPrintDisable) { setPdfPrintDisableValue(pdfPrintDisable); } public static void setPdfPrintDisableValue(String pdfPrintDisable) { ConfigConstants.pdfPrintDisable = pdfPrintDisable; } public static String getPdfDownloadDisable() { return pdfDownloadDisable; } @Value("${pdf.download.disable:true}") public void setPdfDownloadDisable(String pdfDownloadDisable) { setPdfDownloadDisableValue(pdfDownloadDisable); } public static void setPdfDownloadDisableValue(String pdfDownloadDisable) { ConfigConstants.pdfDownloadDisable = pdfDownloadDisable; } public static String getPdfBookmarkDisable() { return pdfBookmarkDisable; } @Value("${pdf.bookmark.disable:true}") public void setPdfBookmarkDisable(String pdfBookmarkDisable) { setPdfBookmarkDisableValue(pdfBookmarkDisable); } public static void setPdfBookmarkDisableValue(String pdfBookmarkDisable) { ConfigConstants.pdfBookmarkDisable = pdfBookmarkDisable; } public static String getOfficePreviewSwitchDisabled() { return officePreviewSwitchDisabled; } @Value("${office.preview.switch.disabled:true}") public void setOfficePreviewSwitchDisabled(String officePreviewSwitchDisabled) { ConfigConstants.officePreviewSwitchDisabled = officePreviewSwitchDisabled; } public static void setOfficePreviewSwitchDisabledValue(String officePreviewSwitchDisabled) { ConfigConstants.officePreviewSwitchDisabled = officePreviewSwitchDisabled; } public static Boolean getFileUploadDisable() { return fileUploadDisable; } @Value("${file.upload.disable:false}") public void setFileUploadDisable(Boolean fileUploadDisable) { setFileUploadDisableValue(fileUploadDisable); } public static void setFileUploadDisableValue(Boolean fileUploadDisable) { ConfigConstants.fileUploadDisable = fileUploadDisable; } public static String getTifPreviewType() { return tifPreviewType; } @Value("${tif.preview.type:tif}") public void setTifPreviewType(String tifPreviewType) { setTifPreviewTypeValue(tifPreviewType); } public static void setTifPreviewTypeValue(String tifPreviewType) { ConfigConstants.tifPreviewType = tifPreviewType; } public static String getBeiAn() { return BeiAn; } @Value("${BeiAn:无}") public void setBeiAn(String BeiAn) { setBeiAnValue(BeiAn); } public static void setBeiAnValue(String BeiAn) { ConfigConstants.BeiAn = BeiAn; } public static String[] getprohibit() { return prohibit; } @Value("${prohibit:exe,dll}") public void setprohibit(String prohibit) { String[] prohibittArr = prohibit.split(","); setprohibitValue(prohibittArr); } public static void setprohibitValue(String[] prohibit) { ConfigConstants.prohibit = prohibit; } public static String maxsize() { return size; } @Value("${spring.servlet.multipart.max-file-size:500MB}") public void setsize(String size) { setsizeValue(size); } public static void setsizeValue(String size) { ConfigConstants.size = size; } public static String getpassword() { return password; } @Value("${sc.password:123456}") public void setpassword(String password) { setpasswordValue(password); } public static void setpasswordValue(String password) { ConfigConstants.password = password; } public static Boolean getdeletesourcefile() { return deletesourcefile; } @Value("${delete.source.file:true}") public void setdeletesourcefile(Boolean deletesourcefile) { setdeletesourcefileValue(deletesourcefile); } public static void setdeletesourcefileValue(Boolean deletesourcefile) { ConfigConstants.deletesourcefile = deletesourcefile; } }