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
This commit is contained in:
Tim Allison 2018-11-01 21:14:03 +00:00
parent 5416787da5
commit 341f456ef7
3 changed files with 20 additions and 0 deletions

View 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) {

View 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");
}
}

Binary file not shown.