Apache Nutch is an extensible and scalable web crawler
NUTCH-810 Upgraded to Tika 0.7
Julien Nioche50d3c425f1b4
diff --git a/CHANGES.txt b/CHANGES.txtindex f2268ff58..c8f22b8d2 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogUnreleased Changes+* NUTCH-810 Upgrade to Tika 0.7 (jnioche)+* NUTCH-785 Copy metadata from origin URL when redirecting in Fetcher + call scfilters.initialScore on newly created URL (jnioche)* NUTCH-779 Mechanism for passing metadata from parse to crawldb (jnioche)diff --git a/conf/tika-mimetypes.xml b/conf/tika-mimetypes.xmlindex 65e516656..297ed90ff 100644--- a/conf/tika-mimetypes.xml+++ b/conf/tika-mimetypes.xml@@ -2198,7 +2198,11 @@<mime-type type="application/x-cpio"><magic priority="50">- <match value="070707" type="host16" offset="0"/>+ <match value="070707" type="little16" offset="0"/>+ <match value="070707" type="big16" offset="0"/>+ <match value="070707" type="string" offset="0"/>+ <match value="070701" type="string" offset="0"/>+ <match value="070702" type="string" offset="0"/></magic><glob pattern="*.cpio"/></mime-type>@@ -3551,7 +3555,13 @@bad HTML, unfortunately.--><root-XML localName="html"/>+ <root-XML localName="HTML"/><root-XML localName="link"/>+ <root-XML localName="LINK"/>+ <root-XML localName="body"/>+ <root-XML localName="BODY"/>+ <root-XML localName="p"/>+ <root-XML localName="P"/><magic priority="50"><match value="<!DOCTYPE HTML" type="string" offset="0:64"/><match value="<!doctype html" type="string" offset="0:64"/>diff --git a/lib/tika-core-0.6.jar b/lib/tika-core-0.7.jarsimilarity index 69%rename from lib/tika-core-0.6.jarrename to lib/tika-core-0.7.jarindex 6e2ee5e07..7ca783153 100644Binary files a/lib/tika-core-0.6.jar and b/lib/tika-core-0.7.jar differdiff --git a/src/plugin/build.xml b/src/plugin/build.xmlindex 7aa83f6aa..561d97e6e 100755--- a/src/plugin/build.xml+++ b/src/plugin/build.xml@@ -32,8 +32,8 @@<ant dir="index-basic" target="deploy"/><ant dir="index-anchor" target="deploy"/><ant dir="index-more" target="deploy"/>- <ant dir="field-basic" target="deploy"/>- <ant dir="field-boost" target="deploy"/>+ <ant dir="field-basic" target="deploy"/>+ <ant dir="field-boost" target="deploy"/><ant dir="languageidentifier" target="deploy"/><ant dir="lib-http" target="deploy"/><ant dir="lib-jakarta-poi" target="deploy"/>@@ -65,12 +65,12 @@<ant dir="query-basic" target="deploy"/><ant dir="query-more" target="deploy"/><ant dir="query-site" target="deploy"/>- <ant dir="query-custom" target="deploy"/>+ <ant dir="query-custom" target="deploy"/><ant dir="query-url" target="deploy"/><ant dir="response-json" target="deploy"/><ant dir="response-xml" target="deploy"/><ant dir="scoring-opic" target="deploy"/>- <ant dir="scoring-link" target="deploy"/>+ <ant dir="scoring-link" target="deploy"/><ant dir="summary-basic" target="deploy"/><ant dir="subcollection" target="deploy"/><ant dir="summary-lucene" target="deploy"/>@@ -99,7 +99,6 @@<ant dir="protocol-httpclient" target="test"/><!--ant dir="parse-ext" target="test"/--><ant dir="parse-html" target="test"/>- <!-- <ant dir="parse-mp3" target="test"/> --><ant dir="parse-msexcel" target="test"/><ant dir="parse-mspowerpoint" target="test"/><ant dir="parse-msword" target="test"/>@@ -107,7 +106,6 @@<ant dir="parse-pdf" target="test"/><ant dir="parse-rss" target="test"/><ant dir="feed" target="test"/>- <!-- <ant dir="parse-rtf" target="test"/> --><ant dir="parse-swf" target="test"/><ant dir="parse-tika" target="test"/><ant dir="parse-zip" target="test"/>@@ -172,11 +170,11 @@<ant dir="query-more" target="clean"/><ant dir="query-site" target="clean"/><ant dir="query-url" target="clean"/>- <ant dir="query-custom" target="clean"/>+ <ant dir="query-custom" target="clean"/><ant dir="response-json" target="clean"/><ant dir="response-xml" target="clean"/><ant dir="scoring-opic" target="clean"/>- <ant dir="scoring-link" target="clean"/>+ <ant dir="scoring-link" target="clean"/><ant dir="subcollection" target="clean"/><ant dir="summary-basic" target="clean"/><ant dir="summary-lucene" target="clean"/>diff --git a/src/plugin/parse-tika/ivy.xml b/src/plugin/parse-tika/ivy.xmlindex d9a431960..e03edffe2 100644--- a/src/plugin/parse-tika/ivy.xml+++ b/src/plugin/parse-tika/ivy.xml@@ -1,7 +1,7 @@<ivy-module version="2.0"><info organisation="apache" module="parse-tika"/><dependencies>- <dependency org="org.apache.tika" name="tika-parsers" rev="0.6">+ <dependency org="org.apache.tika" name="tika-parsers" rev="0.7"><exclude module="lucene-*"/><exclude module="tika-core"/><exclude module="log4j"/>diff --git a/src/plugin/parse-tika/lib/bcmail-jdk15-1.45.jar b/src/plugin/parse-tika/lib/bcmail-jdk15-1.45.jarnew file mode 100644index 000000000..f66e9a8b9Binary files /dev/null and b/src/plugin/parse-tika/lib/bcmail-jdk15-1.45.jar differdiff --git a/src/plugin/parse-tika/lib/bcprov-jdk15-1.45.jar b/src/plugin/parse-tika/lib/bcprov-jdk15-1.45.jarnew file mode 100644index 000000000..409070b03Binary files /dev/null and b/src/plugin/parse-tika/lib/bcprov-jdk15-1.45.jar differdiff --git a/src/plugin/parse-tika/lib/fontbox-0.8.0-incubator.jar b/src/plugin/parse-tika/lib/fontbox-0.8.0-incubator.jardeleted file mode 100644index 91a496ac1..000000000Binary files a/src/plugin/parse-tika/lib/fontbox-0.8.0-incubator.jar and /dev/null differdiff --git a/src/plugin/parse-tika/lib/fontbox-1.1.0.jar b/src/plugin/parse-tika/lib/fontbox-1.1.0.jarnew file mode 100644index 000000000..3bc5a7691Binary files /dev/null and b/src/plugin/parse-tika/lib/fontbox-1.1.0.jar differdiff --git a/src/plugin/parse-tika/lib/jempbox-0.8.0-incubator.jar b/src/plugin/parse-tika/lib/jempbox-0.8.0-incubator.jardeleted file mode 100644index adcead773..000000000Binary files a/src/plugin/parse-tika/lib/jempbox-0.8.0-incubator.jar and /dev/null differdiff --git a/src/plugin/parse-tika/lib/jempbox-1.1.0.jar b/src/plugin/parse-tika/lib/jempbox-1.1.0.jarnew file mode 100644index 000000000..d2c9a0514Binary files /dev/null and b/src/plugin/parse-tika/lib/jempbox-1.1.0.jar differdiff --git a/src/plugin/parse-tika/lib/pdfbox-0.8.0-incubating.jar b/src/plugin/parse-tika/lib/pdfbox-1.1.0.jarsimilarity index 81%rename from src/plugin/parse-tika/lib/pdfbox-0.8.0-incubating.jarrename to src/plugin/parse-tika/lib/pdfbox-1.1.0.jarindex 637324e46..ed19b4509 100644Binary files a/src/plugin/parse-tika/lib/pdfbox-0.8.0-incubating.jar and b/src/plugin/parse-tika/lib/pdfbox-1.1.0.jar differdiff --git a/src/plugin/parse-tika/lib/tika-parsers-0.6.jar b/src/plugin/parse-tika/lib/tika-parsers-0.6.jardeleted file mode 100644index d61242ed6..000000000Binary files a/src/plugin/parse-tika/lib/tika-parsers-0.6.jar and /dev/null differdiff --git a/src/plugin/parse-tika/lib/tika-parsers-0.7.jar b/src/plugin/parse-tika/lib/tika-parsers-0.7.jarnew file mode 100644index 000000000..e34be821bBinary files /dev/null and b/src/plugin/parse-tika/lib/tika-parsers-0.7.jar differdiff --git a/src/plugin/parse-tika/plugin.xml b/src/plugin/parse-tika/plugin.xmlindex 50f36ef04..1659a2e43 100644--- a/src/plugin/parse-tika/plugin.xml+++ b/src/plugin/parse-tika/plugin.xml@@ -25,23 +25,26 @@<library name="parse-tika.jar"><export name="*"/></library>+<library name="asm-3.1.jar"/>- <library name="bcprov-jdk14-136.jar"/><library name="bcmail-jdk14-136.jar"/>+ <library name="bcmail-jdk15-1.45.jar"/>+ <library name="bcprov-jdk14-136.jar"/>+ <library name="bcprov-jdk15-1.45.jar"/><library name="commons-compress-1.0.jar"/><library name="commons-logging-1.1.1.jar"/><library name="dom4j-1.6.1.jar"/>- <library name="fontbox-0.8.0-incubator.jar"/>+ <library name="fontbox-1.1.0.jar"/><library name="geronimo-stax-api_1.0_spec-1.0.1.jar"/>- <library name="jempbox-0.8.0-incubator.jar"/>+ <library name="jempbox-1.1.0.jar"/><library name="metadata-extractor-2.4.0-beta-1.jar"/>- <library name="pdfbox-0.8.0-incubating.jar"/>+ <library name="pdfbox-1.1.0.jar"/><library name="poi-3.6.jar"/><library name="poi-ooxml-3.6.jar"/><library name="poi-ooxml-schemas-3.6.jar"/><library name="poi-scratchpad-3.6.jar"/><library name="tagsoup-1.2.jar"/>- <library name="tika-parsers-0.6.jar"/>+ <library name="tika-parsers-0.7.jar"/><library name="xml-apis-1.0.b2.jar"/><library name="xmlbeans-2.3.0.jar"/></runtime>diff --git a/src/plugin/parse-tika/src/java/org/apache/nutch/parse/tika/TikaConfig.java b/src/plugin/parse-tika/src/java/org/apache/nutch/parse/tika/TikaConfig.javaindex 49497ab33..5b3eaf0ab 100644--- a/src/plugin/parse-tika/src/java/org/apache/nutch/parse/tika/TikaConfig.java+++ b/src/plugin/parse-tika/src/java/org/apache/nutch/parse/tika/TikaConfig.java@@ -21,16 +21,22 @@ import java.io.IOException;import java.io.InputStream;import java.net.URL;import java.util.HashMap;+import java.util.Iterator;import java.util.Map;+import javax.imageio.spi.ServiceRegistry;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import org.apache.tika.exception.TikaException;+import org.apache.tika.mime.MediaType;+import org.apache.tika.mime.MimeTypeException;import org.apache.tika.mime.MimeTypes;import org.apache.tika.mime.MimeTypesFactory;+import org.apache.tika.parser.ParseContext;import org.apache.tika.parser.Parser;+import org.mortbay.log.Log;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.Node;@@ -38,143 +44,208 @@ import org.w3c.dom.NodeList;import org.xml.sax.SAXException;/**- * Parse xml config file. Duplicates the Tika equivalent but allows the classes of the parser to be found- * by classloader+ * Parse xml config file.*/-class TikaConfig {-- static final String DEFAULT_CONFIG_LOCATION =- "/org/apache/tika/tika-config.xml";+public class TikaConfig {private final Map<String, Parser> parsers = new HashMap<String, Parser>();- private static MimeTypes mimeTypes;+ private final MimeTypes mimeTypes;++ public TikaConfig(String file) throws TikaException, IOException,+ SAXException {+ this(new File(file));+ }- TikaConfig(String file)- throws TikaException, IOException, SAXException {- this(new File(file));+ public TikaConfig(File file) throws TikaException, IOException,+ SAXException {+ this(getBuilder().parse(file));}- TikaConfig(File file)- throws TikaException, IOException, SAXException {- this(getBuilder().parse(file));+ public TikaConfig(URL url) throws TikaException, IOException, SAXException {+ this(getBuilder().parse(url.toString()));}- TikaConfig(URL url)- throws TikaException, IOException, SAXException {- this(getBuilder().parse(url.toString()));+ public TikaConfig(InputStream stream) throws TikaException, IOException,+ SAXException {+ this(getBuilder().parse(stream));}- TikaConfig(InputStream stream)- throws TikaException, IOException, SAXException {- this(getBuilder().parse(stream));+ /**+ * @deprecated This method will be removed in Apache Tika 1.0+ * @see <a+ * href="https://issues.apache.org/jira/browse/TIKA-275">TIKA-275</a>+ */+ public TikaConfig(InputStream stream, Parser delegate)+ throws TikaException, IOException, SAXException {+ this(stream);}- TikaConfig(Document document) throws TikaException, IOException {- this(document.getDocumentElement());+ public TikaConfig(Document document) throws TikaException, IOException {+ this(document.getDocumentElement());}- TikaConfig(Element element) throws TikaException, IOException {- Element mtr = getChild(element, "mimeTypeRepository");- if (mtr != null) {- mimeTypes = MimeTypesFactory.create(mtr.getAttribute("resource"));- }+ /**+ * @deprecated This method will be removed in Apache Tika 1.0+ * @see <a+ * href="https://issues.apache.org/jira/browse/TIKA-275">TIKA-275</a>+ */+ public TikaConfig(Document document, Parser delegate) throws TikaException,+ IOException {+ this(document);+ }- NodeList nodes = element.getElementsByTagName("parser");- for (int i = 0; i < nodes.getLength(); i++) {- Element node = (Element) nodes.item(i);- String name = node.getAttribute("class");- try {- Class<?> parserClass = Class.forName(name);- Parser parser = (Parser) parserClass.newInstance();+ public TikaConfig(Element element) throws TikaException, IOException {+ Element mtr = getChild(element, "mimeTypeRepository");+ if (mtr != null && mtr.hasAttribute("resource")) {+ mimeTypes = MimeTypesFactory.create(mtr.getAttribute("resource"));+ } else {+ mimeTypes = MimeTypesFactory.create("tika-mimetypes.xml");+ }++ NodeList nodes = element.getElementsByTagName("parser");+ for (int i = 0; i < nodes.getLength(); i++) {+ Element node = (Element) nodes.item(i);+ String name = node.getAttribute("class");++ try {+ Class<?> parserClass = Class.forName(name);+ Object instance = parserClass.newInstance();+ if (!(instance instanceof Parser)) {+ throw new TikaException(+ "Configured class is not a Tika Parser: " + name);+ }+ Parser parser = (Parser) instance;++ NodeList mimes = node.getElementsByTagName("mime");+ if (mimes.getLength() > 0) {+ for (int j = 0; j < mimes.getLength(); j++) {+ parsers.put(getText(mimes.item(j)).trim(), parser);+ }+ } else {+ ParseContext context = new ParseContext();+ for (MediaType type : parser.getSupportedTypes(context)) {+ parsers.put(type.toString(), parser);+ }+ }+ } catch (ClassNotFoundException e) {+ throw new TikaException("Configured parser class not found: "+ + name, e);+ } catch (IllegalAccessException e) {+ throw new TikaException("Unable to access a parser class: "+ + name, e);+ } catch (InstantiationException e) {+ throw new TikaException(+ "Unable to instantiate a parser class: " + name, e);+ }+ }+ }- NodeList mimes = node.getElementsByTagName("mime");- for (int j = 0; j < mimes.getLength(); j++) {- parsers.put(getText(mimes.item(j)).trim(), parser);- }- } catch (Throwable t) {- // TODO: Log warning about an invalid parser configuration- // For now we just ignore this parser class- }- }+ public TikaConfig() throws MimeTypeException, IOException {+ ParseContext context = new ParseContext();+ Iterator<Parser> iterator = ServiceRegistry.lookupProviders(+ Parser.class, this.getClass().getClassLoader());+ while (iterator.hasNext()) {+ Parser parser = iterator.next();+ for (MediaType type : parser.getSupportedTypes(context)) {+ parsers.put(type.toString(), parser);+ }+ }+ mimeTypes = MimeTypesFactory.create("tika-mimetypes.xml");+ }++ /**+ * @deprecated This method will be removed in Apache Tika 1.0+ * @see <a+ * href="https://issues.apache.org/jira/browse/TIKA-275">TIKA-275</a>+ */+ public TikaConfig(Element element, Parser delegate) throws TikaException,+ IOException {+ this(element);}private String getText(Node node) {- if (node.getNodeType() == Node.TEXT_NODE) {- return node.getNodeValue();- } else if (node.getNodeType() == Node.ELEMENT_NODE) {- StringBuilder builder = new StringBuilder();- NodeList list = node.getChildNodes();- for (int i = 0; i < list.getLength(); i++) {- builder.append(getText(list.item(i)));- }- return builder.toString();- } else {- return "";- }+ if (node.getNodeType() == Node.TEXT_NODE) {+ return node.getNodeValue();+ } else if (node.getNodeType() == Node.ELEMENT_NODE) {+ StringBuilder builder = new StringBuilder();+ NodeList list = node.getChildNodes();+ for (int i = 0; i < list.getLength(); i++) {+ builder.append(getText(list.item(i)));+ }+ return builder.toString();+ } else {+ return "";+ }}/**- * Returns the parser instance configured for the given MIME type.- * Returns <code>null</code> if the given MIME type is unknown.- *- * @param mimeType MIME type+ * Returns the parser instance configured for the given MIME type. Returns+ * <code>null</code> if the given MIME type is unknown.+ *+ * @param mimeType+ * MIME type* @return configured Parser instance, or <code>null</code>*/- Parser getParser(String mimeType) {- return parsers.get(mimeType);+ public Parser getParser(String mimeType) {+ return parsers.get(mimeType);}- Map<String, Parser> getParsers() {- return parsers;+ public Map<String, Parser> getParsers() {+ return parsers;}- MimeTypes getMimeRepository(){- return mimeTypes;+ public MimeTypes getMimeRepository() {+ return mimeTypes;}/**- * Provides a default configuration (TikaConfig). Currently creates a- * new instance each time it's called; we may be able to have it- * return a shared instance once it is completely immutable.- *+ * Provides a default configuration (TikaConfig). Currently creates a new+ * instance each time it's called; we may be able to have it return a shared+ * instance once it is completely immutable.+ ** @return default configuration*/- static TikaConfig getDefaultConfig() {- try {- InputStream stream =- TikaConfig.class.getResourceAsStream(DEFAULT_CONFIG_LOCATION);- return new TikaConfig(stream);- } catch (IOException e) {- throw new RuntimeException(- "Unable to read default configuration", e);- } catch (SAXException e) {- throw new RuntimeException(- "Unable to parse default configuration", e);- } catch (TikaException e) {- throw new RuntimeException(- "Unable to access default configuration", e);- }+ public static TikaConfig getDefaultConfig() {+ try {+ return new TikaConfig();+ } catch (IOException e) {+ throw new RuntimeException("Unable to read default configuration",+ e);+ } catch (TikaException e) {+ throw new RuntimeException(+ "Unable to access default configuration", e);+ }+ }++ /**+ * @deprecated This method will be removed in Apache Tika 1.0+ * @see <a+ * href="https://issues.apache.org/jira/browse/TIKA-275">TIKA-275</a>+ */+ public static TikaConfig getDefaultConfig(Parser delegate)+ throws TikaException {+ return getDefaultConfig();}private static DocumentBuilder getBuilder() throws TikaException {- try {- return DocumentBuilderFactory.newInstance().newDocumentBuilder();- } catch (ParserConfigurationException e) {- throw new TikaException("XML parser not available", e);- }+ try {+ return DocumentBuilderFactory.newInstance().newDocumentBuilder();+ } catch (ParserConfigurationException e) {+ throw new TikaException("XML parser not available", e);+ }}private static Element getChild(Element element, String name) {- Node child = element.getFirstChild();- while (child != null) {- if (child.getNodeType() == Node.ELEMENT_NODE- && name.equals(child.getNodeName())) {- return (Element) child;- }- child = child.getNextSibling();- }- return null;- }--}+ Node child = element.getFirstChild();+ while (child != null) {+ if (child.getNodeType() == Node.ELEMENT_NODE+ && name.equals(child.getNodeName())) {+ return (Element) child;+ }+ child = child.getNextSibling();+ }+ return null;+ }++}\ No newline at end of filediff --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.javaindex 0fbfa9b08..a4f57488a 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@@ -170,6 +170,8 @@ public class TikaParser implements org.apache.nutch.parse.Parser {this.tikaConfig = null;// do we want a custom Tika configuration file+ // deprecated since Tika 0.7 which is based on+ // a service provider based configurationString customConfFile = conf.get("tika.config.file");if (customConfFile != null) {try {