01: // Copyright © 2006-2007 ASERT. Released under the Canoo Webtest license.
02: package com.canoo.webtest.plugins.exceltest;
03:
04: import org.apache.poi.poifs.filesystem.DocumentInputStream;
05: import org.apache.poi.poifs.filesystem.POIFSFileSystem;
06:
07: import java.io.IOException;
08: import java.io.FileNotFoundException;
09: import java.io.InputStream;
10:
11: /**
12: * Hack class to deal with Excel files generated by Crystal Decisions. The root element of an Excel file is supposed
13: * to be 'Workbook' but in Crystal Decisions files, it is 'WORKBOOK'. Excel will still open the file but it causes POI
14: * to fail upon opening the file. This class catches the FileNotFoundException that is thrown when this happens and
15: * tries again with the name capitalized.
16: *
17: * @author Rob Nielsen
18: */
19: public class RetryWithCapsPOIFSFileSystem extends POIFSFileSystem {
20:
21: public RetryWithCapsPOIFSFileSystem(final InputStream inputStream)
22: throws IOException {
23: super (inputStream);
24: }
25:
26: public DocumentInputStream createDocumentInputStream(
27: final String name) throws IOException {
28: try {
29: return super .createDocumentInputStream(name);
30: } catch (FileNotFoundException e) {
31: return super.createDocumentInputStream(name.toUpperCase());
32: }
33: }
34: }
|