]> source.dussan.org Git - poi.git/commitdiff
Refactor out the POIFS directory entry name for Excel 1-95 entries, and have Extracto...
authorNick Burch <nick@apache.org>
Fri, 26 Feb 2016 23:43:59 +0000 (23:43 +0000)
committerNick Burch <nick@apache.org>
Fri, 26 Feb 2016 23:43:59 +0000 (23:43 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1732583 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
src/java/org/apache/poi/hssf/model/InternalWorkbook.java
src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java

index 9dc89c8116a01734d3490f3e97fc5a55529125d3..66c9d4a7c3e4cac82965b0dfce3899427fb92ce8 100644 (file)
@@ -17,6 +17,9 @@
 
 package org.apache.poi.hssf.extractor;
 
+import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES;
+import static org.apache.poi.hssf.model.InternalWorkbook.OLD_WORKBOOK_DIR_ENTRY_NAME;
+
 import java.io.BufferedInputStream;
 import java.io.Closeable;
 import java.io.File;
@@ -99,10 +102,10 @@ public class OldExcelExtractor implements Closeable {
     private void open(DirectoryNode directory) throws IOException {
         DocumentNode book;
         try {
-            book = (DocumentNode)directory.getEntry("Book");
+            book = (DocumentNode)directory.getEntry(OLD_WORKBOOK_DIR_ENTRY_NAME);
         } catch (FileNotFoundException e) {
             // some files have "Workbook" instead
-            book = (DocumentNode)directory.getEntry("Workbook");
+            book = (DocumentNode)directory.getEntry(WORKBOOK_DIR_ENTRY_NAMES[0]);
         }
 
         if (book == null) {
index b932836cb65c2d9c553169d1d42ea430ef481d2c..0b11818fdf68448926fe4e92ea7db63ffbe1ee26 100644 (file)
@@ -37,6 +37,7 @@ import org.apache.poi.ddf.EscherRecord;
 import org.apache.poi.ddf.EscherSimpleProperty;
 import org.apache.poi.ddf.EscherSpRecord;
 import org.apache.poi.ddf.EscherSplitMenuColorsRecord;
+import org.apache.poi.hssf.extractor.OldExcelExtractor;
 import org.apache.poi.hssf.record.BOFRecord;
 import org.apache.poi.hssf.record.BackupRecord;
 import org.apache.poi.hssf.record.BookBoolRecord;
@@ -133,6 +134,12 @@ public final class InternalWorkbook {
         "WORKBOOK", // Typically from third party programs
         "BOOK",     // Typically odd Crystal Reports exports
     };
+    /**
+     * Name of older (pre-Excel 97) Workbook streams, which
+     *  aren't supported by HSSFWorkbook, only by
+     *  {@link OldExcelExtractor}
+     */
+    public static final String OLD_WORKBOOK_DIR_ENTRY_NAME = "Book";
 
     private static final POILogger log = POILogFactory.getLogger(InternalWorkbook.class);
     private static final int DEBUG = POILogger.DEBUG;
index ec66d5d4a652490176ac79375a255d4cf54d5aee..ca4e79a8e4d04623ce8c257b82d6e9922e439c89 100644 (file)
@@ -18,6 +18,7 @@
 package org.apache.poi.hssf.usermodel;
 
 import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES;
+import static org.apache.poi.hssf.model.InternalWorkbook.OLD_WORKBOOK_DIR_ENTRY_NAME;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -267,7 +268,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
 
         // check for previous version of file format
         try {
-            directory.getEntry("Book");
+            directory.getEntry(OLD_WORKBOOK_DIR_ENTRY_NAME);
             throw new OldExcelFormatException("The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. "
                     + "POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)");
         } catch (FileNotFoundException e) {
index 73efc94d38049f89f63f3ceb0a7c736b57328914..e88eaaff820d3581678ede4bf7724c93c6f53d25 100644 (file)
@@ -16,6 +16,9 @@
 ==================================================================== */
 package org.apache.poi.extractor;
 
+import static org.apache.poi.hssf.model.InternalWorkbook.OLD_WORKBOOK_DIR_ENTRY_NAME;
+import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES;
+
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -37,6 +40,7 @@ import org.apache.poi.hsmf.datatypes.AttachmentChunks;
 import org.apache.poi.hsmf.extractor.OutlookTextExtactor;
 import org.apache.poi.hssf.extractor.EventBasedExcelExtractor;
 import org.apache.poi.hssf.extractor.ExcelExtractor;
+import org.apache.poi.hssf.extractor.OldExcelExtractor;
 import org.apache.poi.hwpf.OldWordFileFormatException;
 import org.apache.poi.hwpf.extractor.Word6Extractor;
 import org.apache.poi.hwpf.extractor.WordExtractor;
@@ -66,8 +70,6 @@ import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
 import org.apache.poi.xwpf.usermodel.XWPFRelation;
 import org.apache.xmlbeans.XmlException;
 
-import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES;
-
 /**
  * Figures out the correct POITextExtractor for your supplied
  *  document, and returns it.
@@ -311,6 +313,9 @@ public class ExtractorFactory {
                 return new ExcelExtractor(poifsDir);
             }
         }
+        if (poifsDir.hasEntry(OLD_WORKBOOK_DIR_ENTRY_NAME)) {
+            throw new IllegalArgumentException("Excel 1-95 file found, call OldExcelExtractor directly");
+        }
 
         if (poifsDir.hasEntry("WordDocument")) {
             // Old or new style word document?