*/
@SuppressWarnings({"WeakerAccess", "JavadocReference"})
public final class ExtractorFactory {
+ /**
+ * Some OPCPackages are packed in side an OLE2 container.
+ * If encrypted, the {@link DirectoryNode} is called {@link Decryptor#DEFAULT_POIFS_ENTRY "EncryptedPackage"},
+ * otherwise the node is called "Packge"
+ */
+ public static final String OOXML_PACKAGE = "Package";
+
private static final POILogger LOGGER = POILogFactory.getLogger(ExtractorFactory.class);
/** Should this thread prefer event based over usermodel based extractors? */
public static POITextExtractor createExtractor(final DirectoryNode root, String password) throws IOException {
// Encrypted OOXML files go inside OLE2 containers, is this one?
- if (root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY) || root.hasEntry("Package")) {
+ if (root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE)) {
return wp(FileMagic.OOXML, w -> w.create(root, password));
} else {
return wp(FileMagic.OLE2, w -> w.create(root, password));
package org.apache.poi.poifs.filesystem;
+import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE;
+
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
* @throws IOException If an error occurs while decrypting or if the password does not match
*/
public static InputStream getDecryptedStream(final DirectoryNode root, String password)
- throws IOException {
+ throws IOException {
+ // first check if the node contains an plain package
+ if (root.hasEntry(OOXML_PACKAGE)) {
+ return root.createDocumentInputStream(OOXML_PACKAGE);
+ }
+
EncryptionInfo info = new EncryptionInfo(root);
Decryptor d = Decryptor.getInstance(info);
/**
* Checks that the supplied InputStream (which MUST
* support mark and reset) has a OOXML (zip) header at the start of it.<p>
- *
+ *
* If unsure if your InputStream does support mark / reset,
* use {@link FileMagic#prepareToCheckMagic(InputStream)} to wrap it and make
* sure to always use that, and not the original!
- *
+ *
* @param inp An InputStream which supports either mark/reset
*
* @deprecated in 3.17-beta2, use {@link FileMagic#valueOf(InputStream)} == FileMagic.OOXML instead
==================================================================== */
package org.apache.poi.sl.usermodel;
+import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE;
import static org.apache.poi.poifs.crypt.EncryptionInfo.ENCRYPTION_INFO_ENTRY;
import java.io.BufferedInputStream;
*/
public static SlideShow<?,?> create(final DirectoryNode root, String password) throws IOException {
// Encrypted OOXML files go inside OLE2 containers, is this one?
- if (root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
+ if (root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE)) {
return wp(FileMagic.OOXML, w -> w.create(root, password));
} else {
return wp(FileMagic.OLE2, w -> w.create(root, password));
} else if (fm == FileMagic.OLE2) {
final boolean ooxmlEnc;
try (POIFSFileSystem fs = new POIFSFileSystem(file, true)) {
- ooxmlEnc = fs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY);
+ DirectoryNode root = fs.getRoot();
+ ooxmlEnc = root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE);
}
return wp(ooxmlEnc ? FileMagic.OOXML : fm, w -> w.create(file, password, readOnly));
}
==================================================================== */
package org.apache.poi.ss.usermodel;
+import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE;
import static org.apache.poi.poifs.crypt.EncryptionInfo.ENCRYPTION_INFO_ENTRY;
import java.io.BufferedInputStream;
*/
public static Workbook create(final DirectoryNode root, String password) throws IOException {
// Encrypted OOXML files go inside OLE2 containers, is this one?
- if (root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY)) {
+ if (root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE)) {
return wp(FileMagic.OOXML, w -> w.create(root, password));
} else {
return wp(FileMagic.OLE2, w -> w.create(root, password));
} else if (fm == FileMagic.OLE2) {
final boolean ooxmlEnc;
try (POIFSFileSystem fs = new POIFSFileSystem(file, true)) {
- ooxmlEnc = fs.getRoot().hasEntry(Decryptor.DEFAULT_POIFS_ENTRY);
+ DirectoryNode root = fs.getRoot();
+ ooxmlEnc = root.hasEntry(Decryptor.DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE);
}
return wp(ooxmlEnc ? FileMagic.OOXML : fm, w -> w.create(file, password, readOnly));
}
==================================================================== */
package org.apache.poi.ooxml.extractor;
+import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE;
+
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@Override
public POITextExtractor create(DirectoryNode poifsDir, String password) throws IOException {
// First, check for plain OOXML package
- if (poifsDir.hasEntry("Package")) {
- try (InputStream is = poifsDir.createDocumentInputStream("Package")) {
+ if (poifsDir.hasEntry(OOXML_PACKAGE)) {
+ try (InputStream is = poifsDir.createDocumentInputStream(OOXML_PACKAGE)) {
return create(is, password);
}
}