// Copyright � 2006-2007 ASERT. Released under the Canoo Webtest license.
package com.canoo.webtest.plugins.exceltest;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.InputStream;
/**
* Hack class to deal with Excel files generated by Crystal Decisions. The root element of an Excel file is supposed
* to be 'Workbook' but in Crystal Decisions files, it is 'WORKBOOK'. Excel will still open the file but it causes POI
* to fail upon opening the file. This class catches the FileNotFoundException that is thrown when this happens and
* tries again with the name capitalized.
*
* @author Rob Nielsen
*/
public class RetryWithCapsPOIFSFileSystem extends POIFSFileSystem {
public RetryWithCapsPOIFSFileSystem(final InputStream inputStream) throws IOException {
super(inputStream);
}
public DocumentInputStream createDocumentInputStream(final String name) throws IOException {
try {
return super.createDocumentInputStream(name);
} catch (FileNotFoundException e) {
return super.createDocumentInputStream(name.toUpperCase());
}
}
}