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
This commit is contained in:
Dominik Stadler 2020-12-30 17:03:30 +00:00
parent d406b402dc
commit 0172ec3d50
1 changed files with 7 additions and 14 deletions

View File

@ -39,7 +39,7 @@ import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
*/ */
public class BaseIntegrationTest { public class BaseIntegrationTest {
private final File rootDir; private final File rootDir;
private String file; private final String file;
private FileHandler handler; private FileHandler handler;
public BaseIntegrationTest(File rootDir, String file, FileHandler handler) { public BaseIntegrationTest(File rootDir, String file, FileHandler handler) {
@ -61,7 +61,7 @@ public class BaseIntegrationTest {
handleWrongOLE2XMLExtension(inputFile, e); handleWrongOLE2XMLExtension(inputFile, e);
} catch (OldFileFormatException e) { } catch (OldFileFormatException e) {
// Not even text extraction is supported for these: handler.handleExtracting(inputFile); // 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) { } catch (EncryptedDocumentException e) {
// Do not try to read encrypted files // Do not try to read encrypted files
assumeFalse( true, "File " + file + " excluded because it is password-encrypted" ); 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"))) { if(message != null && (message.equals("The document is really a XLS file"))) {
handler = TestAllFiles.HANDLERS.get(".xls"); handler = TestAllFiles.HANDLERS.get(".xls");
handleFile(inputFile);
} else if(message != null && (message.equals("The document is really a PPT file"))) { } else if(message != null && (message.equals("The document is really a PPT file"))) {
handler = TestAllFiles.HANDLERS.get(".ppt"); handler = TestAllFiles.HANDLERS.get(".ppt");
handleFile(inputFile);
} else if(message != null && (message.equals("The document is really a DOC file"))) { } else if(message != null && (message.equals("The document is really a DOC file"))) {
handler = TestAllFiles.HANDLERS.get(".doc"); handler = TestAllFiles.HANDLERS.get(".doc");
handleFile(inputFile);
} else if(message != null && (message.equals("The document is really a VSD file"))) { } else if(message != null && (message.equals("The document is really a VSD file"))) {
handler = TestAllFiles.HANDLERS.get(".vsd"); 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 // use XWPF instead of HWPF and XSSF instead of HSSF as the file seems to have the wrong extension
} else if (handler instanceof HWPFFileHandler) { } else if (handler instanceof HWPFFileHandler) {
handler = TestAllFiles.HANDLERS.get(".docx"); handler = TestAllFiles.HANDLERS.get(".docx");
handleFile(inputFile);
} else if (handler instanceof HSSFFileHandler) { } else if (handler instanceof HSSFFileHandler) {
handler = TestAllFiles.HANDLERS.get(".xlsx"); handler = TestAllFiles.HANDLERS.get(".xlsx");
handleFile(inputFile);
} else if (handler instanceof HSLFFileHandler) { } else if (handler instanceof HSLFFileHandler) {
handler = TestAllFiles.HANDLERS.get(".pptx"); handler = TestAllFiles.HANDLERS.get(".pptx");
handleFile(inputFile);
// and the other way around, use HWPF instead of XWPF and so forth // and the other way around, use HWPF instead of XWPF and so forth
} else if(handler instanceof XWPFFileHandler) { } else if(handler instanceof XWPFFileHandler) {
handler = TestAllFiles.HANDLERS.get(".doc"); handler = TestAllFiles.HANDLERS.get(".doc");
handleFile(inputFile);
} else if(handler instanceof XSSFFileHandler) { } else if(handler instanceof XSSFFileHandler) {
handler = TestAllFiles.HANDLERS.get(".xls"); handler = TestAllFiles.HANDLERS.get(".xls");
handleFile(inputFile);
} else if(handler instanceof XSLFFileHandler) { } else if(handler instanceof XSLFFileHandler) {
handler = TestAllFiles.HANDLERS.get(".ppt"); handler = TestAllFiles.HANDLERS.get(".ppt");
handleFile(inputFile);
} else { } else {
// nothing matched => throw the exception to the outside // 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 { private void handleFile(File inputFile) throws Exception {