/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* cn.hutool.core.io.FileUtil
* cn.hutool.core.util.ArrayUtil
* com.alibaba.fastjson.JSONObject
* com.alibaba.fastjson2.JSON
* com.jby.common.exceptions.BizAssert
* com.jby.common.exceptions.BusinessException
* com.jby.common.feign.FeignUtils
* com.jby.common.result.Result
* com.jby.common.util.CloseIoUtil
* com.jby.common.util.FileUtil
* com.jby.common.util.HttpClientUtil
* com.jby.common.util.SpringContextHolder
* com.jby.common.util.UniqueUtil
* com.jby.office.constant.Constants
* com.jby.office.domain.param.OfficeFileParseRecordParam
* com.jby.office.domain.vo.OfficeFileParseRecordVO
* com.jby.oss.domain.param.OssParam
* com.jby.system.enums.AttachmentModuleEnum
* javax.annotation.Nullable
* javax.xml.bind.JAXBElement
* org.apache.commons.collections4.CollectionUtils
* org.apache.commons.collections4.MapUtils
* org.apache.commons.io.FilenameUtils
* org.apache.commons.lang3.StringUtils
* org.apache.poi.ooxml.POIXMLDocumentPart
* org.apache.poi.openxml4j.util.ZipSecureFile
* org.apache.poi.xwpf.usermodel.XWPFDocument
* org.apache.poi.xwpf.usermodel.XWPFParagraph
* org.apache.poi.xwpf.usermodel.XWPFPictureData
* org.apache.xmlbeans.XmlException
* org.apache.xmlbeans.XmlObject
* org.docx4j.Docx4J
* org.docx4j.TextUtils
* org.docx4j.TraversalUtil
* org.docx4j.TraversalUtil$Callback
* org.docx4j.XmlUtils
* org.docx4j.convert.out.HTMLSettings
* org.docx4j.model.listnumbering.ListNumberingDefinition
* org.docx4j.openpackaging.packages.OpcPackage
* org.docx4j.openpackaging.packages.WordprocessingMLPackage
* org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart
* org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart
* org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart
* org.docx4j.wml.Body
* org.docx4j.wml.Document
* org.docx4j.wml.Lvl$LvlText
* org.docx4j.wml.P
* org.jsoup.Jsoup
* org.jsoup.nodes.Document
* org.jsoup.nodes.Element
* org.jsoup.nodes.Node
* org.jsoup.nodes.TextNode
* org.jsoup.select.Elements
* org.openxmlformats.schemas.officeDocument.x2006.math.CTOMath
* org.openxmlformats.schemas.officeDocument.x2006.math.CTOMathPara
* org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP
* org.slf4j.Logger
* org.slf4j.LoggerFactory
* org.springframework.beans.BeansException
* org.springframework.beans.factory.annotation.Autowired
* org.springframework.context.ApplicationContext
* org.springframework.context.ApplicationContextAware
* org.springframework.stereotype.Component
* org.springframework.util.StopWatch
* org.springframework.util.StopWatch$TaskInfo
* org.springframework.web.multipart.MultipartFile
*/
package com.jby.officecore.utils;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ArrayUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.jby.common.exceptions.BizAssert;
import com.jby.common.exceptions.BusinessException;
import com.jby.common.feign.FeignUtils;
import com.jby.common.result.Result;
import com.jby.common.util.CloseIoUtil;
import com.jby.common.util.HttpClientUtil;
import com.jby.common.util.SpringContextHolder;
import com.jby.common.util.UniqueUtil;
import com.jby.office.constant.Constants;
import com.jby.office.domain.param.OfficeFileParseRecordParam;
import com.jby.office.domain.vo.OfficeFileParseRecordVO;
import com.jby.officecore.config.OfficeCoreConfig;
import com.jby.officecore.domain.bo.ImageBO;
import com.jby.officecore.domain.bo.ParseBO;
import com.jby.officecore.domain.bo.TagStyleBO;
import com.jby.officecore.domain.param.ParseParam;
import com.jby.officecore.enums.AttrEnum;
import com.jby.officecore.enums.TagEnum;
import com.jby.officecore.feign.FileServiceFeign;
import com.jby.officecore.pool.OMml2MmlTransformerPool;
import com.jby.officecore.utils.DigestUtil;
import com.jby.officecore.utils.LatexUtil;
import com.jby.officecore.utils.MathTypeUtil;
import com.jby.officecore.utils.NumPr;
import com.jby.officecore.utils.OfficeFileUtil;
import com.jby.officecore.utils.OssServiceUtil;
import com.jby.officecore.utils.WordExportUtil;
import com.jby.officecore.utils.WpsConvertUtil;
import com.jby.officecore.utils.finder.CtObjectFinder;
import com.jby.officecore.utils.finder.CtTextBoxFinder;
import com.jby.officecore.utils.finder.CtoMathFinder;
import com.jby.officecore.utils.finder.DrawingPictFinder;
import com.jby.oss.domain.param.OssParam;
import com.jby.system.enums.AttachmentModuleEnum;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import javax.xml.bind.JAXBElement;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFPictureData;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.docx4j.Docx4J;
import org.docx4j.TextUtils;
import org.docx4j.TraversalUtil;
import org.docx4j.XmlUtils;
import org.docx4j.convert.out.HTMLSettings;
import org.docx4j.model.listnumbering.ListNumberingDefinition;
import org.docx4j.openpackaging.packages.OpcPackage;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.openpackaging.parts.WordprocessingML.NumberingDefinitionsPart;
import org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart;
import org.docx4j.wml.Body;
import org.docx4j.wml.Document;
import org.docx4j.wml.Lvl;
import org.docx4j.wml.P;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import org.openxmlformats.schemas.officeDocument.x2006.math.CTOMath;
import org.openxmlformats.schemas.officeDocument.x2006.math.CTOMathPara;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;
import org.springframework.web.multipart.MultipartFile;
@Component
public class WordParseUtil
implements ApplicationContextAware {
private static final Logger log = LoggerFactory.getLogger(WordParseUtil.class);
private static final String TEXT_PATTERN_STR = "^(?:\\s*[\u4e00-\u9fa2]{0,10}[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341]+(?:\u3001|\\s+).+)|(?:(?:[\u3010\u3016\\[])[\u4e00-\u9fa2]{2,20}(?:[\u3011\u3017\\]]))$";
private static final Pattern TEXT_PATTERN = Pattern.compile("^(?:\\s*[\u4e00-\u9fa2]{0,10}[\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341]+(?:\u3001|\\s+).+)|(?:(?:[\u3010\u3016\\[])[\u4e00-\u9fa2]{2,20}(?:[\u3011\u3017\\]]))$");
private static final String MATH_PLACEHOLDER = "%s";
private static final String[] SYMBOL = new String[]{"\\ue0fc", "\\ue100", "\\ue101"};
private static OfficeCoreConfig officeCoreConfig;
private static FileServiceFeign fileServiceFeign;
private static ApplicationContext applicationContext;
private static volatile Executor batchDealPicExecutor;
@Autowired
public void setOfficeCoreConfig(OfficeCoreConfig officeCoreConfig) {
WordParseUtil.officeCoreConfig = officeCoreConfig;
}
@Autowired
public void setFileServiceFeign(FileServiceFeign fileServiceFeign) {
WordParseUtil.fileServiceFeign = fileServiceFeign;
}
public void setApplicationContext(@Nullable ApplicationContext ctx) throws BeansException {
applicationContext = ctx;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
* Enabled force condition propagation
* Lifted jumps to return sites
*/
private static Executor getBatchDealPicExecutor() {
if (!Objects.isNull(batchDealPicExecutor)) return batchDealPicExecutor;
Class clazz = WordParseUtil.class;
synchronized (WordParseUtil.class) {
if (!Objects.isNull(batchDealPicExecutor)) return batchDealPicExecutor;
batchDealPicExecutor = (Executor)applicationContext.getBean("batchDealPicExecutor", Executor.class);
// ** MonitorExit[var0] (shouldn't be in output)
return batchDealPicExecutor;
}
}
public static String parseByUrl(ParseParam param) {
String fileUrl = param.getSourceUrl();
BizAssert.isNotBlank((String)fileUrl, (String)"\u6e90\u6587\u4ef6Url\u4e3a\u7a7a\uff01");
ParseBO parseBO = new ParseBO().setLatexReplaceList(param.getLatexReplaceList());
parseBO.setSourceFileUrl(fileUrl);
File sourceFile = null;
try {
WordParseUtil.createTempDir(parseBO);
String fileName = FileUtil.getName((String)fileUrl);
BizAssert.isNotBlank((String)fileName, (String)"\u6e90\u6587\u4ef6\u5730\u5740\u5f02\u5e38");
parseBO.setSourceFilePath(parseBO.getTempDir().resolve(fileName).toString());
com.jby.common.util.FileUtil.downloadNetworkFile((String)fileUrl, (String)parseBO.getSourceFilePath());
sourceFile = com.jby.common.util.FileUtil.getFile((String)parseBO.getSourceFilePath());
}
catch (Exception e) {
log.error("\u89e3\u6790\u5f02\u5e38, fileUrl:{}", (Object)fileUrl, (Object)e);
if (Objects.nonNull(parseBO.getTempDir())) {
FileUtil.del((Path)parseBO.getTempDir());
}
throw new BusinessException("\u89e3\u6790\u5f02\u5e38");
}
BizAssert.isTrue((sourceFile.length() != 0L ? 1 : 0) != 0, (String)"\u6587\u6863\u5185\u5bb9\u4e3a\u7a7a\uff01");
try {
WordParseUtil.checkSuffixAndSize(sourceFile, null);
String e = WordParseUtil.parse(parseBO);
return e;
}
catch (Exception e) {
log.error("\u89e3\u6790\u5f02\u5e38, fileUrl:{}", (Object)fileUrl, (Object)e);
throw new BusinessException("\u89e3\u6790\u5f02\u5e38");
}
finally {
if (Objects.nonNull(parseBO.getTempDir())) {
FileUtil.del((Path)parseBO.getTempDir());
}
}
}
public static String parseByFile(ParseParam param) {
MultipartFile file = param.getSourceFile();
WordParseUtil.checkSuffixAndSize(file, null);
ParseBO parseBO = new ParseBO().setLatexReplaceList(param.getLatexReplaceList()).setNewParseVersion(param.getNewParseVersion()).setFileId(param.getFileId());
try {
WordParseUtil.createTempDir(parseBO);
String fileName = file.getOriginalFilename();
BizAssert.isNotBlank((String)fileName, (String)"\u6e90\u6587\u4ef6\u5730\u5740\u5f02\u5e38");
assert (fileName != null);
parseBO.setSourceFilePath(parseBO.getTempDir().resolve(fileName).toString());
FileUtil.writeFromStream((InputStream)file.getInputStream(), (File)com.jby.common.util.FileUtil.getFile((String)parseBO.getSourceFilePath()));
String string = WordParseUtil.parse(parseBO);
return string;
}
catch (Exception e) {
log.error("\u89e3\u6790\u5f02\u5e38:{}", (Object)e.getMessage(), (Object)e);
throw new BusinessException("\u89e3\u6790\u5f02\u5e38");
}
finally {
if (Objects.nonNull(parseBO.getTempDir())) {
FileUtil.del((Path)parseBO.getTempDir());
}
}
}
public static String parse(ParseBO parseBO) {
String string;
String preHtml;
if (Boolean.TRUE.equals(officeCoreConfig.getNewParseVersion())) {
parseBO.setNewParseVersion(true);
}
String md5 = DigestUtil.getFileMd5(parseBO.getSourceFilePath());
BizAssert.isNotBlank((String)md5, (String)"\u8ba1\u7b97\u6e90\u6587\u4ef6md5\u5f02\u5e38\uff01");
parseBO.setSourceFileMd5(md5);
if (Boolean.TRUE.equals(officeCoreConfig.getOpenParseCache()) && StringUtils.isNotBlank((CharSequence)(preHtml = WordParseUtil.getFileParseResult(parseBO, md5)))) {
return preHtml;
}
if (StringUtils.isBlank((CharSequence)parseBO.getSourceFileUrl())) {
String sourceFileBakPath = parseBO.getSourceFilePath() + ".JBY_BAK";
com.jby.common.util.FileUtil.copyFile((String)parseBO.getSourceFilePath(), (String)sourceFileBakPath, (boolean)true);
parseBO.setSourceFileBakPath(sourceFileBakPath);
}
if (WordParseUtil.checkIsWps(parseBO)) {
String newSourceFilePath = WpsConvertUtil.convertFile(parseBO.getSourceFilePath(), parseBO.getTempDir().toString(), "docx", 5L);
if (StringUtils.isEmpty((CharSequence)newSourceFilePath)) {
throw new BusinessException("wps\u8f6cdocx\u5931\u8d25\uff01");
}
parseBO.setSourceFilePath(newSourceFilePath);
}
WordParseUtil.handleFormat(parseBO);
parseBO.setTransformer(OMml2MmlTransformerPool.INSTANCE.borrowObject());
FileOutputStream os = null;
try {
StopWatch sw = new StopWatch("\u89e3\u6790word");
ZipSecureFile.setMinInflateRatio((double)0.001);
sw.start("\u52a0\u8f7d\u6e90\u6587\u4ef6");
File sourceFile = com.jby.common.util.FileUtil.getFile((String)parseBO.getSourceFilePath());
WordprocessingMLPackage wordMlPackage = WordprocessingMLPackage.load((File)sourceFile);
sw.stop();
sw.start("\u81ea\u5b9a\u4e49\u89e3\u6790");
WordParseUtil.customParse(wordMlPackage, parseBO);
sw.stop();
sw.start("\u8f6c\u6362\u8bbe\u7f6e");
HTMLSettings htmlSettings = Docx4J.createHTMLSettings();
htmlSettings.setImageDirPath(parseBO.getImagesDir());
htmlSettings.setImageTargetUri("images");
htmlSettings.setOpcPackage((OpcPackage)wordMlPackage);
sw.stop();
sw.start("\u6267\u884c\u8f6c\u6362");
os = new FileOutputStream(new File(parseBO.getHtmlPath()));
Docx4J.toHTML((HTMLSettings)htmlSettings, (OutputStream)os, (int)1);
sw.stop();
sw.start("\u5904\u7406\u56fe\u7247\u4e0a\u4f20OSS\u53ca\u8f6csvg");
WordParseUtil.dealImg(parseBO);
sw.stop();
sw.start("\u5904\u7406\u6210\u5728\u7ebf\u6587\u6863\u652f\u6301\u7684html");
String html = new String(Files.readAllBytes(Paths.get(parseBO.getHtmlPath(), new String[0])), StandardCharsets.UTF_8);
html = WordParseUtil.customParseOfficeHtml(html, parseBO);
sw.stop();
WordParseUtil.saveParseResult(parseBO, html);
log.info(WordParseUtil.formatAsMillis(sw));
string = html;
}
catch (Exception e) {
try {
log.error("wordToHtml exception:{}", (Object)e.getMessage(), (Object)e);
throw new BusinessException("word\u89e3\u6790\u5f02\u5e38");
}
catch (Throwable throwable) {
CloseIoUtil.closeAll((Closeable[])new Closeable[]{os});
OMml2MmlTransformerPool.INSTANCE.returnObject(parseBO.getTransformer());
throw throwable;
}
}
CloseIoUtil.closeAll((Closeable[])new Closeable[]{os});
OMml2MmlTransformerPool.INSTANCE.returnObject(parseBO.getTransformer());
return string;
}
private static boolean checkIsWps(ParseBO parseBO) {
String sourceFilePath = parseBO.getSourceFilePath();
File file = new File(sourceFilePath);
String fileName = file.getName().toLowerCase();
String fileSuffix = com.jby.common.util.FileUtil.getFileSuffix((String)fileName);
return "wps".equals(fileSuffix);
}
private static String uploadFileToOss(File file, String module, String folderName, String fileName) {
return OssServiceUtil.uploadFile(new OssParam().setModule(module).setFolder(folderName).setFile(com.jby.common.util.FileUtil.getMultipartFile((String)fileName, (File)file)));
}
private static void customParse(WordprocessingMLPackage wordMlPackage, ParseBO parseBO) throws Exception {
NumberingDefinitionsPart numberingDefinitionsPart;
MainDocumentPart mainDocumentPart = wordMlPackage.getMainDocumentPart();
StyleDefinitionsPart styleDefinitionsPart = mainDocumentPart.getStyleDefinitionsPart();
if (Objects.nonNull(styleDefinitionsPart)) {
parseBO.setStyleDefinitionsPart(styleDefinitionsPart);
}
if (Objects.nonNull(numberingDefinitionsPart = mainDocumentPart.getNumberingDefinitionsPart())) {
HashMap numDefines = numberingDefinitionsPart.getInstanceListDefinitions();
parseBO.getNumberingDefinitionsMap().putAll(numDefines.entrySet().stream().flatMap(m1 -> ((ListNumberingDefinition)m1.getValue()).getAbstractListDefinition().getAbstractNumNode().getLvl().stream().filter(f -> Objects.nonNull(f.getStart())).map(m2 -> {
NumPr numPr = new NumPr();
numPr.setStart(m2.getStart().getVal());
numPr.setCurrent(numPr.getStart().subtract(BigInteger.ONE));
numPr.setNumFmt(Optional.ofNullable(m2.getNumFmt()).map(m -> m.getVal().toString()).orElse(""));
numPr.setLvlText(Optional.ofNullable(m2.getLvlText()).map(Lvl.LvlText::getVal).orElse(""));
return new AbstractMap.SimpleEntry((String)m1.getKey() + "_" + m2.getIlvl(), numPr);
})).collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)));
}
Body body = ((Document)mainDocumentPart.getJaxbElement()).getBody();
try {
CtObjectFinder ctObjectFinder = new CtObjectFinder(wordMlPackage, parseBO);
new TraversalUtil((Object)body.getContent(), (TraversalUtil.Callback)ctObjectFinder);
MathTypeUtil.mathTypeToMathMl(parseBO.getMathTypeMap());
if (Boolean.TRUE.equals(parseBO.getNewParseVersion())) {
parseBO.getMathTypeMap().values().forEach(m -> {
m = m.replace("JBYSIMJBY", "~");
});
LatexUtil.ommlMathMlToLatexIgnoreNull(parseBO.getMathTypeMap(), officeCoreConfig.getCopyrightAddresses(), parseBO.getTempDir());
} else {
LatexUtil.mathMlToLatexIgnoreNull(parseBO.getMathTypeMap(), officeCoreConfig.getCopyrightAddresses(), parseBO.getTempDir());
}
}
catch (Exception e) {
log.error("\u81ea\u5b9a\u4e49\u89e3\u6790MathType\u516c\u5f0f\u5f02\u5e38", (Throwable)e);
}
try {
DrawingPictFinder drawingPictFinder = new DrawingPictFinder(wordMlPackage, parseBO);
new TraversalUtil((Object)body.getContent(), (TraversalUtil.Callback)drawingPictFinder);
}
catch (Exception e) {
log.error("\u81ea\u5b9a\u4e49\u89e3\u6790\u56fe\u7247\u5f02\u5e38:{}", (Object)e.getMessage(), (Object)e);
}
try {
CtoMathFinder ctoMathFinder = new CtoMathFinder(parseBO);
new TraversalUtil((Object)body.getContent(), (TraversalUtil.Callback)ctoMathFinder);
if (Boolean.TRUE.equals(parseBO.getNewParseVersion())) {
LatexUtil.ommlAndMathMlToLatex(parseBO.getOpenOfficeXmlMap(), parseBO.getTempDir());
} else {
LatexUtil.mathMlToLatex(parseBO.getOpenOfficeXmlMap(), parseBO.getTempDir());
}
}
catch (Exception e) {
log.error("\u81ea\u5b9a\u4e49\u89e3\u6790\u5fae\u8f6f\u6216\u57df\u516c\u5f0f\u5f02\u5e38", (Throwable)e);
}
try {
CtTextBoxFinder ctTextBoxFinder = new CtTextBoxFinder(wordMlPackage, parseBO);
new TraversalUtil((Object)body.getContent(), (TraversalUtil.Callback)ctTextBoxFinder);
}
catch (Exception e) {
log.error("\u81ea\u5b9a\u4e49\u89e3\u6790\u6587\u672c\u6846\u5f02\u5e38", (Throwable)e);
}
for (Object object : body.getContent()) {
List contentList;
P p;
String pText;
if (!(object instanceof P) || !StringUtils.isNotBlank((CharSequence)(pText = TextUtils.getText((Object)(p = (P)object)))) || !pText.contains("JBY_TEXTBOX_JBY") || !CollectionUtils.isNotEmpty((Collection)(contentList = p.getContent()))) continue;
ArrayList matchedItems = new ArrayList();
ArrayList unmatchedItems = new ArrayList();
for (Object obj : contentList) {
if (TextUtils.getText(obj).contains("JBY_TEXTBOX_JBY")) {
matchedItems.add(obj);
continue;
}
unmatchedItems.add(obj);
}
contentList.clear();
contentList.addAll(unmatchedItems);
contentList.addAll(matchedItems);
}
}
private static void uploadImgToOss(ParseBO parseBO) {
File folder = new File(parseBO.getImagesDir());
if (!folder.exists() || !folder.isDirectory()) {
log.info("\u672c\u5730\u6587\u4ef6\u5939\u4e0d\u5b58\u5728\u6216\u4e0d\u662f\u4e00\u4e2a\u6587\u4ef6\u5939:{}", (Object)parseBO.getImagesDir());
return;
}
Object[] files = folder.listFiles();
if (ArrayUtil.isEmpty((Object[])files)) {
return;
}
HashMap tifFileNameMap = new HashMap();
for (Object file : files) {
String fileName;
String suffix;
if (!((File)file).isFile() || StringUtils.isBlank((CharSequence)(suffix = FileUtil.getSuffix((String)(fileName = ((File)file).getName())))) || !"tif".equals(suffix = suffix.toLowerCase()) && !"tiff".equals(suffix)) continue;
WordParseUtil.tifToPng((File)file);
String baseName = FilenameUtils.getBaseName((String)fileName);
tifFileNameMap.put(baseName + ".png", fileName);
}
files = folder.listFiles();
assert (files != null);
for (Object file : files) {
String suffix;
if (!((File)file).isFile() || StringUtils.isBlank((CharSequence)(suffix = FileUtil.getSuffix((String)((File)file).getName())))) continue;
if ("wmf".equals(suffix = suffix.toLowerCase()) || "emf".equals(suffix)) {
byte[] fileData = new byte[]{};
try {
fileData = Files.readAllBytes(((File)file).toPath());
}
catch (IOException e) {
log.error("\u89e3\u6790\u5f02\u5e38, fileUrl:{}", (Object)((File)file).toPath(), (Object)e);
throw new BusinessException("\u89e3\u6790\u5f02\u5e38");
}
String svgUrl = OfficeFileUtil.mf2svg(new ByteArrayInputStream(fileData), parseBO.getOssFolder(), ((File)file).getName());
String tifName = (String)tifFileNameMap.get(((File)file).getName());
String imgKey = "images/" + (StringUtils.isBlank((CharSequence)tifName) ? ((File)file).getName() : tifName);
parseBO.getImgMap().put(imgKey, svgUrl);
continue;
}
if ("tif".equals(suffix) || "tiff".equals(suffix)) continue;
String imgUrl = OssServiceUtil.uploadFile(new OssParam().setModule(AttachmentModuleEnum.OFFICE_IMG.getModule()).setFolder(parseBO.getOssFolder()).setFile(com.jby.common.util.FileUtil.getMultipartFile((String)((File)file).getName(), (File)file)));
String tifName = (String)tifFileNameMap.get(((File)file).getName());
String imgKey = "images/" + (StringUtils.isBlank((CharSequence)tifName) ? ((File)file).getName() : tifName);
parseBO.getImgMap().put(imgKey, imgUrl);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public static File tifToPng(File tiffFile) {
File file;
File pngFile;
BufferedImage image;
ImageInputStream imageInputStream;
FileInputStream is;
block6: {
is = null;
imageInputStream = null;
is = new FileInputStream(tiffFile);
imageInputStream = ImageIO.createImageInputStream(is);
Iterator readers = ImageIO.getImageReaders(imageInputStream);
if (!readers.hasNext()) {
throw new BusinessException("No suitable ImageReader found for " + tiffFile.getAbsolutePath());
}
ImageReader reader = readers.next();
reader.setInput(imageInputStream);
String baseName = FilenameUtils.getBaseName((String)tiffFile.getAbsolutePath());
String parentFolder = tiffFile.getParentFile().getAbsolutePath();
image = reader.read(0);
pngFile = new File(parentFolder, baseName + ".png");
if (image.getType() != 0 && image.getType() != 0) break block6;
boolean hasAlpha = image.getColorModel().hasAlpha();
int newType = hasAlpha ? 2 : 1;
BufferedImage convertedImage = new BufferedImage(image.getWidth(), image.getHeight(), newType);
Graphics2D graphics2D = convertedImage.createGraphics();
graphics2D.drawImage((Image)image, 0, 0, null);
graphics2D.dispose();
ImageIO.write((RenderedImage)convertedImage, "png", pngFile);
File file2 = pngFile;
CloseIoUtil.closeAll((Closeable[])new Closeable[]{imageInputStream, is});
return file2;
}
try {
ImageIO.write((RenderedImage)image, "png", pngFile);
file = pngFile;
}
catch (Exception e) {
File file3;
try {
log.error("tifToPng error:{}", (Object)e.getMessage(), (Object)e);
file3 = null;
}
catch (Throwable throwable) {
CloseIoUtil.closeAll((Closeable[])new Closeable[]{imageInputStream, is});
throw throwable;
}
CloseIoUtil.closeAll((Closeable[])new Closeable[]{imageInputStream, is});
return file3;
}
CloseIoUtil.closeAll((Closeable[])new Closeable[]{imageInputStream, is});
return file;
}
private static void customParse(XWPFDocument document, ParseBO parseBO) {
if (CollectionUtils.isEmpty((Collection)document.getParagraphs())) {
return;
}
for (XWPFParagraph paragraph : document.getParagraphs()) {
org.jsoup.nodes.Document pDocument = Jsoup.parse((String)paragraph.getCTP().xmlText());
boolean updateXml = false;
if (WordParseUtil.parseOpenOfficeXml(parseBO, paragraph, pDocument)) {
updateXml = true;
}
if (!updateXml) continue;
WordParseUtil.overrideParagraph(paragraph, pDocument);
}
LatexUtil.mathMlToLatex(parseBO.getOpenOfficeXmlMap(), parseBO.getTempDir());
}
private static boolean parseOpenOfficeXml(ParseBO parseBO, XWPFParagraph paragraph, org.jsoup.nodes.Document pDocument) {
boolean updateXml = false;
ArrayList placeholderList = new ArrayList();
for (CTOMathPara ctoMathPara : paragraph.getCTP().getOMathParaList()) {
for (CTOMath ctoMath : ctoMathPara.getOMathList()) {
String placeholder = parseBO.getOpenOfficeXmlPlaceholder();
parseBO.getOpenOfficeXmlMap().put(placeholder, WordParseUtil.getMathMl(ctoMath, parseBO.getTransformer()));
placeholderList.add(placeholder);
}
}
for (CTOMath ctoMath : paragraph.getCTP().getOMathList()) {
String placeholder = parseBO.getOpenOfficeXmlPlaceholder();
parseBO.getOpenOfficeXmlMap().put(placeholder, WordParseUtil.getMathMl(ctoMath, parseBO.getTransformer()));
placeholderList.add(placeholder);
}
Elements oMathElements = pDocument.getElementsByTag("m:oMath");
if (oMathElements.size() == placeholderList.size()) {
for (int i = 0; i < oMathElements.size(); ++i) {
Element element = (Element)oMathElements.get(i);
Element wr = new Element("w:r");
wr.append(String.format(MATH_PLACEHOLDER, placeholderList.get(i)));
element.replaceWith((Node)wr);
updateXml = true;
}
}
return updateXml;
}
private static boolean parseMathType(ParseBO parseBO, org.jsoup.nodes.Document pDocument) {
boolean updateXml = false;
Elements imageDataElements = pDocument.getElementsByTag("v:imagedata");
for (Element element : imageDataElements) {
String svgUrl = parseBO.getImgMap().get(element.attr("r:id"));
List styleList = TagEnum.getStyleList(element.parent());
Map styleMap = styleList.stream().collect(Collectors.toMap(TagStyleBO::getAttr, TagStyleBO::getValue, (l, r) -> l));
double width = WordExportUtil.getPtValue(styleMap.get(AttrEnum.WIDTH.getAttr()));
double height = WordExportUtil.getPtValue(styleMap.get(AttrEnum.HEIGHT.getAttr()));
if (!StringUtils.isNotBlank((CharSequence)svgUrl)) continue;
Element imgElement = new Element(TagEnum.IMG.getName());
imgElement.attr(AttrEnum.SRC.getAttr(), svgUrl);
imgElement.attr(AttrEnum.WIDTH.getAttr(), width + "pt");
imgElement.attr(AttrEnum.HEIGHT.getAttr(), height + "pt");
WordParseUtil.addImgAttr(imgElement);
String placeholder = parseBO.getMathTypePlaceholder();
parseBO.getMathTypeMap().put(placeholder, imgElement.outerHtml());
Element parent = element.parent().parent().parent();
Element wr = new Element("w:r");
wr.append(String.format(MATH_PLACEHOLDER, placeholder));
parent.replaceWith((Node)wr);
updateXml = true;
}
return updateXml;
}
private static void overrideParagraph(XWPFParagraph paragraph, org.jsoup.nodes.Document pDocument) {
String xml = pDocument.body().html();
try {
xml = xml.replace(" ", " ");
CTP ctp = (CTP)CTP.Factory.parse(xml);
paragraph.getCTP().set((XmlObject)ctp);
}
catch (XmlException e) {
log.error("\u91cd\u5199\u6bb5\u843d\u5f02\u5e38, xml:{}", (Object)xml, (Object)e);
}
}
public static String getMathMl(JAXBElement> ctoMathEle, Transformer transformer) {
String oml = XmlUtils.marshaltoString(ctoMathEle, (boolean)true, (boolean)false);
StringReader reader = new StringReader(oml);
StreamSource source = new StreamSource(reader);
return WordParseUtil.sourceToMathMl(source, transformer);
}
private static String getMathMl(CTOMath ctoMath, Transformer transformer) {
org.w3c.dom.Node node = ctoMath.getDomNode();
DOMSource source = new DOMSource(node);
return WordParseUtil.sourceToMathMl(source, transformer);
}
private static String sourceToMathMl(Source source, Transformer transformer) {
String mathMl;
StringWriter stringwriter = new StringWriter();
StreamResult result = new StreamResult(stringwriter);
try {
transformer.transform(source, result);
mathMl = stringwriter.toString();
stringwriter.close();
}
catch (Exception e) {
log.error("word\u5185\u516c\u5f0f\u89e3\u6790\u5f02\u5e38\uff1a" + e.getMessage(), (Throwable)e);
throw new BusinessException("\u516c\u5f0f\u89e3\u6790\u5f02\u5e38\uff01");
}
mathMl = mathMl.substring(mathMl.indexOf("=\"http://www.w3.org/1998/Math/MathML\""));
mathMl = "