<pathelement location="${main.output.test.dir}"/>
<pathelement location="${ooxml.output.dir}"/>
<pathelement location="${integration.output.test.dir}"/>
+ <pathelement location="${examples.output.dir}"/>
</path>
<path id="ooxml-lite.classpath">
<path refid="ooxml.classpath"/>
<pathelement location="${ooxml.output.dir}"/>
<pathelement location="${main.output.test.dir}"/>
+ <pathelement location="${examples.output.dir}"/>
<pathelement location="${main.ant.jar}"/>
</classpath>
</javac>
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.util.SAXHelper;
import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler.SheetContentsHandler;
} else {
output.append(',');
}
-
+
+ // gracefully handle missing CellRef here in a similar way as XSSFCell does
+ if(cellReference == null) {
+ cellReference = new CellAddress(currentRow, currentCol).formatAsString();
+ }
+
// Did we miss any cells?
int thisCol = (new CellReference(cellReference)).getCol();
int missedCols = thisCol - currentCol - 1;
return files;
}
+ @SuppressWarnings("DefaultAnnotationParam")
@Parameter(value=0)
public String file;
throw new Exception("While handling " + file, e);
}
}
+
+ // let some file handlers do additional stuff
+ handler.handleAdditional(inputFile);
}
static String getExtension(String file) {
@Override
public void handleExtracting(File file) throws Exception {
}
+
+ @Override
+ public void handleAdditional(File file) throws Exception {
+ }
}
}
stream.close();\r
}\r
}\r
+\r
+ @Override\r
+ public void handleAdditional(File file) throws Exception {\r
+ // by default we do nothing here\r
+ }\r
}\r
* is returning some text.
*/
void handleExtracting(File file) throws Exception;
+
+ /**
+ * Allows to perform some additional work, e.g. run
+ * some of the example applications
+ */
+ void handleAdditional(File file) throws Exception;
}
==================================================================== */
package org.apache.poi.stress;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-
+import org.apache.poi.EncryptedDocumentException;
+import org.apache.poi.hssf.OldExcelFormatException;
+import org.apache.poi.hssf.dev.BiffViewer;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.util.RecordFormatException;
import org.junit.Test;
+import java.io.*;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.junit.Assert.assertFalse;
+
public class HSSFFileHandler extends SpreadsheetHandler {
private POIFSFileHandler delegate = new POIFSFileHandler();
@Override
// TODO: still fails on some records... RecordsStresser.handleWorkbook(wb);
}
+ private static final Set<String> EXPECTED_ADDITIONAL_FAILURES = new HashSet<String>();
+ static {
+ // encrypted
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/35897-type4.xls");
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/xor-encryption-abc.xls");
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/password.xls");
+ // broken files
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/43493.xls");
+ // TODO: ok to ignore?
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/50833.xls");
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/51832.xls");
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/XRefCalc.xls");
+ }
+
+ @Override
+ public void handleAdditional(File file) throws Exception {
+ // redirect stdout as the examples often write lots of text
+ PrintStream oldOut = System.out;
+ try {
+ System.setOut(new PrintStream(new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+ }
+ }));
+
+ BiffViewer.main(new String[]{file.getAbsolutePath()});
+
+ assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!",
+ EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()));
+ } catch (OldExcelFormatException e) {
+ // old excel formats are not supported here
+ } catch (EncryptedDocumentException e) {
+ if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
+ throw e;
+ }
+ } catch (RecordFormatException e) {
+ if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
+ throw e;
+ }
+ } catch (RuntimeException e) {
+ if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
+ throw e;
+ }
+ } finally {
+ System.setOut(oldOut);
+ }
+ }
+
// a test-case to test this locally without executing the full TestAllFiles
@Test
public void test() throws Exception {
==================================================================== */
package org.apache.poi.stress;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
+import java.util.HashSet;
import java.util.Iterator;
+import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
+import org.apache.poi.POIXMLException;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.util.IOUtils;
+import org.apache.poi.xssf.eventusermodel.XLSX2CSV;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
+import org.apache.poi.xssf.eventusermodel.examples.FromHowTo;
import org.apache.poi.xssf.extractor.XSSFExportToXml;
import org.apache.poi.xssf.usermodel.XSSFMap;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
exporter.exportToXML(os, true);
}
}
-
+
+ private static final Set<String> EXPECTED_ADDITIONAL_FAILURES = new HashSet<String>();
+ static {
+ // expected sheet-id not found
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/52348.xlsx");
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/59021.xlsx");
+ // zip-bomb
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/54764.xlsx");
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/54764-2.xlsx");
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/54764.xlsx");
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/poc-xmlbomb.xlsx");
+ // strict OOXML
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/57914.xlsx");
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/SampleSS.strict.xlsx");
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/SimpleStrict.xlsx");
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/sample.strict.xlsx");
+ // binary format
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/Simple.xlsb");
+ // TODO: good to ignore?
+ EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/sample-beta.xlsx");
+ }
+
+ @Override
+ public void handleAdditional(File file) throws Exception {
+ // redirect stdout as the examples often write lots of text
+ PrintStream oldOut = System.out;
+ try {
+ System.setOut(new PrintStream(new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+ }
+ }));
+ FromHowTo.main(new String[]{file.getAbsolutePath()});
+ XLSX2CSV.main(new String[]{file.getAbsolutePath()});
+
+ assertFalse("Expected Extraction to fail for file " + file + " and handler " + this + ", but did not fail!",
+ EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName()));
+
+ } catch (OLE2NotOfficeXmlFileException e) {
+ // we have some files that are not actually OOXML and thus cannot be tested here
+ } catch (IllegalArgumentException e) {
+ if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
+ throw e;
+ }
+ } catch (InvalidFormatException e) {
+ if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
+ throw e;
+ }
+ } catch (IOException e) {
+ if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
+ throw e;
+ }
+ } catch (POIXMLException e) {
+ if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" + file.getName())) {
+ throw e;
+ }
+ } finally {
+ System.setOut(oldOut);
+ }
+ }
+
// a test-case to test this locally without executing the full TestAllFiles
@Test
public void test() throws Exception {
public void testExtractor() throws Exception {
handleExtracting(new File("test-data/spreadsheet/ref-56737.xlsx"));
}
-}
\ No newline at end of file
+
+ @Test
+ public void testAdditional() throws Exception {
+ handleAdditional(new File("test-data/spreadsheet/poc-xmlbomb.xlsx"));
+ }
+}