Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

commit to address NUTCH-1097 and update to changes.txt

Lewis John McGibbney0a8dace9503f
diff --git a/CHANGES.txt b/CHANGES.txt
index 98188c4bc..c674a74de 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
Release 1.4 - Current development
+* NUTCH-1097 application/xhtml+xml should be enabled in plugin.xml of parse-html; allow multiple mimetypes for plugin.xml (Ferdy via lewismc)
+
* NUTCH-797 Fix parse-tika and parse-html to use relative URL resolution per RFC-3986
(Robert Hohman, ab)
diff --git a/src/java/org/apache/nutch/parse/ParserFactory.java b/src/java/org/apache/nutch/parse/ParserFactory.java
index 15aabe8f3..5f00d8776 100644
--- a/src/java/org/apache/nutch/parse/ParserFactory.java
+++ b/src/java/org/apache/nutch/parse/ParserFactory.java
@@ -343,14 +343,13 @@ public final class ParserFactory {
// NotMappedParserException
for (int i=0; i<extensions.length; i++) {
- if (extensions[i].getAttribute("contentType") != null
- && extensions[i].getAttribute("contentType").equals(
- contentType)) {
- extList.add(extensions[i]);
- }
- else if ("*".equals(extensions[i].getAttribute("contentType"))){
+ if ("*".equals(extensions[i].getAttribute("contentType"))){
extList.add(0, extensions[i]);
}
+ else if (extensions[i].getAttribute("contentType") != null
+ && contentType.matches(escapeContentType(extensions[i].getAttribute("contentType")))) {
+ extList.add(extensions[i]);
+ }
}
if (extList.size() > 0) {
@@ -377,10 +376,18 @@ public final class ParserFactory {
return (extList.size() > 0) ? extList : null;
}
+
+ private String escapeContentType(String contentType) {
+ // Escapes contentType in order to use as a regex
+ // (and keep backwards compatibility).
+ // This enables to accept multiple types for a single parser.
+ return contentType.replace("+", "\\+").replace(".", "\\.");
+ }
private boolean match(Extension extension, String id, String type) {
return ((id.equals(extension.getId())) &&
- (type.equals(extension.getAttribute("contentType")) || extension.getAttribute("contentType").equals("*") ||
+ (extension.getAttribute("contentType").equals("*") ||
+ type.matches(escapeContentType(extension.getAttribute("contentType"))) ||
type.equals(DEFAULT_PLUGIN)));
}
diff --git a/src/plugin/parse-html/plugin.xml b/src/plugin/parse-html/plugin.xml
index c154c53a7..3be70c3ea 100755
--- a/src/plugin/parse-html/plugin.xml
+++ b/src/plugin/parse-html/plugin.xml
@@ -39,7 +39,7 @@
<implementation id="org.apache.nutch.parse.html.HtmlParser"
class="org.apache.nutch.parse.html.HtmlParser">
- <parameter name="contentType" value="text/html"/>
+ <parameter name="contentType" value="text/html|application/xhtml+xml"/>
<parameter name="pathSuffix" value=""/>
</implementation>