From: Andreas Beeker Date: Tue, 23 Mar 2021 23:58:47 +0000 (+0000) Subject: add more xsbs to the ooxml-lite jar by recursing through XWPF and XSSF documents X-Git-Tag: REL_5_1_0~293 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7c6e80e9036d55382d87feda7cee9d5110c7df7c;p=poi.git add more xsbs to the ooxml-lite jar by recursing through XWPF and XSSF documents git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1887978 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/integrationtest/org/apache/poi/stress/POIXMLDocumentHandler.java b/src/integrationtest/org/apache/poi/stress/POIXMLDocumentHandler.java index a06b315d6e..930c904a77 100644 --- a/src/integrationtest/org/apache/poi/stress/POIXMLDocumentHandler.java +++ b/src/integrationtest/org/apache/poi/stress/POIXMLDocumentHandler.java @@ -25,6 +25,8 @@ import org.apache.poi.ooxml.POIXMLDocument; import org.apache.poi.poifs.crypt.Decryptor; import org.apache.poi.poifs.filesystem.FileMagic; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlObject; public final class POIXMLDocumentHandler { protected void handlePOIXMLDocument(POIXMLDocument doc) throws Exception { @@ -46,4 +48,25 @@ public final class POIXMLDocumentHandler { } return false; } + + /** + * Recurse through the document and convert all elements so they are available in the ooxml-lite jar. + * This method only makes sense for hierarchical documents like .docx. + * If the document is split up in different parts like in .pptx, each part needs to be provided. + * + * @param base the entry point + */ + protected static void cursorRecursive(XmlObject base) { + XmlCursor cur = base.newCursor(); + try { + if (!cur.toFirstChild()) { + return; + } + do { + cursorRecursive(cur.getObject()); + } while (cur.toNextSibling()); + } finally { + cur.dispose(); + } + } } diff --git a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java index 68f07b55be..def8750c84 100644 --- a/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java +++ b/src/integrationtest/org/apache/poi/stress/XSSFFileHandler.java @@ -48,11 +48,13 @@ import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.poifs.crypt.Decryptor; import org.apache.poi.poifs.crypt.EncryptionInfo; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.util.IOUtils; import org.apache.poi.util.NullPrintStream; import org.apache.poi.xssf.eventusermodel.XSSFReader; import org.apache.poi.xssf.extractor.XSSFExportToXml; import org.apache.poi.xssf.usermodel.XSSFMap; +import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; @@ -106,6 +108,11 @@ class XSSFFileHandler extends SpreadsheetHandler { // also verify general POIFS-stuff new POIXMLDocumentHandler().handlePOIXMLDocument(wb); + POIXMLDocumentHandler.cursorRecursive(wb.getCTWorkbook()); + for (Sheet sh : wb) { + POIXMLDocumentHandler.cursorRecursive(((XSSFSheet)sh).getCTWorksheet()); + } + // and finally ensure that exporting to XML works exportToXML(wb); diff --git a/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java b/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java index b5a497a388..0970d4fa1a 100644 --- a/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java +++ b/src/integrationtest/org/apache/poi/stress/XWPFFileHandler.java @@ -34,6 +34,7 @@ class XWPFFileHandler extends AbstractFileHandler { try (XWPFDocument doc = new XWPFDocument(stream)) { new POIXMLDocumentHandler().handlePOIXMLDocument(doc); + POIXMLDocumentHandler.cursorRecursive(doc.getDocument()); } catch (POIXMLException e) { Exception cause = (Exception)e.getCause(); throw cause == null ? e : cause; diff --git a/src/multimodule/ooxml-lite/java9/module-info.class b/src/multimodule/ooxml-lite/java9/module-info.class index 2a720c718d..6c12f9f957 100644 Binary files a/src/multimodule/ooxml-lite/java9/module-info.class and b/src/multimodule/ooxml-lite/java9/module-info.class differ diff --git a/src/multimodule/ooxml-lite/java9/module-info.java b/src/multimodule/ooxml-lite/java9/module-info.java index 2559d369d8..f8e193e41e 100644 --- a/src/multimodule/ooxml-lite/java9/module-info.java +++ b/src/multimodule/ooxml-lite/java9/module-info.java @@ -29,6 +29,7 @@ open module org.apache.poi.ooxml.schemas { exports com.microsoft.schemas.office.excel; exports com.microsoft.schemas.office.office; exports com.microsoft.schemas.office.visio.x2012.main; + exports com.microsoft.schemas.office.word; exports com.microsoft.schemas.office.x2006.digsig; exports com.microsoft.schemas.vml; exports org.apache.poi.schemas.ooxml.system.ooxml;