@Override public boolean canExtract(DirectoryNode dn) { return dn.hasEntry("package"); }
@Override public boolean canExtract(DirectoryNode dn) { ClassID clsId = dn.getStorageClsid(); return (PdfClassID.equals(clsId) || dn.hasEntry("CONTENTS")); }
protected boolean canExtractExcel(DirectoryNode dn) { ClassIDPredefined clsId = ClassIDPredefined.lookup(dn.getStorageClsid()); return (ClassIDPredefined.EXCEL_V7 == clsId || ClassIDPredefined.EXCEL_V8 == clsId || dn.hasEntry("Workbook") /*...*/); }
protected boolean canExtractWord(DirectoryNode dn) { ClassIDPredefined clsId = ClassIDPredefined.lookup(dn.getStorageClsid()); return (ClassIDPredefined.WORD_V7 == clsId || ClassIDPredefined.WORD_V8 == clsId || dn.hasEntry("WordDocument")); }
if (poifsDir.hasEntry(workbookName)) { if (getPreferEventExtractor()) { return new EventBasedExcelExtractor(poifsDir); if (poifsDir.hasEntry(OLD_WORKBOOK_DIR_ENTRY_NAME)) { throw new OldExcelFormatException("Old Excel Spreadsheet format (1-95) " + "found. Please call OldExcelExtractor directly for basic text extraction");
/** * Adds an OLE package manager object with the given POIFS to the sheet * * @param poiData an POIFS containing the embedded document, to be added * @param label the label of the payload * @param fileName the original filename * @param command the command to open the payload * @return the index of the added ole object * @throws IOException if the object can't be embedded */ public int addOlePackage(POIFSFileSystem poiData, String label, String fileName, String command) throws IOException { DirectoryNode root = poiData.getRoot(); Map<String,ClassID> olemap = getOleMap(); for (Map.Entry<String,ClassID> entry : olemap.entrySet()) { if (root.hasEntry(entry.getKey())) { root.setStorageClsid(entry.getValue()); break; } } ByteArrayOutputStream bos = new ByteArrayOutputStream(); poiData.writeFilesystem(bos); return addOlePackage(bos.toByteArray(), label, fileName, command); }
public static String getWorkbookDirEntryName(DirectoryNode directory) { for(String wbName : WORKBOOK_DIR_ENTRY_NAMES) { if(directory.hasEntry(wbName)) { return wbName; } } // check for an encrypted .xlsx file - they get OLE2 wrapped try { directory.getEntry(Decryptor.DEFAULT_POIFS_ENTRY); throw new EncryptedDocumentException("The supplied spreadsheet seems to be an Encrypted .xlsx file. " + "It must be decrypted before use by XSSF, it cannot be used by HSSF"); } catch (FileNotFoundException e) { // fall through } // check for previous version of file format try { directory.getEntry(OLD_WORKBOOK_DIR_ENTRY_NAME); throw new OldExcelFormatException("The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. " + "POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)"); } catch (FileNotFoundException e) { // fall through } throw new IllegalArgumentException("The supplied POIFSFileSystem does not contain a BIFF8 'Workbook' entry. " + "Is it really an excel file? Had: " + directory.getEntryNames()); }
/** * Set the contents of a document, creating if needed, * otherwise updating. Returns the created / updated DocumentEntry * * @param name the name of the new or existing DocumentEntry * @param stream the InputStream from which to populate the DocumentEntry * * @return the new or updated DocumentEntry * * @exception IOException if the document can't be created or its content be replaced */ @SuppressWarnings("WeakerAccess") public DocumentEntry createOrUpdateDocument(final String name, final InputStream stream) throws IOException { if (! hasEntry(name)) { return createDocument(name, stream); } else { DocumentNode existing = (DocumentNode)getEntry(name); POIFSDocument nDoc = new POIFSDocument(existing); nDoc.replaceContents(stream); return existing; } }
public static POITextExtractor createExtractor(InputStream inp) throws IOException, OpenXML4JException, XmlException { InputStream is = FileMagic.prepareToCheckMagic(inp); FileMagic fm = FileMagic.valueOf(is); switch (fm) { case OLE2: POIFSFileSystem fs = new POIFSFileSystem(is); boolean isEncrypted = fs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY); return isEncrypted ? createEncryptedOOXMLExtractor(fs) : createExtractor(fs); case OOXML: return createExtractor(OPCPackage.open(is)); default: throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream"); } }
@Override public int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException { // check if we were created by POIFS otherwise create a new dummy POIFS for storing the package data if (initDirectory()) { preserveNodes = true; } // get free MBD-Node int storageId = 0; DirectoryEntry oleDir = null; do { String storageStr = "MBD"+ HexDump.toHex(++storageId); if (!getDirectory().hasEntry(storageStr)) { oleDir = getDirectory().createDirectory(storageStr); oleDir.setStorageClsid(ClassIDPredefined.OLE_V1_PACKAGE.getClassID()); } } while (oleDir == null); Ole10Native.createOleMarkerEntry(oleDir); Ole10Native oleNative = new Ole10Native(label, fileName, command, oleData); ByteArrayOutputStream bos = new ByteArrayOutputStream(); oleNative.writeOut(bos); oleDir.createDocument(Ole10Native.OLE10_NATIVE, new ByteArrayInputStream(bos.toByteArray())); return storageId; }
@SuppressWarnings("unchecked") public static <T extends POITextExtractor> T createExtractor(File f) throws IOException, OpenXML4JException, XmlException { POIFSFileSystem fs = null; try { fs = new POIFSFileSystem(f); if (fs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) { return (T)createEncryptedOOXMLExtractor(fs); } POITextExtractor extractor = createExtractor(fs); extractor.setFilesystem(fs); return (T)extractor; } catch (OfficeXmlFileException e) { // ensure file-handle release IOUtils.closeQuietly(fs); OPCPackage pkg = OPCPackage.open(f.toString(), PackageAccess.READ); T t = (T)createExtractor(pkg); t.setFilesystem(pkg); return t; } 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 | Error | RuntimeException | IOException | XmlException e) { // NOSONAR // ensure file-handle release IOUtils.closeQuietly(fs); throw e; } }
String entryName = null; for (String n : names) { if (root.hasEntry(n)) { entryName = n; break;
if (root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) { InputStream stream = null; try {
> SlideShow<S,P> create(final DirectoryNode root, String password) throws IOException { if (root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) { InputStream stream = null; try {
if (outFS.getRoot().hasEntry(SummaryInformation.DEFAULT_STREAM_NAME)) { outFS.getRoot().getEntry(SummaryInformation.DEFAULT_STREAM_NAME).delete();
public boolean hasContentsEntry() throws IOException { return getFileSystem().getRoot().hasEntry(CONTENTS_ENTRY); }
if (root.hasEntry("Package")) { Entry ooxml = root.getEntry("Package"); TikaInputStream stream = TikaInputStream.get(new DocumentInputStream((DocumentEntry) ooxml));
if (rootNode == null || !rootNode.hasEntry(OLE_DOCUMENT_NAME)) { throw new UnsupportedFormatException("Unsupported QuattroPro file format. " + "Looking for OLE entry \"" + OLE_DOCUMENT_NAME