]> source.dussan.org Git - poi.git/commitdiff
bug 60316 -- until we can implement it properly, gracefully skip the glossary documen...
authorTim Allison <tallison@apache.org>
Thu, 1 Nov 2018 21:14:03 +0000 (21:14 +0000)
committerTim Allison <tallison@apache.org>
Thu, 1 Nov 2018 21:14:03 +0000 (21:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1845517 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/ooxml/POIXMLDocumentPart.java
src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
test-data/document/60316.dotx [new file with mode: 0644]

index 5a368c576a0fbbf3f99b3cbec50e1662424568ec..54fa790eca51def01cd73ecf34946c287e3985ec 100644 (file)
@@ -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<PackagePart, POIXMLDocumentPart> 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) {
index d51750e9223e40fd24f162de3258275a717b1f09..0fcccd1838bacdeb287c3ea945878f0fa394806e 100644 (file)
@@ -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 (file)
index 0000000..5d24a78
Binary files /dev/null and b/test-data/document/60316.dotx differ