package org.apache.poi.xssf;
+import org.apache.poi.POIDataSamples;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.POIDataSamples;
/**
* @author Yegor Kozlov
*/
public final class XSSFITestDataProvider implements ITestDataProvider {
+ public static final XSSFITestDataProvider instance = new XSSFITestDataProvider();
+ private XSSFITestDataProvider() {
+ // enforce singleton
+ }
+ public static XSSFITestDataProvider getInstance(){
+ return instance;
+ }
public XSSFWorkbook openSampleWorkbook(String sampleFileName) {
return XSSFTestDataSamples.openSampleWorkbook(sampleFileName);
}
-
public XSSFWorkbook writeOutAndReadBack(Workbook original) {
if(!(original instanceof XSSFWorkbook)) {
throw new IllegalArgumentException("Expected an instance of XSSFWorkbook");
}
-
return XSSFTestDataSamples.writeOutAndReadBack((XSSFWorkbook)original);
}
-
public XSSFWorkbook createWorkbook(){
return new XSSFWorkbook();
}
-
public byte[] getTestDataFileContent(String fileName) {
return POIDataSamples.getSpreadSheetInstance().readFile(fileName);
}
-
public SpreadsheetVersion getSpreadsheetVersion(){
return SpreadsheetVersion.EXCEL2007;
}
-
- private XSSFITestDataProvider() {
- // enforce singleton
- }
- private static XSSFITestDataProvider inst = new XSSFITestDataProvider();
- public static XSSFITestDataProvider getInstance(){
- return inst;
+ public String getStandardFileNameExtension() {
+ return "xlsx";
}
}
package org.apache.poi.hssf;
+import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.POIDataSamples;
/**
* @author Yegor Kozlov
*/
public final class HSSFITestDataProvider implements ITestDataProvider {
+ public static final HSSFITestDataProvider instance = new HSSFITestDataProvider();
+ private HSSFITestDataProvider(){
+ // enforce singleton
+ }
+ public static HSSFITestDataProvider getInstance(){
+ return instance;
+ }
public HSSFWorkbook openSampleWorkbook(String sampleFileName) {
- return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
- }
-
- public HSSFWorkbook writeOutAndReadBack(Workbook original) {
+ return HSSFTestDataSamples.openSampleWorkbook(sampleFileName);
+ }
+ public HSSFWorkbook writeOutAndReadBack(Workbook original) {
if(!(original instanceof HSSFWorkbook)) {
throw new IllegalArgumentException("Expected an instance of HSSFWorkbook");
}
-
return HSSFTestDataSamples.writeOutAndReadBack((HSSFWorkbook)original);
- }
-
+ }
public HSSFWorkbook createWorkbook(){
return new HSSFWorkbook();
}
-
public byte[] getTestDataFileContent(String fileName) {
return POIDataSamples.getSpreadSheetInstance().readFile(fileName);
}
-
public SpreadsheetVersion getSpreadsheetVersion(){
return SpreadsheetVersion.EXCEL97;
}
-
- private HSSFITestDataProvider(){}
- private static HSSFITestDataProvider inst = new HSSFITestDataProvider();
- public static HSSFITestDataProvider getInstance(){
- return inst;
+ public String getStandardFileNameExtension() {
+ return "xls";
}
}
*/
public interface ITestDataProvider {
/**
- * Override to provide HSSF / XSSF specific way for re-serialising a workbook
+ * Provides HSSF / XSSF specific way for re-serialising a workbook
*
* @param wb the workbook to re-serialize
* @return the re-serialized workbook
Workbook writeOutAndReadBack(Workbook wb);
/**
- * Override to provide way of loading HSSF / XSSF sample workbooks
+ * Provides way of loading HSSF / XSSF sample workbooks
*
* @param sampleFileName the file name to load
* @return an instance of Workbook loaded from the supplied file name
Workbook openSampleWorkbook(String sampleFileName);
/**
- * Override to provide way of creating HSSF / XSSF workbooks
+ * Provides way of creating HSSF / XSSF workbooks
* @return an instance of Workbook
*/
Workbook createWorkbook();
byte[] getTestDataFileContent(String fileName);
SpreadsheetVersion getSpreadsheetVersion();
+
+ /**
+ * @return "xls" or "xlsx"
+ */
+ String getStandardFileNameExtension();
}