Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Change the way the parse-plugin.xml file is loaded (MalformedURLException reported by Earl Cahill)

Jerome Charron8736631610a1
diff --git a/src/java/org/apache/nutch/parse/ParsePluginsReader.java b/src/java/org/apache/nutch/parse/ParsePluginsReader.java
index 60ead74bf..4684bdba7 100644
--- a/src/java/org/apache/nutch/parse/ParsePluginsReader.java
+++ b/src/java/org/apache/nutch/parse/ParsePluginsReader.java
@@ -54,14 +54,17 @@ public class ParsePluginsReader {
public static final Logger LOG =
LogFormatter.getLogger(ParsePluginsReader.class.getName());
+ /** The property name of the parse-plugins location */
+ private static final String PP_FILE_PROP = "parse.plugin.file";
+
/* the parse-plugins file */
- private String fParsePluginsFile = "parse-plugins.xml";
+ private String fParsePluginsFile = null;
+
/**
* Constructs a new ParsePluginsReader
*/
- public ParsePluginsReader() {
- }
+ public ParsePluginsReader() { }
/**
* Reads the <code>parse-plugins.xml</code> file and returns the
@@ -82,33 +85,22 @@ public class ParsePluginsReader {
Document document = null;
InputSource inputSource = null;
- //check to see if the Nutch conf property
- //parse.plugin.file is defined
- String parsePluginFileUrl = NutchConf.get().get("parse.plugin.file");
-
InputStream ppInputStream = null;
-
- if (parsePluginFileUrl != null) {
- URL parsePluginUrl = null;
-
- try {
- parsePluginUrl = new URL(parsePluginFileUrl);
- ppInputStream = parsePluginUrl.openStream();
- } catch (MalformedURLException e) {
- LOG.log(Level.SEVERE,
- "Unable to load parse plugins file from URL ["
- + parsePluginFileUrl + "]", e);
- return null;
- } catch (IOException e) {
- LOG.log(Level.SEVERE,
- "Unable to load parse plugins file from URL ["
- + parsePluginFileUrl + "]", e);
- return null;
- }
- } else {
- ppInputStream = NutchConf.get().getConfResourceAsInputStream(
- fParsePluginsFile);
- }
+ if (fParsePluginsFile != null) {
+ URL parsePluginUrl = null;
+ try {
+ parsePluginUrl = new URL(fParsePluginsFile);
+ ppInputStream = parsePluginUrl.openStream();
+ } catch (Exception e) {
+ LOG.log(Level.SEVERE,
+ "Unable to load parse plugins file from URL " +
+ "[" + fParsePluginsFile + "]", e);
+ return pList;
+ }
+ } else {
+ ppInputStream = NutchConf.get().getConfResourceAsInputStream(
+ NutchConf.get().get(PP_FILE_PROP));
+ }
inputSource = new InputSource(ppInputStream);
diff --git a/src/test/org/apache/nutch/parse/TestParserFactory.java b/src/test/org/apache/nutch/parse/TestParserFactory.java
index 74d188c1b..5cb9a6b26 100644
--- a/src/test/org/apache/nutch/parse/TestParserFactory.java
+++ b/src/test/org/apache/nutch/parse/TestParserFactory.java
@@ -37,30 +37,13 @@ import java.net.MalformedURLException;
*/
public class TestParserFactory extends TestCase {
- private NutchConf conf = null;
public TestParserFactory(String name) { super(name); }
-
- private void initNutchConf(String testFile) {
- // set the Nutch Conf property for parse.plugin.file.url
- // to ${test.src.dir}/org/apache/nutch/parse/parse-plugin-test.xml
- String testParsePluginFileUrl = null;
- try{
- testParsePluginFileUrl = new File(System.getProperty("test.src.dir")
- +"/org/apache/nutch/parse/" + testFile).toURL().toString();
- NutchConf.get().set("parse.plugin.file.url",testParsePluginFileUrl);
- this.conf = NutchConf.get();
- }
- catch(MalformedURLException e){
- throw new RuntimeException("Unable to load parse-plugins.xml file from URL: "+testParsePluginFileUrl);
- }
- }
-
- /** Inits the Test Case: loads the Nutch Conf instance. */
+
+ /** Inits the Test Case with the test parse-plugin file */
protected void setUp() throws Exception {
- if (conf == null) {
- initNutchConf("parse-plugin-test.xml");
- }
+ NutchConf.get().set("parse.plugin.file",
+ "org/apache/nutch/parse/parse-plugin-test.xml");
}
/** Unit test for <code>getParser(String, String)</code> method. */