From: Tim Allison Date: Thu, 1 Nov 2018 21:14:03 +0000 (+0000) Subject: bug 60316 -- until we can implement it properly, gracefully skip the glossary documen... X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1cd3f7b14e0906283684038dad0617a66addc1fc;p=poi.git bug 60316 -- until we can implement it properly, gracefully skip the glossary document in XWPF. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1845517 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java b/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java index 5a368c576a..54fa790eca 100644 --- a/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java +++ b/src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java @@ -42,6 +42,7 @@ import org.apache.poi.util.POILogger; import org.apache.poi.xddf.usermodel.chart.XDDFChart; import org.apache.poi.xssf.usermodel.XSSFRelation; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.poi.xwpf.usermodel.XWPFRelation; /** * Represents an entry of a OOXML package. @@ -613,6 +614,14 @@ public class POIXMLDocumentPart { */ protected void read(POIXMLFactory factory, Map context) throws OpenXML4JException { PackagePart pp = getPackagePart(); + + if (pp.getContentType().equals(XWPFRelation.TEMPLATE.getContentType())) { + logger.log(POILogger.WARN, + "POI does not currently support template.main+xml (glossary) parts. " + + "Skipping this part for now."); + return; + } + // add mapping a second time, in case of initial caller hasn't done so POIXMLDocumentPart otherChild = context.put(pp, this); if (otherChild != null && otherChild != this) { diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java index d51750e922..0fcccd1838 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java @@ -29,6 +29,7 @@ import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.usermodel.XWPFDocument; import static org.apache.poi.POITestCase.assertContains; import static org.apache.poi.POITestCase.assertEndsWith; +import static org.apache.poi.POITestCase.assertNotContained; import static org.apache.poi.POITestCase.assertStartsWith; /** @@ -441,4 +442,14 @@ public class TestXWPFWordExtractor extends TestCase { assertContains(txt, "Sequencing data"); extractor.close(); } + + public void testGlossary() throws IOException { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("60316.dotx"); + XWPFWordExtractor extractor = new XWPFWordExtractor(doc); + String txt = extractor.getText(); + assertContains(txt, "Getting the perfect"); + //this content appears only in the glossary document + //once we add processing for this, we can change this to contains + assertNotContained(txt, "table rows"); + } } diff --git a/test-data/document/60316.dotx b/test-data/document/60316.dotx new file mode 100644 index 0000000000..5d24a7848c Binary files /dev/null and b/test-data/document/60316.dotx differ