From 0172ec3d503b8fdca0086dbe6fec3a14f201f6a6 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Wed, 30 Dec 2020 17:03:30 +0000 Subject: [PATCH] Adjust error-message on old files and simplify code slightly git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1884950 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/stress/BaseIntegrationTest.java | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/integrationtest/org/apache/poi/stress/BaseIntegrationTest.java b/src/integrationtest/org/apache/poi/stress/BaseIntegrationTest.java index 617355ec47..a9d5f8e6db 100644 --- a/src/integrationtest/org/apache/poi/stress/BaseIntegrationTest.java +++ b/src/integrationtest/org/apache/poi/stress/BaseIntegrationTest.java @@ -39,7 +39,7 @@ import org.apache.poi.poifs.filesystem.OfficeXmlFileException; */ public class BaseIntegrationTest { private final File rootDir; - private String file; + private final String file; private FileHandler handler; public BaseIntegrationTest(File rootDir, String file, FileHandler handler) { @@ -61,7 +61,7 @@ public class BaseIntegrationTest { handleWrongOLE2XMLExtension(inputFile, e); } catch (OldFileFormatException e) { // Not even text extraction is supported for these: handler.handleExtracting(inputFile); - assumeFalse( true, "File " + file + " excluded because it is unsupported old Excel format" ); + assumeFalse( true, "File " + file + " excluded because it is an unsupported old format" ); } catch (EncryptedDocumentException e) { // Do not try to read encrypted files assumeFalse( true, "File " + file + " excluded because it is password-encrypted" ); @@ -123,42 +123,35 @@ public class BaseIntegrationTest { if(message != null && (message.equals("The document is really a XLS file"))) { handler = TestAllFiles.HANDLERS.get(".xls"); - handleFile(inputFile); } else if(message != null && (message.equals("The document is really a PPT file"))) { handler = TestAllFiles.HANDLERS.get(".ppt"); - handleFile(inputFile); } else if(message != null && (message.equals("The document is really a DOC file"))) { handler = TestAllFiles.HANDLERS.get(".doc"); - handleFile(inputFile); } else if(message != null && (message.equals("The document is really a VSD file"))) { handler = TestAllFiles.HANDLERS.get(".vsd"); - handleFile(inputFile); // use XWPF instead of HWPF and XSSF instead of HSSF as the file seems to have the wrong extension } else if (handler instanceof HWPFFileHandler) { handler = TestAllFiles.HANDLERS.get(".docx"); - handleFile(inputFile); } else if (handler instanceof HSSFFileHandler) { handler = TestAllFiles.HANDLERS.get(".xlsx"); - handleFile(inputFile); } else if (handler instanceof HSLFFileHandler) { handler = TestAllFiles.HANDLERS.get(".pptx"); - handleFile(inputFile); // and the other way around, use HWPF instead of XWPF and so forth } else if(handler instanceof XWPFFileHandler) { handler = TestAllFiles.HANDLERS.get(".doc"); - handleFile(inputFile); } else if(handler instanceof XSSFFileHandler) { handler = TestAllFiles.HANDLERS.get(".xls"); - handleFile(inputFile); } else if(handler instanceof XSLFFileHandler) { handler = TestAllFiles.HANDLERS.get(".ppt"); - handleFile(inputFile); } else { // nothing matched => throw the exception to the outside - throw e; - } + throw e; + } + + // we found a different handler to try processing again + handleFile(inputFile); } private void handleFile(File inputFile) throws Exception { -- 2.39.5