Skip to content

Commit 3b8fefa

Browse files
authored
Merge pull request #45 from levigo/feature/JS-2500_iwork_office_types
feat(JS-2500): recognize iWork office types
2 parents 26c4243 + 5f7c57e commit 3b8fefa

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,30 @@
5252
<zip4j.version>2.11.5</zip4j.version>
5353
<slf4j.version>1.7.36</slf4j.version>
5454

55-
<poi.version>5.2.5</poi.version>
55+
<poi.version>5.3.0</poi.version>
5656
<rtfparserkit.version>1.16.0</rtfparserkit.version>
57-
<commons.io.version>2.16.1</commons.io.version>
58-
<commons-compress.version>1.26.2</commons-compress.version>
57+
<commons.io.version>2.18.0</commons.io.version>
58+
<commons-compress.version>1.27.1</commons-compress.version>
5959
<opennlp-tools.version>1.9.3</opennlp-tools.version>
6060

61-
<pdfbox.version>2.0.31</pdfbox.version>
61+
<pdfbox.version>2.0.32</pdfbox.version>
6262

6363
<jaxb-api.version>4.0.2</jaxb-api.version>
6464
<jaxb-core.version>4.0.5</jaxb-core.version>
6565
<jaxb-impl.version>4.0.5</jaxb-impl.version>
6666

6767
<!-- testing -->
68-
<junit.version>5.10.3</junit.version>
68+
<junit.version>5.11.3</junit.version>
6969
<hamcrest.version>2.2</hamcrest.version>
7070
<jmock-junit5.version>2.13.1</jmock-junit5.version>
71-
<log4j.version>2.23.1</log4j.version>
71+
<log4j.version>2.24.2</log4j.version>
7272

7373
<!-- sonarcloud -->
7474
<sonar.projectKey>levigo_filetype-analyzer</sonar.projectKey>
7575
<sonar.organization>levigo</sonar.organization>
7676
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
7777

78-
<bouncycastle.version>1.78.1</bouncycastle.version>
78+
<bouncycastle.version>1.79</bouncycastle.version>
7979
</properties>
8080

8181
<build>

src/main/java/org/jadice/filetype/matchers/OfficeOpenXMLMatcher.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ public enum OfficeOpenType {
191191
"application/vnd.ms-visio.template.main+xml"),
192192
VISIO_TEMPLATE_MACRO_ENABLED("application/vnd.ms-visio.template.macroEnabled.12",
193193
"Microsoft Visio 2013 macro-enabled Template", "vstm",
194-
"application/vnd.ms-visio.template.macroEnabled.main+xml");
194+
"application/vnd.ms-visio.template.macroEnabled.main+xml"),
195+
APPLE_KEYNOTE("application/vnd.apple.keynote","Apple Keynote Document", "key") ,
196+
APPLE_NUMBERS("application/vnd.apple.numbers", "Apple Numbers Document", "numbers"),
197+
APPLE_PAGES("application/vnd.apple.pages", "Apple Pages Document", "pages"),;
195198

196199

197200
final String mimeType;
@@ -258,6 +261,12 @@ private void detect(final Context ctx, final ZipFile archive) throws IOException
258261
final SortedSet<Relationship> rels = getRelationships(archive);
259262
final List<ContentType> contentTypes = getContentTypes(archive);
260263
if (rels.isEmpty() || contentTypes.isEmpty()) {
264+
final OfficeOpenType type = findIWorkDocumentType(ctx, archive);
265+
if (type != null) {
266+
ctx.setProperty(MimeTypeAction.KEY, type.mimeType);
267+
ctx.setProperty(DescriptionAction.KEY, type.description);
268+
ctx.setProperty(ExtensionAction.KEY, type.extension);
269+
}
261270
return;
262271
}
263272

@@ -283,6 +292,27 @@ private void detect(final Context ctx, final ZipFile archive) throws IOException
283292

284293
}
285294

295+
private OfficeOpenType findIWorkDocumentType(final Context ctx, final ZipFile archive) throws IOException {
296+
final InputStream indexDocument = getSafeInputStream("Index/Document.iwa", archive);
297+
final InputStream metadataDocumentIdentifier = getSafeInputStream("Metadata/DocumentIdentifier", archive);
298+
OfficeOpenType mimeType = null;
299+
if (indexDocument != null && metadataDocumentIdentifier != null) {
300+
switch (ctx.getStatedExtension()){
301+
case "pages" :
302+
mimeType = OfficeOpenType.APPLE_PAGES;
303+
break;
304+
case "key" :
305+
mimeType = OfficeOpenType.APPLE_KEYNOTE;
306+
break;
307+
case "numbers" :
308+
mimeType = OfficeOpenType.APPLE_NUMBERS;
309+
break;
310+
default:
311+
}
312+
}
313+
return mimeType;
314+
}
315+
286316
private OfficeOpenType findDocumentType(final SortedSet<Relationship> rels, final List<ContentType> contentTypes) {
287317

288318
final Relationship mainDocRel = getMainDocument(rels);
@@ -354,7 +384,7 @@ private Map<String, Object> readXMLMetaData(final InputStream inputStream) throw
354384
if (n instanceof Element) {
355385
String key = n.getNodeName();
356386
String val = DOMUtil.getNodeText(n);
357-
if (val != null && val.length() > 0) {
387+
if (val != null && !val.isEmpty()) {
358388
// Ignore empty information
359389
result.put(key, val);
360390
}

src/test/java/TestVariousTypes.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ public static Stream<Arguments> dataProviderVarious() {
7070
arguments("/various_types/File-PNG_8pbc_GRAY.png", "image/png", "PNG image data, grayscale,", "png"),
7171
arguments("/various_types/File-PNG_8bpc_RGBA.png", "image/png", "PNG image data, \\b/color RGBA,", "png"),
7272
arguments("/various_types/File-PNG_16bpc_RGBA.png", "image/png", "PNG image data, \\b/color RGBA,", "png"),
73-
arguments("/various_types/sample-rtf-files-sample2.rtf", "text/rtf", "Rich Text Format data", "rtf")
73+
arguments("/various_types/sample-rtf-files-sample2.rtf", "text/rtf", "Rich Text Format data", "rtf"),
74+
arguments("/various_types/iworks_pages_file.pages", "application/vnd.apple.pages", "Apple Pages Document", "pages"),
75+
arguments("/various_types/iworks_numbers_file.numbers", "application/vnd.apple.numbers", "Apple Numbers Document", "numbers"),
76+
arguments("/various_types/iworks_keynote_file.key", "application/vnd.apple.keynote", "Apple Keynote Document", "key")
7477
);
7578
}
7679

454 KB
Binary file not shown.
134 KB
Binary file not shown.
89.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)