Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIKA-4092 -- upgrade POI #1211

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tika-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@
<pax.exam.version>4.13.1</pax.exam.version>
<pdfbox.version>2.0.28</pdfbox.version>
<!-- NOTE: sync tukaani version with commons-compress in tika-parsers -->
<poi.version>5.2.3</poi.version>
<poi.version>5.2.4-SNAPSHOT</poi.version>
<quartz.version>2.3.2</quartz.version>
<reactor.netty.version>1.1.8</reactor.netty.version>
<rome.version>1.19.0</rome.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.tika.detect.microsoft;

import static org.apache.poi.hssf.model.InternalWorkbook.BOOK;
import static org.apache.tika.mime.MediaType.application;
import static org.apache.tika.mime.MediaType.image;

Expand Down Expand Up @@ -286,16 +287,11 @@ public static MediaType detect(Set<String> anyCaseNames, DirectoryEntry root) {
if (mediaType != null) {
return mediaType;
}

for (String workbookEntryName : InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES) {
if (ucNames.contains(workbookEntryName)) {
MediaType tmp = processCompObjFormatType(root);
if (tmp.equals(MS_GRAPH_CHART)) {
return MS_GRAPH_CHART;
}
return XLS;
}
mediaType = checkXLS(ucNames, root);
if (mediaType != null) {
return mediaType;
}

if (ucNames.contains(SW_DOC_CONTENT_MGR) && ucNames.contains(SW_DOC_MGR_TEMP_STORAGE)) {
return SLDWORKS;
} else if (ucNames.contains(STAR_CALC_DOCUMENT)) {
Expand All @@ -322,9 +318,6 @@ public static MediaType detect(Set<String> anyCaseNames, DirectoryEntry root) {
// Works 7.0 spreadsheet files contain both
// we want to avoid classifying this as Excel
return XLR;
} else if (ucNames.contains("BOOK")) {
// Excel 95 or older, we won't be able to parse this....
return XLS;
} else if (ucNames.contains(WORD_DOCUMENT)) {
return DOC;
} else if (ucNames.contains(QUILL)) {
Expand Down Expand Up @@ -395,6 +388,26 @@ public static MediaType detect(Set<String> anyCaseNames, DirectoryEntry root) {
return OLE;
}

private static MediaType checkXLS(Set<String> ucNames, DirectoryEntry root) {
for (String workbookEntryName : InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES) {
if (ucNames.contains(workbookEntryName)) {
MediaType tmp = processCompObjFormatType(root);
if (tmp.equals(MS_GRAPH_CHART)) {
return MS_GRAPH_CHART;
}
return XLS;
}
}
if (ucNames.contains(BOOK)) {
MediaType tmp = processCompObjFormatType(root);
if (tmp.equals(MS_GRAPH_CHART)) {
return MS_GRAPH_CHART;
}
return XLS;
}
return null;
}

private static MediaType checkEncrypted(Set<String> ucNames, DirectoryEntry root) {
//figure out if encrypted/pw protected first
if (ucNames.contains(DATA_SPACES)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ protected void handleEmbeddedOfficeDoc(DirectoryEntry dir, String resourceName,

// Is it an embedded OLE2 document, or an embedded OOXML document?
//first try for ooxml
Entry ooxml = dir.hasEntry("Package") ? dir.getEntry("Package") :
(dir.hasEntry("package") ? dir.getEntry("package") : null);
Entry ooxml = dir.hasEntry("Package") ? dir.getEntry("Package") : null;

if (ooxml != null) {
// It's OOXML (has a ZipFile):
Expand Down Expand Up @@ -218,16 +217,12 @@ private void handleCompObj(DirectoryEntry dir, POIFSDocumentType type, String rN
//TikaCoreProperties.ORIGINAL_RESOURCE_NAME

// Grab the contents and process
DocumentEntry contentsEntry;
DocumentEntry contentsEntry = null;
try {
contentsEntry = (DocumentEntry) dir.getEntry("CONTENTS");
} catch (FileNotFoundException fnfe1) {
try {
contentsEntry = (DocumentEntry) dir.getEntry("Contents");
} catch (FileNotFoundException fnfe2) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(fnfe2, parentMetadata);
return;
}
} catch (FileNotFoundException fnfe) {
EmbeddedDocumentUtil.recordEmbeddedStreamException(fnfe, parentMetadata);
return;
}
int length = contentsEntry.getSize();
DocumentInputStream inp = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ private byte[] handleEmbeddedPOIFS(InputStream is, Metadata metadata,
try {
contentsEntry = (DocumentEntry) root.getEntry("CONTENTS");
} catch (FileNotFoundException ioe) {
contentsEntry = (DocumentEntry) root.getEntry("Contents");
//no contents
EmbeddedDocumentUtil.recordEmbeddedStreamException(ioe, metadata);
return ret;
}

try (DocumentInputStream inp = new DocumentInputStream(contentsEntry)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Set;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import org.apache.tika.TikaTest;
Expand All @@ -50,7 +49,6 @@ public void testEncrypted() throws Exception {
}

@Test
@Disabled("until POI can handle case insensitive entry lookups")
public void testBasic() throws Exception {
List<Metadata> metadataList = getRecursiveMetadata("casing/simple_normal_case.doc");
assertCloseEnough(metadataList, getRecursiveMetadata("casing/simple_lower_case.doc"));
Expand Down