diff options
author | Nick Burch <nick@apache.org> | 2010-01-25 19:02:13 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2010-01-25 19:02:13 +0000 |
commit | 4c1c3a3ae3a5a86d8fbe42cb1e89afa18c1a8ce1 (patch) | |
tree | 92e768780766821c61b6755bdec7c85da38b2ccf /src/ooxml/testcases/org/apache/poi/extractor | |
parent | 5da681c81f2e77eb37bf79febab568147a3ae6b6 (diff) | |
download | poi-4c1c3a3ae3a5a86d8fbe42cb1e89afa18c1a8ce1.tar.gz poi-4c1c3a3ae3a5a86d8fbe42cb1e89afa18c1a8ce1.zip |
Most of support suggested by Phil Varner on the list - ExtractorFactory can now be told to prefer Event Based extractors (current Excel only) on a per-thread or overall basis
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@902927 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/ooxml/testcases/org/apache/poi/extractor')
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java index c127427a23..81f55cc9f7 100644 --- a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java +++ b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java @@ -27,6 +27,7 @@ import org.apache.poi.hdgf.extractor.VisioTextExtractor; import org.apache.poi.hpbf.extractor.PublisherTextExtractor; import org.apache.poi.hslf.extractor.PowerPointExtractor; import org.apache.poi.hsmf.extractor.OutlookTextExtactor; +import org.apache.poi.hssf.extractor.EventBasedExcelExtractor; import org.apache.poi.hssf.extractor.ExcelExtractor; import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.poifs.filesystem.POIFSFileSystem; @@ -390,6 +391,72 @@ public class TestExtractorFactory extends TestCase { // Good } } + + public void testPreferEventBased() throws Exception { + assertEquals(false, ExtractorFactory.getPreferEventExtractor()); + assertEquals(false, ExtractorFactory.getThreadPrefersEventExtractors()); + assertEquals(null, ExtractorFactory.getAllThreadsPreferEventExtractors()); + + ExtractorFactory.setThreadPrefersEventExtractors(true); + + assertEquals(true, ExtractorFactory.getPreferEventExtractor()); + assertEquals(true, ExtractorFactory.getThreadPrefersEventExtractors()); + assertEquals(null, ExtractorFactory.getAllThreadsPreferEventExtractors()); + + ExtractorFactory.setAllThreadsPreferEventExtractors(false); + + assertEquals(false, ExtractorFactory.getPreferEventExtractor()); + assertEquals(true, ExtractorFactory.getThreadPrefersEventExtractors()); + assertEquals(Boolean.FALSE, ExtractorFactory.getAllThreadsPreferEventExtractors()); + + ExtractorFactory.setAllThreadsPreferEventExtractors(null); + + assertEquals(true, ExtractorFactory.getPreferEventExtractor()); + assertEquals(true, ExtractorFactory.getThreadPrefersEventExtractors()); + assertEquals(null, ExtractorFactory.getAllThreadsPreferEventExtractors()); + + + // Check we get the right extractors now + assertTrue( + ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls))) + instanceof EventBasedExcelExtractor + ); + assertTrue( + ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls))).getText().length() > 200 + ); + + assertTrue( + ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString())) + instanceof XSSFExcelExtractor // TODO + ); + assertTrue( + ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString())).getText().length() > 200 + ); + + + // Put back to normal + ExtractorFactory.setThreadPrefersEventExtractors(false); + assertEquals(false, ExtractorFactory.getPreferEventExtractor()); + assertEquals(false, ExtractorFactory.getThreadPrefersEventExtractors()); + assertEquals(null, ExtractorFactory.getAllThreadsPreferEventExtractors()); + + // And back + assertTrue( + ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls))) + instanceof ExcelExtractor + ); + assertTrue( + ExtractorFactory.createExtractor(new POIFSFileSystem(new FileInputStream(xls))).getText().length() > 200 + ); + + assertTrue( + ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString())) + instanceof XSSFExcelExtractor + ); + assertTrue( + ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString())).getText().length() > 200 + ); + } /** * Test embeded docs text extraction. For now, only |