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
This commit is contained in:
Nick Burch 2015-01-18 23:46:29 +00:00
parent bcb02aa4bc
commit cef16bab94
2 changed files with 11 additions and 8 deletions

View File

@ -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 {

View File

@ -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');
}
}
}
}