git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1887978 13f79535-47bb-0310-9956-ffa450edef68tags/REL_5_1_0
@@ -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(); | |||
} | |||
} | |||
} |
@@ -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); | |||
@@ -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; |
@@ -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; |