Author: jerome
Date: Mon Oct  3 08:56:43 2005
New Revision: 293370

URL: http://svn.apache.org/viewcvs?rev=293370&view=rev
Log:
Change the way the parse-plugin.xml file is loaded (MalformedURLException 
reported by Earl Cahill)

Modified:
    lucene/nutch/trunk/src/java/org/apache/nutch/parse/ParsePluginsReader.java
    lucene/nutch/trunk/src/test/org/apache/nutch/parse/TestParserFactory.java

Modified: 
lucene/nutch/trunk/src/java/org/apache/nutch/parse/ParsePluginsReader.java
URL: 
http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/java/org/apache/nutch/parse/ParsePluginsReader.java?rev=293370&r1=293369&r2=293370&view=diff
==============================================================================
--- lucene/nutch/trunk/src/java/org/apache/nutch/parse/ParsePluginsReader.java 
(original)
+++ lucene/nutch/trunk/src/java/org/apache/nutch/parse/ParsePluginsReader.java 
Mon Oct  3 08:56:43 2005
@@ -54,14 +54,17 @@
   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 @@
     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);
     

Modified: 
lucene/nutch/trunk/src/test/org/apache/nutch/parse/TestParserFactory.java
URL: 
http://svn.apache.org/viewcvs/lucene/nutch/trunk/src/test/org/apache/nutch/parse/TestParserFactory.java?rev=293370&r1=293369&r2=293370&view=diff
==============================================================================
--- lucene/nutch/trunk/src/test/org/apache/nutch/parse/TestParserFactory.java 
(original)
+++ lucene/nutch/trunk/src/test/org/apache/nutch/parse/TestParserFactory.java 
Mon Oct  3 08:56:43 2005
@@ -37,30 +37,13 @@
  */
 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. */


Reply via email to