public class ExtractorFactory {
public static final String CORE_DOCUMENT_REL =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
public static POITextExtractor createExtractor(File f) throws IOException, InvalidFormatException, OpenXML4JException, XmlException {
InputStream inp = new PushbackInputStream(
new FileInputStream(f), 8);
if(POIFSFileSystem.hasPOIFSHeader(inp)) {
return createExtractor(new POIFSFileSystem(inp));
}
if(POIXMLDocument.hasOOXMLHeader(inp)) {
inp.close();
return createExtractor(OPCPackage.open(f.toString()));
}
throw new IllegalArgumentException("Your File was neither an OLE2 file, nor an OOXML file");
}