make sure to process shape's parent drawing only once.
*/
package org.apache.tika.parser.microsoft.ooxml;
-import javax.xml.parsers.SAXParser;
+
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.hssf.extractor.ExcelExtractor;
@@ -253,6 +255,12 @@ public class XSSFExcelExtractorDecorator extends AbstractOOXMLExtractor {
if (shapes == null) {
return;
}
+ //We don't currently have an obvious way to get drawings
+ //directly from sheetIter. Therefore, we grab the shapes and process those.
+ //To get the diagrams and charts, we need to get the parent drawing for each
+ //shape, and we need to make sure that we only process each parent shape once!
+ //SEE TIKA-2703 TODO: add unit test
+ Set<String> seenParentDrawings = new HashSet<>();
for (XSSFShape shape : shapes) {
if (shape instanceof XSSFSimpleShape) {
String sText = ((XSSFSimpleShape) shape).getText();
@@ -261,13 +269,15 @@ public class XSSFExcelExtractorDecorator extends AbstractOOXMLExtractor {
}
extractHyperLinksFromShape(((XSSFSimpleShape)shape).getCTShape(), xhtml);
}
- XSSFDrawing drawing = shape.getDrawing();
- if (drawing != null) {
+
+ XSSFDrawing parentDrawing = shape.getDrawing();
+ if (parentDrawing != null) {
+ if (! seenParentDrawings.contains(parentDrawing.getPackagePart().getPartName().toString())) {
//dump diagram data
handleGeneralTextContainingPart(
AbstractOOXMLExtractor.RELATION_DIAGRAM_DATA,
"diagram-data",
- drawing.getPackagePart(),
+ parentDrawing.getPackagePart(),
metadata,
new OOXMLWordAndPowerPointTextHandler(
new OOXMLTikaBodyPartHandler(xhtml),
@@ -278,7 +288,7 @@ public class XSSFExcelExtractorDecorator extends AbstractOOXMLExtractor {
handleGeneralTextContainingPart(
XSSFRelation.CHART.getRelation(),
"chart",
- drawing.getPackagePart(),
+ parentDrawing.getPackagePart(),
metadata,
new OOXMLWordAndPowerPointTextHandler(
new OOXMLTikaBodyPartHandler(xhtml),
@@ -286,6 +296,8 @@ public class XSSFExcelExtractorDecorator extends AbstractOOXMLExtractor {
)
);
}
+ seenParentDrawings.add(parentDrawing.getPackagePart().getPartName().toString());
+ }
}
}
