@@ -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 }
0 commit comments