Search in sources :

Example 1 with UnsupportedFileFormatException

use of org.apache.poi.UnsupportedFileFormatException in project poi by apache.

the class TestExtractorFactory method testPackage.

@Test
public void testPackage() throws Exception {
    // Excel
    POIXMLTextExtractor extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString(), PackageAccess.READ));
    assertTrue(extractor instanceof XSSFExcelExtractor);
    extractor.close();
    extractor = ExtractorFactory.createExtractor(OPCPackage.open(xlsx.toString()));
    assertTrue(extractor.getText().length() > 200);
    extractor.close();
    // Word
    extractor = ExtractorFactory.createExtractor(OPCPackage.open(docx.toString()));
    assertTrue(extractor instanceof XWPFWordExtractor);
    extractor.close();
    extractor = ExtractorFactory.createExtractor(OPCPackage.open(docx.toString()));
    assertTrue(extractor.getText().length() > 120);
    extractor.close();
    // PowerPoint
    extractor = ExtractorFactory.createExtractor(OPCPackage.open(pptx.toString()));
    assertTrue(extractor instanceof XSLFPowerPointExtractor);
    extractor.close();
    extractor = ExtractorFactory.createExtractor(OPCPackage.open(pptx.toString()));
    assertTrue(extractor.getText().length() > 120);
    extractor.close();
    // Visio
    extractor = ExtractorFactory.createExtractor(OPCPackage.open(vsdx.toString()));
    assertTrue(extractor instanceof XDGFVisioExtractor);
    assertTrue(extractor.getText().length() > 20);
    extractor.close();
    // Text
    try {
        ExtractorFactory.createExtractor(OPCPackage.open(txt.toString()));
        fail("TestExtractorFactory.testPackage() failed on " + txt);
    } catch (UnsupportedFileFormatException e) {
    // Good
    } catch (Exception e) {
        System.out.println("TestExtractorFactory.testPackage() failed on " + txt);
        throw e;
    }
}
Also used : UnsupportedFileFormatException(org.apache.poi.UnsupportedFileFormatException) XDGFVisioExtractor(org.apache.poi.xdgf.extractor.XDGFVisioExtractor) POIXMLTextExtractor(org.apache.poi.POIXMLTextExtractor) XSLFPowerPointExtractor(org.apache.poi.xslf.extractor.XSLFPowerPointExtractor) XSSFExcelExtractor(org.apache.poi.xssf.extractor.XSSFExcelExtractor) XWPFWordExtractor(org.apache.poi.xwpf.extractor.XWPFWordExtractor) OldExcelFormatException(org.apache.poi.hssf.OldExcelFormatException) UnsupportedFileFormatException(org.apache.poi.UnsupportedFileFormatException) POIXMLException(org.apache.poi.POIXMLException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 POIXMLException (org.apache.poi.POIXMLException)1 POIXMLTextExtractor (org.apache.poi.POIXMLTextExtractor)1 UnsupportedFileFormatException (org.apache.poi.UnsupportedFileFormatException)1 OldExcelFormatException (org.apache.poi.hssf.OldExcelFormatException)1 XDGFVisioExtractor (org.apache.poi.xdgf.extractor.XDGFVisioExtractor)1 XSLFPowerPointExtractor (org.apache.poi.xslf.extractor.XSLFPowerPointExtractor)1 XSSFExcelExtractor (org.apache.poi.xssf.extractor.XSSFExcelExtractor)1 XWPFWordExtractor (org.apache.poi.xwpf.extractor.XWPFWordExtractor)1 Test (org.junit.Test)1