Apache Nutch is an extensible and scalable web crawler
NUTCH-1083 ParserChecker implements Tools
Julien Nioche8b51303393a9
diff --git a/CHANGES.txt b/CHANGES.txtindex 9ddee3174..e68577143 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogRelease 2.0 - Current Development+* NUTCH-1083 ParserChecker implements Tools (jnioche)+* NUTCH-1004 Do not index empty values for title field (markus)* NUTCH-914 Implement Apache Project Branding Requirements (lewismc via jnioche)diff --git a/src/java/org/apache/nutch/parse/ParserChecker.java b/src/java/org/apache/nutch/parse/ParserChecker.javaindex 3e1db66d3..2046996ca 100644--- a/src/java/org/apache/nutch/parse/ParserChecker.java+++ b/src/java/org/apache/nutch/parse/ParserChecker.java@@ -26,6 +26,8 @@ import org.apache.avro.util.Utf8;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.apache.hadoop.conf.Configuration;+import org.apache.hadoop.util.Tool;+import org.apache.hadoop.util.ToolRunner;import org.apache.nutch.protocol.Content;import org.apache.nutch.protocol.Protocol;import org.apache.nutch.protocol.ProtocolFactory;@@ -39,14 +41,15 @@ import org.apache.nutch.util.NutchConfiguration;* @author John Xing*/-public class ParserChecker {+public class ParserChecker implements Tool {public static final Logger LOG = LoggerFactory.getLogger(ParserChecker.class);+ private Configuration conf;public ParserChecker() {}- public static void main(String[] args) throws Exception {+ public int run(String[] args) throws Exception {boolean dumpText = false;boolean force = false;String contentType = null;@@ -56,7 +59,7 @@ public class ParserChecker {if (args.length == 0) {System.err.println(usage);- System.exit(-1);+ return (-1);}for (int i = 0; i < args.length; i++) {@@ -77,14 +80,13 @@ public class ParserChecker {LOG.info("fetching: " + url);}- Configuration conf = NutchConfiguration.create();ProtocolFactory factory = new ProtocolFactory(conf);Protocol protocol = factory.getProtocol(url);WebPage page = new WebPage();Content content = protocol.getProtocolOutput(url, page).getContent();page.setBaseUrl(new org.apache.avro.util.Utf8(url));page.setContent(ByteBuffer.wrap(content.getContent()));-+if (force) {content.setContentType(contentType);} else {@@ -93,25 +95,25 @@ public class ParserChecker {if (contentType == null) {System.err.println("");- System.exit(-1);+ return (-1);}if (LOG.isInfoEnabled()) {LOG.info("parsing: " + url);LOG.info("contentType: " + contentType);}-+page.setContentType(new Utf8(contentType));Parse parse = new ParseUtil(conf).parse(url, page);- if (parse==null){+ if (parse == null) {System.err.println("Problem with parse - check log");- System.exit(-1);+ return (-1);}-+System.out.print("---------\nUrl\n---------------\n");- System.out.print(url+"\n");+ System.out.print(url + "\n");System.out.print("---------\nMetadata\n---------\n");Map<Utf8, ByteBuffer> metadata = page.getMetadata();StringBuffer sb = new StringBuffer();@@ -130,6 +132,22 @@ public class ParserChecker {System.out.print(parse.getText());}- System.exit(0);+ return 0;+ }++ @Override+ public Configuration getConf() {+ return conf;+ }++ @Override+ public void setConf(Configuration c) {+ conf = c;+ }++ public static void main(String[] args) throws Exception {+ int res = ToolRunner.run(NutchConfiguration.create(), new ParserChecker(),+ args);+ System.exit(res);}}