Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Remove hard-coded content-type checking in parsers

Jerome Charron9b2a1e9c86b6
diff --git a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HtmlParser.java b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HtmlParser.java
index 2c62f965f..f8feb9c36 100644
--- a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HtmlParser.java
+++ b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HtmlParser.java
@@ -109,17 +109,12 @@ public class HtmlParser implements Parser {
Outlink[] outlinks = new Outlink[0];
ContentProperties metadata = new ContentProperties();
- // check that contentType is one we can handle
- String contentType = content.getContentType();
- if (!"".equals(contentType) && !contentType.startsWith("text/html"))
- return new ParseStatus(ParseStatus.FAILED, ParseStatus.FAILED_INVALID_FORMAT,
- "Content-Type not text/html: " + contentType).getEmptyParse();
-
// parse the content
DocumentFragment root;
try {
byte[] contentInOctets = content.getContent();
InputSource input = new InputSource(new ByteArrayInputStream(contentInOctets));
+ String contentType = content.getMetadata().getProperty("Content-Type");
String encoding = StringUtil.parseCharacterEncoding(contentType);
if (encoding!=null) {
metadata.put("OriginalCharEncoding", encoding);
diff --git a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/MSPowerPointParser.java b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/MSPowerPointParser.java
index e3cd2a76a..a5c1e23f5 100644
--- a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/MSPowerPointParser.java
+++ b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/MSPowerPointParser.java
@@ -89,15 +89,6 @@ public class MSPowerPointParser implements Parser {
*/
public Parse getParse(final Content content) {
- // check that contentType is one we can handle
- final String contentType = content.getContentType();
-
- if (contentType != null && !contentType.startsWith(MIME_TYPE)) {
- return new ParseStatus(ParseStatus.FAILED,
- ParseStatus.FAILED_INVALID_FORMAT, "Content-Type is not ["
- + MIME_TYPE + "] was: " + contentType).getEmptyParse();
- }
-
String plainText = null;
String title = null;
Outlink[] outlinks = null;
@@ -170,4 +161,4 @@ public class MSPowerPointParser implements Parser {
}
}
-}
\ No newline at end of file
+}
diff --git a/src/plugin/parse-msword/src/java/org/apache/nutch/parse/msword/MSWordParser.java b/src/plugin/parse-msword/src/java/org/apache/nutch/parse/msword/MSWordParser.java
index ad60619be..e009b739b 100644
--- a/src/plugin/parse-msword/src/java/org/apache/nutch/parse/msword/MSWordParser.java
+++ b/src/plugin/parse-msword/src/java/org/apache/nutch/parse/msword/MSWordParser.java
@@ -57,12 +57,6 @@ public class MSWordParser implements Parser {
public Parse getParse(Content content) {
- // check that contentType is one we can handle
- String contentType = content.getContentType();
- if (contentType != null && !contentType.startsWith("application/msword"))
- return new ParseStatus(ParseStatus.FAILED, ParseStatus.FAILED_INVALID_FORMAT,
- "Content-Type not application/msword: " + contentType).getEmptyParse();
-
String text = null;
String title = null;
Properties properties = null;
diff --git a/src/plugin/parse-pdf/src/java/org/apache/nutch/parse/pdf/PdfParser.java b/src/plugin/parse-pdf/src/java/org/apache/nutch/parse/pdf/PdfParser.java
index d521bef06..bc83439f5 100644
--- a/src/plugin/parse-pdf/src/java/org/apache/nutch/parse/pdf/PdfParser.java
+++ b/src/plugin/parse-pdf/src/java/org/apache/nutch/parse/pdf/PdfParser.java
@@ -84,12 +84,6 @@ public class PdfParser implements Parser {
public Parse getParse(Content content) {
- // check that contentType is one we can handle
- String contentType = content.getContentType();
- if (contentType != null && !contentType.startsWith("application/pdf"))
- return new ParseStatus(ParseStatus.FAILED, ParseStatus.FAILED_INVALID_FORMAT,
- "Content-Type not application/pdf: " + contentType).getEmptyParse();
-
// in memory representation of pdf file
PDDocument pdf = null;
diff --git a/src/plugin/parse-rss/src/java/org/apache/nutch/parse/rss/RSSParser.java b/src/plugin/parse-rss/src/java/org/apache/nutch/parse/rss/RSSParser.java
index b7bf0d37d..c0d9f8f89 100644
--- a/src/plugin/parse-rss/src/java/org/apache/nutch/parse/rss/RSSParser.java
+++ b/src/plugin/parse-rss/src/java/org/apache/nutch/parse/rss/RSSParser.java
@@ -101,15 +101,6 @@ public class RSSParser implements Parser {
*/
public Parse getParse(Content content) {
- // check that contentType is one we can handle
- String contentType = content.getContentType();
- if (contentType != null
- && (!contentType.startsWith("text/xml") && !contentType
- .startsWith("application/rss+xml")))
- return new ParseStatus(ParseStatus.FAILED_INVALID_FORMAT,
- "Content-Type not text/xml or application/rss+xml: "
- + contentType).getEmptyParse();
-
List theRSSChannels = null;
try {
diff --git a/src/plugin/parse-zip/src/java/org/apache/nutch/parse/zip/ZipParser.java b/src/plugin/parse-zip/src/java/org/apache/nutch/parse/zip/ZipParser.java
index 359afea72..e1709a7a4 100644
--- a/src/plugin/parse-zip/src/java/org/apache/nutch/parse/zip/ZipParser.java
+++ b/src/plugin/parse-zip/src/java/org/apache/nutch/parse/zip/ZipParser.java
@@ -48,13 +48,6 @@ public class ZipParser implements Parser{
public Parse getParse(final Content content) {
- // check that contentType is one we can handle
- final String contentType = content.getContentType();
- if (contentType != null && !contentType.startsWith("application/zip")) {
- return new ParseStatus(ParseStatus.FAILED, ParseStatus.FAILED_INVALID_FORMAT,
- "Content-Type not application/zip: " + contentType).getEmptyParse();
- }
-
String resultText = null;
String resultTitle = null;
Outlink[] outlinks = null;