[
https://issues.apache.org/jira/browse/TIKA-4854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18109670#comment-18109670
]
ASF GitHub Bot commented on TIKA-4854:
--------------------------------------
Copilot commented on code in PR #3094:
URL: https://github.com/apache/tika/pull/3094#discussion_r3889457498
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/test/java/org/apache/tika/parser/iwork/IWorkParserTest.java:
##########
@@ -55,6 +55,45 @@ public void setUp() {
iWorkParser = new IWorkPackageParser();
}
+ /**
+ * The QuickLook preview of a Pages '09 package is the document's
+ * THUMBNAIL embedded document, emitted after the content.
+ */
+ @Test
+ public void testPagesThumbnail() throws Exception {
+ List<Metadata> metadataList = getRecursiveMetadata("testPages.pages");
+ assertEquals(2, metadataList.size());
+ assertEquals("application/vnd.apple.pages",
+ metadataList.get(0).get(HttpHeaders.CONTENT_TYPE));
+ Metadata thumbnail = metadataList.get(1);
+ assertEquals("QuickLook/Thumbnail.jpg",
thumbnail.get(TikaCoreProperties.RESOURCE_NAME_KEY));
+ assertEquals("image/jpeg", thumbnail.get(HttpHeaders.CONTENT_TYPE));
+
assertEquals(TikaCoreProperties.EmbeddedResourceType.THUMBNAIL.toString(),
+ thumbnail.get(TikaCoreProperties.EMBEDDED_RESOURCE_TYPE));
+ }
+
+ @Test
+ public void testNumbersThumbnail() throws Exception {
+ List<Metadata> metadataList =
getRecursiveMetadata("testNumbers.numbers");
+ assertEquals(2, metadataList.size());
+
assertEquals(TikaCoreProperties.EmbeddedResourceType.THUMBNAIL.toString(),
+
metadataList.get(1).get(TikaCoreProperties.EMBEDDED_RESOURCE_TYPE));
Review Comment:
`testNumbersThumbnail` only asserts that the second embedded document is
marked as a THUMBNAIL. As written, the test would still pass if the parser
emitted the wrong embedded entry (wrong resource name or content type).
Consider asserting the expected resource name and content type as well (similar
to `testPagesThumbnail`/`testKeynoteThumbnail`).
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-apple-module/src/test/java/org/apache/tika/parser/iwork/iwana/IWork18ParserTest.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.parser.iwork.iwana;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+import javax.imageio.ImageIO;
+
+import org.junit.jupiter.api.Test;
+
+import org.apache.tika.TikaTest;
+import org.apache.tika.io.TikaInputStream;
+import org.apache.tika.metadata.HttpHeaders;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.TikaCoreProperties;
+import org.apache.tika.parser.ParseContext;
+
+public class IWork18ParserTest extends TikaTest {
+
+ /**
+ * The package's preview.jpg is the document's THUMBNAIL embedded
+ * document. The test fixture was saved without one, so a preview is
+ * added to a copy of it.
+ */
+ @Test
+ public void testPreviewIsTheThumbnail() throws Exception {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ try (InputStream is =
getResourceAsStream("/test-documents/testKeynote2018.key");
+ ZipInputStream in = new ZipInputStream(is);
+ ZipOutputStream out = new ZipOutputStream(bos)) {
+ ZipEntry entry;
+ while ((entry = in.getNextEntry()) != null) {
+ out.putNextEntry(new ZipEntry(entry.getName()));
+ in.transferTo(out);
+ out.closeEntry();
+ }
+ out.putNextEntry(new ZipEntry("Presentation.key/preview.jpg"));
+ out.write(jpeg());
+ out.closeEntry();
+ }
+ List<Metadata> metadataList;
+ try (TikaInputStream tis = TikaInputStream.get(bos.toByteArray())) {
+ metadataList = getRecursiveMetadata(tis, new
IWork18PackageParser(), new Metadata(),
+ new ParseContext(), false);
+ }
+ assertEquals(2, metadataList.size());
+ assertEquals("application/vnd.apple.keynote.18",
+ metadataList.get(0).get(HttpHeaders.CONTENT_TYPE));
+ Metadata thumbnail = metadataList.get(1);
+ assertEquals("Presentation.key/preview.jpg",
+ thumbnail.get(TikaCoreProperties.RESOURCE_NAME_KEY));
+
assertEquals(TikaCoreProperties.EmbeddedResourceType.THUMBNAIL.toString(),
+ thumbnail.get(TikaCoreProperties.EMBEDDED_RESOURCE_TYPE));
+ }
+
+ /**
+ * A small but well-formed JPEG, so the preview parses like a real one.
+ */
+ private static byte[] jpeg() throws Exception {
+ BufferedImage image = new BufferedImage(8, 8,
BufferedImage.TYPE_INT_RGB);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ImageIO.write(image, "jpeg", bos);
+ return bos.toByteArray();
+ }
Review Comment:
`ImageIO.write(...)` returns a boolean and can return false if no JPEG
writer is available. If that happens, this test will silently write an
empty/invalid preview and then fail later in a harder-to-diagnose way. Consider
asserting the write succeeded and failing fast with a clear message.
> Emit the preview image of iWork '09 and iWork '18 packages as a THUMBNAIL
> embedded resource
> -------------------------------------------------------------------------------------------
>
> Key: TIKA-4854
> URL: https://issues.apache.org/jira/browse/TIKA-4854
> Project: Tika
> Issue Type: Improvement
> Reporter: Dominik Schmidt
> Priority: Major
>
> IWork13PackageParser emits preview.jpg as a THUMBNAIL embedded document. The
> two other iWork package parsers do not emit any embedded documents:
> IWorkPackageParser (iWork '09, QuickLook/Thumbnail.jpg) only parses the index
> XML, and IWork18PackageParser only detects the media type although the
> package carries preview.jpg as well. Both previews should be emitted as
> THUMBNAIL like the '13 one, so a client gets the representative image of
> every iWork file the same way.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)