https://bz.apache.org/bugzilla/show_bug.cgi?id=60316
Bug ID: 60316
Summary: When processing glossary components, we need to return
grandparent for getXWPFDocument
Product: POI
Version: 3.16-dev
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P2
Component: XWPF
Assignee: [email protected]
Reporter: [email protected]
On TIKA-2147 and TIKA-2149, Seva Alekseyev and Sharath Kumar shared two
documents that throw:
java.lang.ClassCastException: org.apache.poi.POIXMLDocumentPart cannot be cast
to org.apache.poi.xwpf.usermodel.XWPFDocument
at
org.apache.poi.xwpf.usermodel.XWPFFootnotes.getXWPFDocument(XWPFFootnotes.java:162)
at org.apache.poi.xwpf.usermodel.XWPFFootnote.<init>(XWPFFootnote.java:47)
at
org.apache.poi.xwpf.usermodel.XWPFFootnotes.onDocumentRead(XWPFFootnotes.java:95)
at
org.apache.poi.POIXMLDocumentPart._invokeOnDocumentRead(POIXMLDocumentPart.java:658)
at
org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(XWPFDocument.java:235)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:160)
at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:124)
at
org.apache.poi.xwpf.extractor.XWPFWordExtractor.<init>(XWPFWordExtractor.java:58)
at
org.apache.poi.extractor.ExtractorFactory.createExtractor(ExtractorFactory.java:237)
at
org.apache.tika.parser.microsoft.ooxml.OOXMLExtractorFactory.parse(OOXMLExtractorFactory.java:86)
I think the issue is that the because the footnotes are within a glossary, when
we call getXWPFDocument(), we're invoking .getParent() which gets the
POIXMLDocumentPart. If we get the grandparent in this case, we actually get
the XWPFDocument.
I propose something along these lines:
public XWPFDocument getXWPFDocument() {
if (document != null) {
return document;
} else {
Object parent = getParent();
if (parent != null) {
if (parent instanceof XWPFDocument) {
return (XWPFDocument)parent;
} else if (parent instanceof POIXMLDocumentPart) {
Object grandParent = ((POIXMLDocumentPart)
parent).getParent();
if (grandParent instanceof XWPFDocument) {
return (XWPFDocument) grandParent;
}
}
}
throw new IllegalStateException("couldn't find the parent");
}
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]