流程手册、表单手册,手册生成、下载、预览时检测是否为xml(外表是doc,其实是xml),若是则转换为真正的doc格式,解决QQ浏览器打开xml格式的word乱码问题

This commit is contained in:
446052889@qq.com 2023-09-15 15:59:41 +08:00
parent 7a7ec7ef04
commit 65069648a6
9 changed files with 68 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import com.actionsoft.apps.coe.pal.constant.CoEConstant;
import com.actionsoft.apps.coe.pal.log.CoEOpLogAPI;
import com.actionsoft.apps.coe.pal.log.CoEOpLogConst;
import com.actionsoft.apps.coe.pal.pal.output.OutputAPIManager;
import com.actionsoft.apps.coe.pal.pal.output.util.OutputWordUtil;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.server.fs.AbstFileProcessor;
@ -36,6 +37,7 @@ public class OutputDCFileProcessor extends AbstFileProcessor implements FileProc
*/
public static String getReportDownloadURL(String wsId, String id, String profileId, UserContext _uc, String taskName) throws Exception {
UtilFile file = OutputAPIManager.getInstance().getFilePath(wsId, id, profileId);
OutputWordUtil.xml2Word(null, file.getPath());
if (file.exists()) {
//String josnStr = OutputAPIManager.getInstance().getWizardJsonData(wsId, id, profileId);
// JSONObject jsonObj = JSONObject.fromObject(josnStr);
@ -66,6 +68,7 @@ public class OutputDCFileProcessor extends AbstFileProcessor implements FileProc
*/
public static String doPreviewReport(String wsId, String id, String profileId, UserContext _uc) throws Exception {
UtilFile file = OutputAPIManager.getInstance().getFilePath(wsId, id, profileId);
OutputWordUtil.xml2Word(null, file.getPath());
ResponseObject result = ResponseObject.newOkResponse();
if (file.exists()) {
File[] fileList = file.listFiles();

View File

@ -103,7 +103,9 @@ public class Report1Gener {
log.info("begin...");
log.info("-------------------");
// ----文件处理-----
genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj);
genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj);
// xml转换成word格式
OutputWordUtil.xml2Word(log, dcContext.getPath());
log.info("end");
// }
} finally {

View File

@ -95,6 +95,8 @@ public class Report2Gener {
log.info("-------------------");
// ----文件处理-----
genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj);
// xml转换成word格式
OutputWordUtil.xml2Word(log, dcContext.getPath());
log.info("end");
}
} finally {

View File

@ -4,6 +4,7 @@ import com.actionsoft.apps.coe.pal.constant.CoEConstant;
import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodCache;
import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodAttributeModel;
import com.actionsoft.apps.coe.pal.pal.method.model.PALMethodModel;
import com.actionsoft.apps.coe.pal.pal.output.extend.GenerLogExd;
import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager;
import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache;
import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.cache.DesignerShapeRelationCache;
@ -47,6 +48,7 @@ import org.apache.commons.lang.StringUtils;
import java.awt.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.List;
import java.util.*;
@ -2238,4 +2240,57 @@ public class OutputWordUtil {
}
return versionHistoryTable;
}
/**
* xml转换成word找doc文件执行转换
* @param log
* @param fileDirPath
*/
public static void xml2Word(GenerLogExd log, String fileDirPath) {
File dir = new File(fileDirPath);
if (dir.exists() && dir.isDirectory()) {
File [] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.isFile() && file.getName().toLowerCase().endsWith(".doc")) {
xml2Word(log, fileDirPath, file.getName());
}
}
}
}
/**
* xml转换成word
* @param filePath
* @param fileName
*/
public static void xml2Word(GenerLogExd log, String filePath, String fileName) {
boolean record = log != null;
File file = new File(filePath, fileName);
if (file.exists() && isXML(file.getPath())) {
Document document = new Document();
document.loadFromFile(file.getPath());
document.saveToFile(file.getPath(), FileFormat.Doc);
if (record) {
log.info("文件从XML格式转换成Doc格式");
}
} else {
if (record) {
log.info("文件不存在或者文件不是XML格式无需转换成Doc格式");
}
}
}
public static boolean isXML(String filePath) {
try (FileInputStream fis = new FileInputStream(filePath)) {
byte[] buffer = new byte[50]; // 假设我们读取前50个字节进行检测
int bytesRead = fis.read(buffer);
String startOfFile = new String(buffer, 0, bytesRead, StandardCharsets.UTF_8);
// 使用正则表达式来处理可能出现的前导空白字符
return startOfFile.trim().startsWith("<?xml");
} catch (IOException e) {
return false;
}
}
}

View File

@ -9,6 +9,7 @@ import com.actionsoft.apps.coe.pal.constant.CoEConstant;
import com.actionsoft.apps.coe.pal.log.CoEOpLogAPI;
import com.actionsoft.apps.coe.pal.log.CoEOpLogConst;
import com.actionsoft.apps.coe.pal.pal.output.OutputAPIManager;
import com.actionsoft.apps.coe.pal.pal.output.util.OutputWordUtil;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.server.fs.AbstFileProcessor;
@ -36,6 +37,7 @@ public class OutputDCFileProcessor extends AbstFileProcessor implements FileProc
*/
public static String getReportDownloadURL(String wsId, String id, String profileId, UserContext _uc, String taskName) throws Exception {
UtilFile file = OutputAPIManager.getInstance().getFilePath(wsId, id, profileId);
OutputWordUtil.xml2Word(null, file.getPath());
if (file.exists()) {
//String josnStr = OutputAPIManager.getInstance().getWizardJsonData(wsId, id, profileId);
// JSONObject jsonObj = JSONObject.fromObject(josnStr);
@ -66,6 +68,7 @@ public class OutputDCFileProcessor extends AbstFileProcessor implements FileProc
*/
public static String doPreviewReport(String wsId, String id, String profileId, UserContext _uc) throws Exception {
UtilFile file = OutputAPIManager.getInstance().getFilePath(wsId, id, profileId);
OutputWordUtil.xml2Word(null, file.getPath());
ResponseObject result = ResponseObject.newOkResponse();
if (file.exists()) {
File[] fileList = file.listFiles();

View File

@ -97,6 +97,8 @@ public class Report1Gener {
log.info("-------------------");
// ----文件处理-----
genarateWord(tempPath, tempName, dcContext.getPath(), jsonObj);
// xml转换成word格式
OutputWordUtil.xml2Word(log, dcContext.getPath());
log.info("end");
// }
} catch (FileNotFoundException e) {