Search in sources :

Example 1 with OfficeXmlFileException

use of org.apache.poi.poifs.filesystem.OfficeXmlFileException in project poi by apache.

the class ExtractorFactory method createExtractor.

public static POITextExtractor createExtractor(File f) throws IOException, OpenXML4JException, XmlException {
    NPOIFSFileSystem fs = null;
    try {
        fs = new NPOIFSFileSystem(f);
        POIOLE2TextExtractor extractor = createExtractor(fs);
        extractor.setFilesystem(fs);
        return extractor;
    } catch (OfficeXmlFileException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        return createExtractor(OPCPackage.open(f.toString(), PackageAccess.READ));
    } catch (NotOLE2FileException ne) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw new IllegalArgumentException("Your File was neither an OLE2 file, nor an OOXML file");
    } catch (OpenXML4JException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw e;
    } catch (XmlException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw e;
    } catch (IOException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw e;
    } catch (RuntimeException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw e;
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) OfficeXmlFileException(org.apache.poi.poifs.filesystem.OfficeXmlFileException) NotOLE2FileException(org.apache.poi.poifs.filesystem.NotOLE2FileException) XmlException(org.apache.xmlbeans.XmlException) IOException(java.io.IOException) POIOLE2TextExtractor(org.apache.poi.POIOLE2TextExtractor)

Aggregations

IOException (java.io.IOException)1 POIOLE2TextExtractor (org.apache.poi.POIOLE2TextExtractor)1 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)1 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)1 NotOLE2FileException (org.apache.poi.poifs.filesystem.NotOLE2FileException)1 OfficeXmlFileException (org.apache.poi.poifs.filesystem.OfficeXmlFileException)1 XmlException (org.apache.xmlbeans.XmlException)1