fix some codestyle problem

pull/134/MERGE
陈精华 2023-05-06 16:51:06 +08:00
parent 9e3d450854
commit 93fb40d282
No known key found for this signature in database
GPG Key ID: 30BDC970902B755D
19 changed files with 97 additions and 96 deletions

View File

@ -121,12 +121,12 @@ watermark.angle = ${WATERMARK_ANGLE:10}
#Tiftifjsjpgjpgpdfpdf便
tif.preview.type = ${KK_TIF_PREVIEW_TYPE:tif}
#
BeiAn =
beiAn =
#
prohibit =exe,dll,dat
#
sc.password =123456
sc.password = 123456
# OFFICECADTIFF
delete.source.file = true
PDFdpi
#PDFdpi
pdf2jpg.dpi = 105

View File

@ -42,12 +42,12 @@ public class ConfigConstants {
private static String pdfBookmarkDisable;
private static Boolean fileUploadDisable;
private static String tifPreviewType;
private static String BeiAn;
private static String[] prohibit= {};
private static String beiAn;
private static String[] prohibit = {};
private static String size;
private static String password;
private static int pdf2JpgDpi;
private static Boolean deletesourcefile;
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";
@ -68,12 +68,12 @@ public class ConfigConstants {
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_BEIAN = "无";
public static final String DEFAULT_SIZE = "500MB";
public static final String DEFAULT_PROHIBIT = "exe,dll";
public static final String DEFAULT_PASSWORD = "123456";
public static final String DEFAULT_PDF2_JPG_DPI_DISABLE = "105";
public static final String DEFAULT_Delete_Source_File_PREVIEW_TYPE = "true";
public static final String DEFAULT_DELETE_SOURCE_FILE = "true";
public static Boolean isCacheEnabled() {
return cacheEnabled;
@ -367,73 +367,73 @@ public class ConfigConstants {
}
public static String getBeiAn() {
return BeiAn;
return beiAn;
}
@Value("${BeiAn:无}")
public void setBeiAn(String BeiAn) {
setBeiAnValue(BeiAn);
@Value("${beiAn:无}")
public void setBeiAn(String beiAn) {
setBeiAnValue(beiAn);
}
public static void setBeiAnValue(String BeiAn) {
ConfigConstants.BeiAn = BeiAn;
public static void setBeiAnValue(String beiAn) {
ConfigConstants.beiAn = beiAn;
}
public static String[] getprohibit() {
public static String[] getProhibit() {
return prohibit;
}
@Value("${prohibit:exe,dll}")
public void setprohibit(String prohibit) {
String[] prohibittArr = prohibit.split(",");
setprohibitValue(prohibittArr);
public void setProhibit(String prohibit) {
String[] prohibitArr = prohibit.split(",");
setProhibitValue(prohibitArr);
}
public static void setprohibitValue(String[] prohibit) {
public static void setProhibitValue(String[] prohibit) {
ConfigConstants.prohibit = prohibit;
}
public static String maxsize() {
public static String maxSize() {
return size;
}
@Value("${spring.servlet.multipart.max-file-size:500MB}")
public void setsize(String size) {
setsizeValue(size);
public void setSize(String size) {
setSizeValue(size);
}
public static void setsizeValue(String size) {
public static void setSizeValue(String size) {
ConfigConstants.size = size;
}
public static String getpassword() {
public static String getPassword() {
return password;
}
@Value("${sc.password:123456}")
public void setpassword(String password) {
setpasswordValue(password);
public void setPassword(String password) {
setPasswordValue(password);
}
public static void setpasswordValue(String password) {
public static void setPasswordValue(String password) {
ConfigConstants.password = password;
}
public static int getpdf2JpgDpi() {
public static int getPdf2JpgDpi() {
return pdf2JpgDpi;
}
@Value("${pdf.picture.size:105}")
public void pdf2JpgDpi(int pdf2JpgDpi) {
setpdf2JpgDpiValue(pdf2JpgDpi);
setPdf2JpgDpiValue(pdf2JpgDpi);
}
public static void setpdf2JpgDpiValue(int pdf2JpgDpi) {
public static void setPdf2JpgDpiValue(int pdf2JpgDpi) {
ConfigConstants.pdf2JpgDpi = pdf2JpgDpi;
}
public static Boolean getdeletesourcefile() {
return deletesourcefile;
public static Boolean getDeleteSourceFile() {
return deleteSourceFile;
}
@Value("${delete.source.file:true}")
public void setdeletesourcefile(Boolean deletesourcefile) {
setdeletesourcefileValue(deletesourcefile);
public void setDeleteSourceFile(Boolean deleteSourceFile) {
setDeleteSourceFileValue(deleteSourceFile);
}
public static void setdeletesourcefileValue(Boolean deletesourcefile) {
ConfigConstants.deletesourcefile = deletesourcefile;
public static void setDeleteSourceFileValue(Boolean deleteSourceFile) {
ConfigConstants.deleteSourceFile = deleteSourceFile;
}
}

View File

@ -55,11 +55,11 @@ public class ConfigRefreshComponent {
String tifPreviewType;
String prohibit;
String[] prohibitArray;
String BeiAn;
String beiAn;
String size;
String password;
int pdf2JpgDpi;
Boolean deletesourcefile;
boolean deleteSourceFile;
while (true) {
FileReader fileReader = new FileReader(configFilePath);
BufferedReader bufferedReader = new BufferedReader(fileReader);
@ -84,12 +84,12 @@ public class ConfigRefreshComponent {
pdfBookmarkDisable = properties.getProperty("pdf.bookmark.disable", ConfigConstants.DEFAULT_PDF_BOOKMARK_DISABLE);
fileUploadDisable = Boolean.parseBoolean(properties.getProperty("file.upload.disable", ConfigConstants.DEFAULT_FILE_UPLOAD_DISABLE));
tifPreviewType = properties.getProperty("tif.preview.type", ConfigConstants.DEFAULT_TIF_PREVIEW_TYPE);
size = properties.getProperty("spring.servlet.multipart.max-file-size", ConfigConstants.DEFAULT_size_DISABLE);
BeiAn = properties.getProperty("BeiAn", ConfigConstants.DEFAULT_BeiAn_DISABLE);
prohibit = properties.getProperty("prohibit", ConfigConstants.DEFAULT_prohibit_DISABLE);
password = properties.getProperty("sc.password", ConfigConstants.DEFAULT_password_DISABLE);
size = properties.getProperty("spring.servlet.multipart.max-file-size", ConfigConstants.DEFAULT_SIZE);
beiAn = properties.getProperty("beiAn", ConfigConstants.DEFAULT_BEIAN);
prohibit = properties.getProperty("prohibit", ConfigConstants.DEFAULT_PROHIBIT);
password = properties.getProperty("sc.password", ConfigConstants.DEFAULT_PASSWORD);
pdf2JpgDpi = Integer.parseInt(properties.getProperty("pdf2jpg.dpi", ConfigConstants.DEFAULT_PDF2_JPG_DPI_DISABLE));
deletesourcefile = Boolean.parseBoolean(properties.getProperty("delete.source.file", ConfigConstants.DEFAULT_Delete_Source_File_PREVIEW_TYPE));
deleteSourceFile = Boolean.parseBoolean(properties.getProperty("delete.source.file", ConfigConstants.DEFAULT_DELETE_SOURCE_FILE));
prohibitArray = prohibit.split(",");
ConfigConstants.setCacheEnabledValueValue(cacheEnabled);
@ -109,12 +109,12 @@ public class ConfigRefreshComponent {
ConfigConstants.setPdfBookmarkDisableValue(pdfBookmarkDisable);
ConfigConstants.setFileUploadDisableValue(fileUploadDisable);
ConfigConstants.setTifPreviewTypeValue(tifPreviewType);
ConfigConstants.setBeiAnValue(BeiAn);
ConfigConstants.setsizeValue(size);
ConfigConstants.setprohibitValue(prohibitArray);
ConfigConstants.setpasswordValue(password);
ConfigConstants.setpdf2JpgDpiValue(pdf2JpgDpi);
ConfigConstants.setdeletesourcefileValue(deletesourcefile);
ConfigConstants.setBeiAnValue(beiAn);
ConfigConstants.setSizeValue(size);
ConfigConstants.setProhibitValue(prohibitArray);
ConfigConstants.setPasswordValue(password);
ConfigConstants.setPdf2JpgDpiValue(pdf2JpgDpi);
ConfigConstants.setDeleteSourceFileValue(deleteSourceFile);
setWatermarkConfig(properties);
bufferedReader.close();
fileReader.close();

View File

@ -120,7 +120,7 @@ public class FileAttribute {
public Boolean forceUpdatedCache() {
return forceUpdatedCache;
}
public void setforceUpdatedCache(Boolean forceUpdatedCache) {
public void setForceUpdatedCache(Boolean forceUpdatedCache) {
this.forceUpdatedCache = forceUpdatedCache;
}

View File

@ -1,6 +1,5 @@
package cn.keking.service;
import cn.keking.config.ConfigConstants;
import cn.keking.model.FileType;
import cn.keking.utils.RarUtils;
import cn.keking.web.filter.BaseUrlFilter;
@ -68,7 +67,6 @@ public class CompressFileReader {
if (result == ExtractOperationResult.OK) {
FileType type = FileType.typeFromUrl(str[0]);
if (type.equals(FileType.PICTURE)) {
// System.out.println( baseUrl +folderName + "_" + str[0]);
imgUrls.add(baseUrl +folderName + "_/" + str[0].replace("\\", "/"));
}
fileHandlerService.putImgCache(fileName, imgUrls);

View File

@ -250,8 +250,8 @@ public class FileHandlerService {
String imageFilePath;
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
imageFilePath = folder + File.separator + pageIndex + pdf2jpg_image_format;
BufferedImage image = pdfRenderer.renderImageWithDPI(pageIndex, ConfigConstants.getpdf2JpgDpi(), ImageType.RGB);
ImageIOUtil.writeImage(image, imageFilePath, ConfigConstants.getpdf2JpgDpi());
BufferedImage image = pdfRenderer.renderImageWithDPI(pageIndex, ConfigConstants.getPdf2JpgDpi(), ImageType.RGB);
ImageIOUtil.writeImage(image, imageFilePath, ConfigConstants.getPdf2JpgDpi());
String imageUrl = this.getPdf2jpgUrl(pdfName, pageIndex);
imageUrls.add(imageUrl);
}
@ -269,8 +269,7 @@ public class FileHandlerService {
}
} catch (IOException e) {
System.out.println("发生错误:"+e);
// logger.error("Convert pdf to jpg exception, pdfFilePath{}", pdfFilePath, e);
logger.error("Convert pdf to jpg exception, pdfFilePath{}", pdfFilePath, e);
throw new Exception(e);
}finally {
if (doc != null) { //关闭
@ -356,7 +355,6 @@ public class FileHandlerService {
fileName = strs[1] + urlStrr.trim();
attribute.setSkipDownLoad(true);
}
// System.out.println(fileName);
url = WebUtils.encodeUrlFileName(url);
fileName = KkFileUtils.htmlEscape(fileName); //文件名处理
attribute.setType(type);
@ -374,7 +372,7 @@ public class FileHandlerService {
attribute.setFileKey(fileKey);
}
if ("true".equalsIgnoreCase(forceUpdatedCache)) {
attribute.setforceUpdatedCache(true);
attribute.setForceUpdatedCache(true);
}
String tifPreviewType = req.getParameter("tifPreviewType");

View File

@ -56,7 +56,8 @@ public class CadFilePreviewImpl implements FilePreview {
if (!convertResult) {
return otherFilePreview.notSupportedFile(model, fileAttribute, "cad文件转换异常请联系管理员");
}
if( ConfigConstants.getdeletesourcefile()){ //是否保留CAD源文件
//是否保留CAD源文件
if( ConfigConstants.getDeleteSourceFile()) {
KkFileUtils.deleteFileByPath(filePath);
}
if (ConfigConstants.isCacheEnabled()) {

View File

@ -61,7 +61,8 @@ public class CompressFilePreviewImpl implements FilePreview {
}
}
if (!ObjectUtils.isEmpty(fileTree)) {
if( ConfigConstants.getdeletesourcefile()){ //是否保留压缩包源文件
//是否保留压缩包源文件
if (ConfigConstants.getDeleteSourceFile()) {
KkFileUtils.deleteFileByPath(filePath);
}
if (ConfigConstants.isCacheEnabled()) {

View File

@ -114,7 +114,8 @@ public class OfficeFilePreviewImpl implements FilePreview {
// 对转换后的文件进行操作(改变编码方式)
fileHandlerService.doActionConvertedFile(outFilePath);
}
if(ConfigConstants.getdeletesourcefile()){ //是否保留OFFICE源文件
//是否保留OFFICE源文件
if (ConfigConstants.getDeleteSourceFile()) {
KkFileUtils.deleteFileByPath(filePath);
}
if (isUseCached) {

View File

@ -60,8 +60,9 @@ public class TiffFilePreviewImpl implements FilePreview {
return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
}
String filePath = response.getContent();
if(ConvertPicUtil.convertJpg2Pdf(filePath, outFilePath)){
if(ConfigConstants.getdeletesourcefile()){ //是否保留TIFF源文件
if (ConvertPicUtil.convertJpg2Pdf(filePath, outFilePath)) {
//是否保留TIFF源文件
if (ConfigConstants.getDeleteSourceFile()) {
KkFileUtils.deleteFileByPath(filePath);
}
if (ConfigConstants.isCacheEnabled()) {
@ -70,11 +71,10 @@ public class TiffFilePreviewImpl implements FilePreview {
}
model.addAttribute("pdfUrl", pdfName);
return PDF_FILE_PREVIEW_PAGE;
}else {
} else {
return NOT_SUPPORTED_FILE_PAGE;
}
}
else {
} else {
model.addAttribute("pdfUrl", pdfName);
return PDF_FILE_PREVIEW_PAGE;
}

View File

@ -17,14 +17,18 @@ import javax.media.jai.RenderedOp;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.ParameterBlock;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class ConvertPicUtil {
private static final int FIT_WIDTH = 500;
private static final int FIT_HEIGHT = 900;
private final static Logger logger = LoggerFactory.getLogger(ConvertPicUtil.class);
private final static String fileDir = ConfigConstants.getFileDir();
/**
@ -77,10 +81,7 @@ public class ConvertPicUtil {
RenderedOp renderedOp = JAI.create("filestore", pb);
renderedOp.dispose();
logger.info("每页分别保存至: " + fileJpg.getCanonicalPath());
} else {
// logger.info("JPG文件已存在 " + fileJpg.getCanonicalPath());
}
listImageFiles.add(strJpgUrl);
}
@ -105,14 +106,12 @@ public class ConvertPicUtil {
* @param strJpgFile jpg
* @param strPdfFile pdf
*/
private static final int FIT_WIDTH = 500;
private static final int FIT_HEIGHT = 900;
public static boolean convertJpg2Pdf(String strJpgFile, String strPdfFile) {
Document document= null;
Document document = null;
RandomAccessFileOrArray rafa = null;
try {
document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(strPdfFile));
PdfWriter.getInstance(document, Files.newOutputStream(Paths.get(strPdfFile)));
document.open();
rafa = new RandomAccessFileOrArray(new FileChannelRandomAccessSource(new RandomAccessFile(strJpgFile, "r").getChannel()));
int pages = TiffImage.getNumberOfPages(rafa);
@ -131,15 +130,16 @@ public class ConvertPicUtil {
document.close();
rafa.close();
return true;
}
catch (Exception e)
{
System.out.println("错误:"+ e.getMessage());
}
finally {
document.close();
} catch (Exception e) {
logger.error("图片转PDF异常图片文件路径" + strJpgFile, e);
} finally {
try {
rafa.close();
if (document != null && document.isOpen()) {
document.close();
}
if (rafa != null) {
rafa.close();
}
} catch (IOException e) {
e.printStackTrace();
}

View File

@ -13,7 +13,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;
import java.util.UUID;
import static cn.keking.utils.KkFileUtils.isFtpUrl;

View File

@ -43,7 +43,6 @@ public class EncodingDetects {
}
public static void readFile(String file, String code) {
BufferedReader fr;
try {
String myCode = code!=null&&!"".equals(code) ? code : "UTF8";

View File

@ -186,7 +186,7 @@ public class KkFileUtils {
*/
public static boolean isAllowedUpload(String file) {
String fileType = suffixFromFileName(file);
for (String type : ConfigConstants.getprohibit()) {
for (String type : ConfigConstants.getProhibit()) {
if (type.equals(fileType))
return false;
}

View File

@ -2,6 +2,8 @@ package cn.keking.utils;
import io.mola.galimatias.GalimatiasParseException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Base64Utils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.HtmlUtils;
@ -24,6 +26,8 @@ import java.util.regex.Pattern;
**/
public class WebUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(WebUtils.class);
/**
* URL
*
@ -209,7 +213,7 @@ public class WebUtils {
*
* 2022/12/17
*/
public static boolean hefaurl (String url) {
public static boolean isValidUrl(String url) {
String regStr = "^((https|http|ftp|rtsp|mms|file)://)";//[.?*]表示匹配的就是本身
Pattern pattern = Pattern.compile(regStr);
Matcher matcher = pattern.matcher(url);
@ -253,8 +257,7 @@ public class WebUtils {
try {
return new String(Base64Utils.decodeFromString(source.replaceAll(" ", "+").replaceAll("\n", "")), charsets);
} catch (Exception e) {
System.out.println("接入方法错误,或者未使用BASE64");
// e.printStackTrace();
LOGGER.error("url解码异常可能是接入方法错误或者未使用BASE64", e);
return null;
}
}

View File

@ -65,7 +65,7 @@ public class FileController {
return checkResult;
}
fileName = checkResult.getContent().toString();
if(!ConfigConstants.getpassword().equalsIgnoreCase(password)){
if(!ConfigConstants.getPassword().equalsIgnoreCase(password)) {
logger.error("删除文件【{}】失败,密码错误!",fileName);
return ReturnResponse.failure("删除文件失败,密码错误!");
}

View File

@ -40,8 +40,8 @@ public class AttributeSetFilter implements Filter {
request.setAttribute("fileKey", httpRequest.getParameter("fileKey"));
request.setAttribute("switchDisabled", ConfigConstants.getOfficePreviewSwitchDisabled());
request.setAttribute("fileUploadDisable", ConfigConstants.getFileUploadDisable());
request.setAttribute("BeiAn", ConfigConstants.getBeiAn());
request.setAttribute("size", ConfigConstants.maxsize());
request.setAttribute("beiAn", ConfigConstants.getBeiAn());
request.setAttribute("size", ConfigConstants.maxSize());
}
/**

View File

@ -56,7 +56,8 @@ public class TrustDirFilter implements Filter {
}
private boolean allowPreview(String urlPath) {
if(!StringUtils.hasText(urlPath) || !WebUtils.hefaurl(urlPath)){ //判断URL是否合法
//判断URL是否合法
if(!StringUtils.hasText(urlPath) || !WebUtils.isValidUrl(urlPath)) {
return false ;
}
try {

View File

@ -156,7 +156,7 @@
</div>
<div style="display: grid; place-items: center;">
<div>
<a target="_blank" href="https://beian.miit.gov.cn/" >${BeiAn}</a>
<a target="_blank" href="https://beian.miit.gov.cn/">${beiAn}</a>
</div>
</div>
<script>