From 364c2a7a40a117a8d5a02f50f388823719ddb3e6 Mon Sep 17 00:00:00 2001 From: chily Date: Sun, 3 Apr 2022 21:43:13 +0800 Subject: [PATCH] =?UTF-8?q?issue=20#2054:=20=E5=9C=A8Android=E4=B8=8A?= =?UTF-8?q?=E8=B7=B3=E8=BF=87http://apache.org/xml/features/disallow-docty?= =?UTF-8?q?pe-decl=E7=9A=84=E9=99=90=E5=88=B6.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../excel/analysis/v07/XlsxSaxAnalyser.java | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 3aa5fa65..7216f636 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.alibaba easyexcel - 3.0.5 + 3.0.6 jar easyexcel diff --git a/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java b/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java index ea8b87b1..5204edf2 100644 --- a/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java +++ b/src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java @@ -41,10 +41,7 @@ import org.apache.poi.xssf.usermodel.XSSFRelation; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr; import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument; -import org.xml.sax.ContentHandler; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; +import org.xml.sax.*; /** * @author jipengfei @@ -188,7 +185,16 @@ public class XlsxSaxAnalyser implements ExcelReadExecutor { } else { saxFactory = SAXParserFactory.newInstance(xlsxSAXParserFactoryName, null); } - saxFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + + try { + saxFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + } catch (SAXNotRecognizedException e) { + log.warn( + "SAXNotRecognizedException occur, not supported feature: " + + "http://apache.org/xml/features/disallow-doctype-decl, which will disable DOCTYPE declaration" + + " if set true."); + } + saxFactory.setFeature("http://xml.org/sax/features/external-general-entities", false); saxFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false); SAXParser saxParser = saxFactory.newSAXParser();