commit
4f86a56f59
|
@ -142,6 +142,10 @@ pdf2jpg.dpi = ${KK_PDF2JPG_DPI:144}
|
||||||
office.type.web = ${KK_OFFICE_TYPE_WEB:web}
|
office.type.web = ${KK_OFFICE_TYPE_WEB:web}
|
||||||
#Cad类型图片浏览模式:tif(利用前端js插件浏览);svg(转换为svg显示);pdf(转换为pdf后显示,便于打印)
|
#Cad类型图片浏览模式:tif(利用前端js插件浏览);svg(转换为svg显示);pdf(转换为pdf后显示,便于打印)
|
||||||
cad.preview.type = ${KK_CAD_PREVIEW_TYPE:pdf}
|
cad.preview.type = ${KK_CAD_PREVIEW_TYPE:pdf}
|
||||||
|
#Cad转换超时设置
|
||||||
|
cad.timeout =${KK_CAD_TIMEOUT:90}
|
||||||
|
#Cad转换线程设置
|
||||||
|
cad.thread =${KK_CAD_THREAD:5}
|
||||||
|
|
||||||
#OFFICE转换模块设置
|
#OFFICE转换模块设置
|
||||||
#生成限制 默认不限制 使用方法 (1-5)
|
#生成限制 默认不限制 使用方法 (1-5)
|
||||||
|
|
|
@ -58,6 +58,8 @@ public class ConfigConstants {
|
||||||
private static Boolean officeExportBookmarks;
|
private static Boolean officeExportBookmarks;
|
||||||
private static Boolean officeExportNotes;
|
private static Boolean officeExportNotes;
|
||||||
private static Boolean officeDocumentOpenPasswords;
|
private static Boolean officeDocumentOpenPasswords;
|
||||||
|
private static String cadTimeout;
|
||||||
|
private static int cadThread;
|
||||||
|
|
||||||
public static final String DEFAULT_CACHE_ENABLED = "true";
|
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_TXT_TYPE = "txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd";
|
||||||
|
@ -89,6 +91,9 @@ public class ConfigConstants {
|
||||||
public static final String DEFAULT_DELETE_CAPTCHA = "false";
|
public static final String DEFAULT_DELETE_CAPTCHA = "false";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String DEFAULT_CAD_TIMEOUT = "90";
|
||||||
|
public static final String DEFAULT_CAD_THREAD = "5";
|
||||||
|
|
||||||
public static final String DEFAULT_OFFICE_PAQERANQE = "false";
|
public static final String DEFAULT_OFFICE_PAQERANQE = "false";
|
||||||
public static final String DEFAULT_OFFICE_WATERMARK = "false";
|
public static final String DEFAULT_OFFICE_WATERMARK = "false";
|
||||||
public static final String DEFAULT_OFFICE_QUALITY = "80";
|
public static final String DEFAULT_OFFICE_QUALITY = "80";
|
||||||
|
@ -469,6 +474,23 @@ public class ConfigConstants {
|
||||||
ConfigConstants.deleteSourceFile = deleteSourceFile;
|
ConfigConstants.deleteSourceFile = deleteSourceFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Boolean getDeleteCaptcha() {
|
||||||
|
return deleteCaptcha;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Value("${delete.captcha:false}")
|
||||||
|
public void setDeleteCaptcha(Boolean deleteCaptcha) {
|
||||||
|
setDeleteCaptchaValue(deleteCaptcha);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setDeleteCaptchaValue(Boolean deleteCaptcha) {
|
||||||
|
ConfigConstants.deleteCaptcha = deleteCaptcha;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以下为cad转换模块设置
|
||||||
|
*/
|
||||||
|
|
||||||
public static String getCadPreviewType() {
|
public static String getCadPreviewType() {
|
||||||
return cadPreviewType;
|
return cadPreviewType;
|
||||||
}
|
}
|
||||||
|
@ -482,17 +504,32 @@ public class ConfigConstants {
|
||||||
ConfigConstants.cadPreviewType = cadPreviewType;
|
ConfigConstants.cadPreviewType = cadPreviewType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Boolean getDeleteCaptcha() {
|
|
||||||
return deleteCaptcha;
|
public static String getCadTimeout() {
|
||||||
|
return cadTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${delete.captcha:false}")
|
@Value("${cad.timeout:90}")
|
||||||
public void setDeleteCaptcha(Boolean deleteCaptcha) {
|
public void setCadTimeout(String cadTimeout) {
|
||||||
setDeleteCaptchaValue(deleteCaptcha);
|
setCadTimeoutValue(cadTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDeleteCaptchaValue(Boolean deleteCaptcha) {
|
public static void setCadTimeoutValue(String cadTimeout) {
|
||||||
ConfigConstants.deleteCaptcha = deleteCaptcha;
|
ConfigConstants.cadTimeout = cadTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int getCadThread() {
|
||||||
|
return cadThread;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Value("${cad.thread:5}")
|
||||||
|
public void setCadThread(int cadthread) {
|
||||||
|
setCadThreadValue(cadthread);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCadThreadValue(int cadthread) {
|
||||||
|
ConfigConstants.cadThread = cadthread;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -70,6 +70,8 @@ public class ConfigRefreshComponent {
|
||||||
boolean officExportBookmarks;
|
boolean officExportBookmarks;
|
||||||
boolean officeExportNotes;
|
boolean officeExportNotes;
|
||||||
boolean officeDocumentOpenPasswords;
|
boolean officeDocumentOpenPasswords;
|
||||||
|
String cadTimeout;
|
||||||
|
int cadThread;
|
||||||
while (true) {
|
while (true) {
|
||||||
FileReader fileReader = new FileReader(configFilePath);
|
FileReader fileReader = new FileReader(configFilePath);
|
||||||
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||||
|
@ -110,6 +112,8 @@ public class ConfigRefreshComponent {
|
||||||
officExportBookmarks = Boolean.parseBoolean(properties.getProperty("office.exportbookmarks", ConfigConstants.DEFAULT_OFFICE_EXPORTBOOKMARKS));
|
officExportBookmarks = Boolean.parseBoolean(properties.getProperty("office.exportbookmarks", ConfigConstants.DEFAULT_OFFICE_EXPORTBOOKMARKS));
|
||||||
officeExportNotes = Boolean.parseBoolean(properties.getProperty("office.exportnotes", ConfigConstants.DEFAULT_OFFICE_EXPORTNOTES));
|
officeExportNotes = Boolean.parseBoolean(properties.getProperty("office.exportnotes", ConfigConstants.DEFAULT_OFFICE_EXPORTNOTES));
|
||||||
officeDocumentOpenPasswords = Boolean.parseBoolean(properties.getProperty("office.documentopenpasswords", ConfigConstants.DEFAULT_OFFICE_EOCUMENTOPENPASSWORDS));
|
officeDocumentOpenPasswords = Boolean.parseBoolean(properties.getProperty("office.documentopenpasswords", ConfigConstants.DEFAULT_OFFICE_EOCUMENTOPENPASSWORDS));
|
||||||
|
cadTimeout = properties.getProperty("cad.timeout", ConfigConstants.DEFAULT_CAD_TIMEOUT);
|
||||||
|
cadThread = Integer.parseInt(properties.getProperty("cad.thread", ConfigConstants.DEFAULT_CAD_THREAD));
|
||||||
prohibitArray = prohibit.split(",");
|
prohibitArray = prohibit.split(",");
|
||||||
|
|
||||||
ConfigConstants.setCacheEnabledValueValue(cacheEnabled);
|
ConfigConstants.setCacheEnabledValueValue(cacheEnabled);
|
||||||
|
@ -145,6 +149,8 @@ public class ConfigRefreshComponent {
|
||||||
ConfigConstants.setOfficeDocumentOpenPasswordsValue(officeDocumentOpenPasswords);
|
ConfigConstants.setOfficeDocumentOpenPasswordsValue(officeDocumentOpenPasswords);
|
||||||
ConfigConstants.setDeleteSourceFileValue(deleteSourceFile);
|
ConfigConstants.setDeleteSourceFileValue(deleteSourceFile);
|
||||||
ConfigConstants.setDeleteCaptchaValue(deleteCaptcha);
|
ConfigConstants.setDeleteCaptchaValue(deleteCaptcha);
|
||||||
|
ConfigConstants.setCadTimeoutValue(cadTimeout);
|
||||||
|
ConfigConstants.setCadThreadValue(cadThread);
|
||||||
setWatermarkConfig(properties);
|
setWatermarkConfig(properties);
|
||||||
bufferedReader.close();
|
bufferedReader.close();
|
||||||
fileReader.close();
|
fileReader.close();
|
||||||
|
|
|
@ -54,7 +54,6 @@ public class FileHandlerService {
|
||||||
private final Logger logger = LoggerFactory.getLogger(FileHandlerService.class);
|
private final Logger logger = LoggerFactory.getLogger(FileHandlerService.class);
|
||||||
private final String fileDir = ConfigConstants.getFileDir();
|
private final String fileDir = ConfigConstants.getFileDir();
|
||||||
private final CacheService cacheService;
|
private final CacheService cacheService;
|
||||||
private final InterruptionTokenSource source = new com.aspose.cad.InterruptionTokenSource(); //CAD延时
|
|
||||||
@Value("${server.tomcat.uri-encoding:UTF-8}")
|
@Value("${server.tomcat.uri-encoding:UTF-8}")
|
||||||
private String uriEncoding;
|
private String uriEncoding;
|
||||||
|
|
||||||
|
@ -148,7 +147,7 @@ public class FileHandlerService {
|
||||||
/**
|
/**
|
||||||
cad定义线程池
|
cad定义线程池
|
||||||
*/
|
*/
|
||||||
private static final ExecutorService pool = Executors.newFixedThreadPool(1);
|
private static final ExecutorService pool = Executors.newFixedThreadPool(ConfigConstants.getCadThread());
|
||||||
/**
|
/**
|
||||||
* 对转换后的文件进行操作(改变编码方式)
|
* 对转换后的文件进行操作(改变编码方式)
|
||||||
*
|
*
|
||||||
|
@ -304,6 +303,7 @@ public class FileHandlerService {
|
||||||
* @return 转换是否成功
|
* @return 转换是否成功
|
||||||
*/
|
*/
|
||||||
public String cadToPdf(String inputFilePath, String outputFilePath ,String cadPreviewType) throws Exception {
|
public String cadToPdf(String inputFilePath, String outputFilePath ,String cadPreviewType) throws Exception {
|
||||||
|
final InterruptionTokenSource source = new InterruptionTokenSource();//CAD延时
|
||||||
Callable<String> call = () -> {
|
Callable<String> call = () -> {
|
||||||
File outputFile = new File(outputFilePath);
|
File outputFile = new File(outputFilePath);
|
||||||
LoadOptions opts = new LoadOptions();
|
LoadOptions opts = new LoadOptions();
|
||||||
|
@ -336,9 +336,7 @@ public class FileHandlerService {
|
||||||
TiffOptions.setInterruptionToken(source.getToken());
|
TiffOptions.setInterruptionToken(source.getToken());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
OutputStream stream = null;
|
try (OutputStream stream = new FileOutputStream(outputFile)) {
|
||||||
try {
|
|
||||||
stream = new FileOutputStream(outputFile);
|
|
||||||
switch (cadPreviewType) {
|
switch (cadPreviewType) {
|
||||||
case "svg":
|
case "svg":
|
||||||
cadImage.save(stream, SvgOptions);
|
cadImage.save(stream, SvgOptions);
|
||||||
|
@ -352,34 +350,30 @@ public class FileHandlerService {
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("PDFFileNotFoundException,inputFilePath:{}", inputFilePath, e);
|
logger.error("PDFFileNotFoundException,inputFilePath:{}", inputFilePath, e);
|
||||||
return "null";
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
if (stream != null) { //关闭
|
//关闭
|
||||||
stream.close();
|
|
||||||
}
|
|
||||||
if (cadImage != null) { //关闭
|
if (cadImage != null) { //关闭
|
||||||
cadImage.close();
|
cadImage.dispose();
|
||||||
}
|
}
|
||||||
source.interrupt(); //结束任务
|
source.interrupt(); //结束任务
|
||||||
source.dispose();
|
|
||||||
}
|
}
|
||||||
return "true";
|
return "true";
|
||||||
};
|
};
|
||||||
Future<String> result = pool.submit(call);
|
Future<String> result = pool.submit(call);
|
||||||
try {
|
try {
|
||||||
// 如果在超时时间内,没有数据返回:则抛出TimeoutException异常
|
// 如果在超时时间内,没有数据返回:则抛出TimeoutException异常
|
||||||
result.get(60, TimeUnit.SECONDS);
|
result.get(Long.parseLong(ConfigConstants.getCadTimeout()), TimeUnit.SECONDS);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
System.out.println("InterruptedException发生");
|
System.out.println("InterruptedException发生");
|
||||||
return "null";
|
return null;
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
System.out.println("ExecutionException发生");
|
System.out.println("ExecutionException发生");
|
||||||
return "null";
|
return null;
|
||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
System.out.println("TimeoutException发生,意味着线程超时报错");
|
System.out.println("TimeoutException发生,意味着线程超时报错");
|
||||||
return "null";
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
source.interrupt(); //结束任务
|
|
||||||
source.dispose();
|
source.dispose();
|
||||||
}
|
}
|
||||||
return "true";
|
return "true";
|
||||||
|
|
Loading…
Reference in New Issue