From 4643b2ade024f419372fc6893e36f4a7fb893bfd Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Mon, 11 Jul 2016 22:53:22 +0000 Subject: [PATCH] Exceptions git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1752227 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/extractor/OLE2ExtractorFactory.java | 8 ++++++++ .../poi/extractor/OLE2ScrachpadExtractorFactory.java | 6 +----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/poi/extractor/OLE2ExtractorFactory.java b/src/java/org/apache/poi/extractor/OLE2ExtractorFactory.java index 9facd3979..52a0bf12f 100644 --- a/src/java/org/apache/poi/extractor/OLE2ExtractorFactory.java +++ b/src/java/org/apache/poi/extractor/OLE2ExtractorFactory.java @@ -16,6 +16,7 @@ ==================================================================== */ 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.IOException; @@ -27,6 +28,7 @@ import java.util.List; import org.apache.poi.POIOLE2TextExtractor; import org.apache.poi.POITextExtractor; +import org.apache.poi.hssf.OldExcelFormatException; import org.apache.poi.hssf.extractor.EventBasedExcelExtractor; import org.apache.poi.hssf.extractor.ExcelExtractor; import org.apache.poi.poifs.filesystem.DirectoryEntry; @@ -171,6 +173,10 @@ public class OLE2ExtractorFactory { return new ExcelExtractor(poifsDir); } } + if (poifsDir.hasEntry(OLD_WORKBOOK_DIR_ENTRY_NAME)) { + throw new OldExcelFormatException("Old Excel Spreadsheet format (1-95) " + + "found. Please call OldExcelExtractor directly for basic text extraction"); + } // Ask Scratchpad, or fail trying Class cls = getScratchpadClass(); @@ -178,6 +184,8 @@ public class OLE2ExtractorFactory { Method m = cls.getDeclaredMethod("createExtractor", DirectoryNode.class); POITextExtractor ext = (POITextExtractor)m.invoke(null, poifsDir); if (ext != null) return ext; + } catch (IllegalArgumentException iae) { + throw iae; } catch (Exception e) { throw new IllegalArgumentException("Error creating Scratchpad Extractor", e); } diff --git a/src/scratchpad/src/org/apache/poi/extractor/OLE2ScrachpadExtractorFactory.java b/src/scratchpad/src/org/apache/poi/extractor/OLE2ScrachpadExtractorFactory.java index b1e52f4d7..6f8428202 100644 --- a/src/scratchpad/src/org/apache/poi/extractor/OLE2ScrachpadExtractorFactory.java +++ b/src/scratchpad/src/org/apache/poi/extractor/OLE2ScrachpadExtractorFactory.java @@ -34,11 +34,9 @@ import org.apache.poi.hsmf.extractor.OutlookTextExtactor; import org.apache.poi.hwpf.OldWordFileFormatException; import org.apache.poi.hwpf.extractor.Word6Extractor; import org.apache.poi.hwpf.extractor.WordExtractor; -import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.Entry; -import org.apache.xmlbeans.XmlException; /** * Scratchpad-specific logic for {@link OLE2ExtractorFactory} and @@ -55,9 +53,7 @@ public class OLE2ScrachpadExtractorFactory { * Note - doesn't check for core-supported formats! * Note - doesn't check for OOXML-supported formats */ - public static POITextExtractor createExtractor(DirectoryNode poifsDir) throws IOException, - OpenXML4JException, XmlException - { + public static POITextExtractor createExtractor(DirectoryNode poifsDir) throws IOException { if (poifsDir.hasEntry("WordDocument")) { // Old or new style word document? try {