From 0257c23caefcc5effa14b36a335ee478a15bafc7 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sun, 18 Jan 2015 23:46:29 +0000 Subject: [PATCH] Have ExtractorFactory open OPCPackages from files in read-only mode by default, since writing should never be needed when extracting text git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1652877 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/extractor/ExtractorFactory.java | 3 ++- .../poi/xssf/extractor/XSSFExcelExtractor.java | 16 +++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java b/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java index fa3b03882..65d1e3d69 100644 --- a/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java +++ b/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java @@ -44,6 +44,7 @@ import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.OPCPackage; +import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationshipCollection; import org.apache.poi.poifs.filesystem.DirectoryEntry; @@ -131,7 +132,7 @@ public class ExtractorFactory { return createExtractor(new POIFSFileSystem(inp)); } if(POIXMLDocument.hasOOXMLHeader(inp)) { - return createExtractor(OPCPackage.open(f.toString())); + return createExtractor(OPCPackage.open(f.toString(), PackageAccess.READ)); } throw new IllegalArgumentException("Your File was neither an OLE2 file, nor an OOXML file"); } finally { diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java index ba3844ae0..6f43ba126 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java @@ -195,13 +195,15 @@ public class XSSFExcelExtractor extends POIXMLTextExtractor // add textboxes if (includeTextBoxes){ - XSSFDrawing drawing = sheet.createDrawingPatriarch(); - for (XSSFShape shape : drawing.getShapes()){ - if (shape instanceof XSSFSimpleShape){ - String boxText = ((XSSFSimpleShape)shape).getText(); - if (boxText.length() > 0){ - text.append(boxText); - text.append('\n'); + XSSFDrawing drawing = sheet.getDrawingPatriarch(); + if (drawing != null) { + for (XSSFShape shape : drawing.getShapes()){ + if (shape instanceof XSSFSimpleShape){ + String boxText = ((XSSFSimpleShape)shape).getText(); + if (boxText.length() > 0){ + text.append(boxText); + text.append('\n'); + } } } }