Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-1699 Tika Parser - Image Parse Bug

Lewis John McGibbney6f4df5827ac3
diff --git a/CHANGES.txt b/CHANGES.txt
index d80e8527c..2142308ac 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
Nutch Development Trunk
+* NUTCH-1699 Tika Parser - Image Parse Bug (Mehmet Zahid Yüzügüldü, snagel via lewismc)
+
* NUTCH-1695 Add NutchDocument.toString() to ease debugging (markus)
* NUTCH-1675 NutchField to support long (markus)
diff --git a/src/plugin/parse-tika/build.xml b/src/plugin/parse-tika/build.xml
index 17dea0440..4ecb3f878 100644
--- a/src/plugin/parse-tika/build.xml
+++ b/src/plugin/parse-tika/build.xml
@@ -47,6 +47,7 @@
<include name="*.pdf"/>
<include name="ootest.*"/>
<include name="*.doc"/>
+ <include name="*.gif"/>
</fileset>
</copy>
diff --git a/src/plugin/parse-tika/sample/nutch_logo_tm.gif b/src/plugin/parse-tika/sample/nutch_logo_tm.gif
new file mode 100644
index 000000000..0545a6042
Binary files /dev/null and b/src/plugin/parse-tika/sample/nutch_logo_tm.gif differ
diff --git a/src/plugin/parse-tika/src/java/org/apache/nutch/parse/tika/TikaParser.java b/src/plugin/parse-tika/src/java/org/apache/nutch/parse/tika/TikaParser.java
index 8680e4e78..36bfcca54 100644
--- a/src/plugin/parse-tika/src/java/org/apache/nutch/parse/tika/TikaParser.java
+++ b/src/plugin/parse-tika/src/java/org/apache/nutch/parse/tika/TikaParser.java
@@ -93,6 +93,7 @@ public class TikaParser implements org.apache.nutch.parse.Parser {
DocumentFragment root = doc.createDocumentFragment();
DOMBuilder domhandler = new DOMBuilder(doc, root);
ParseContext context = new ParseContext();
+ tikamd.set(Metadata.CONTENT_TYPE, mimeType);
try {
parser.parse(new ByteArrayInputStream(raw), domhandler, tikamd,context);
} catch (Exception e) {
diff --git a/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestImageMetadata.java b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestImageMetadata.java
new file mode 100644
index 000000000..c479a10c8
--- /dev/null
+++ b/src/plugin/parse-tika/src/test/org/apache/nutch/tika/TestImageMetadata.java
@@ -0,0 +1,72 @@
+/**
+ * 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.nutch.tika;
+
+import org.apache.nutch.protocol.ProtocolFactory;
+import org.apache.nutch.protocol.Protocol;
+import org.apache.nutch.protocol.Content;
+import org.apache.nutch.protocol.ProtocolException;
+
+import org.apache.nutch.parse.Parse;
+import org.apache.nutch.parse.ParseUtil;
+import org.apache.nutch.parse.ParseException;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.nutch.util.NutchConfiguration;
+
+import org.apache.hadoop.io.Text;
+import org.apache.nutch.crawl.CrawlDatum;
+
+import junit.framework.TestCase;
+
+/**
+ * Test extraction of image metadata
+ */
+public class TestImageMetadata extends TestCase {
+
+ private String fileSeparator = System.getProperty("file.separator");
+ // This system property is defined in ./src/plugin/build-plugin.xml
+ private String sampleDir = System.getProperty("test.data",".");
+ // Make sure sample files are copied to "test.data" as specified in
+ private String[] sampleFiles = {
+ "nutch_logo_tm.gif",
+ };
+
+ public TestImageMetadata(String name) {
+ super(name);
+ }
+
+ public void testIt() throws ProtocolException, ParseException {
+ String urlString;
+ Protocol protocol;
+ Content content;
+ Parse parse;
+
+ for (int i = 0; i < sampleFiles.length; i++) {
+ urlString = "file:" + sampleDir + fileSeparator + sampleFiles[i];
+
+ Configuration conf = NutchConfiguration.create();
+ protocol = new ProtocolFactory(conf).getProtocol(urlString);
+ content = protocol.getProtocolOutput(new Text(urlString), new CrawlDatum()).getContent();
+ parse = new ParseUtil(conf).parseByExtensionId("parse-tika", content).get(content.getUrl());
+
+ assertEquals("121", parse.getData().getMeta("width"));
+ assertEquals("48", parse.getData().getMeta("height"));
+ }
+ }
+
+}