You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by si...@apache.org on 2006/08/17 18:40:50 UTC
svn commit: r432292 - in /lucene/nutch/trunk/src:
java/org/apache/nutch/protocol/ProtocolFactory.java
test/org/apache/nutch/protocol/TestProtocolFactory.java
Author: siren
Date: Thu Aug 17 09:40:50 2006
New Revision: 432292
URL: http://svn.apache.org/viewvc?rev=432292&view=rev
Log:
Allow protocol plugins to contain implementation for more than one protocol.
Modified:
lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java
lucene/nutch/trunk/src/test/org/apache/nutch/protocol/TestProtocolFactory.java
Modified: lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java?rev=432292&r1=432291&r2=432292&view=diff
==============================================================================
--- lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java (original)
+++ lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java Thu Aug 17 09:40:50 2006
@@ -27,40 +27,45 @@
import org.apache.hadoop.conf.Configuration;
-/**
- * Creates and caches {@link Protocol} plugins. Protocol plugins should
- * define the attribute "protocolName" with the name of the protocol that they
- * implement. Configuration object is used for caching. Cache key is
- * constructed from appending protocol name (eg. http) to
- * constant {@link Protocol#X_POINT_ID).
+/**
+ * Creates and caches {@link Protocol} plugins. Protocol plugins should define
+ * the attribute "protocolName" with the name of the protocol that they
+ * implement. Configuration object is used for caching. Cache key is constructed
+ * from appending protocol name (eg. http) to constant
+ * {@link Protocol#X_POINT_ID).
*/
public class ProtocolFactory {
public static final Log LOG = LogFactory.getLog(ProtocolFactory.class);
private ExtensionPoint extensionPoint;
+
private Configuration conf;
public ProtocolFactory(Configuration conf) {
- this.conf = conf;
- this.extensionPoint = PluginRepository.get(conf)
- .getExtensionPoint(Protocol.X_POINT_ID);
- if (this.extensionPoint == null) {
- throw new RuntimeException("x-point " + Protocol.X_POINT_ID + " not found.");
- }
- }
+ this.conf = conf;
+ this.extensionPoint = PluginRepository.get(conf).getExtensionPoint(
+ Protocol.X_POINT_ID);
+ if (this.extensionPoint == null) {
+ throw new RuntimeException("x-point " + Protocol.X_POINT_ID
+ + " not found.");
+ }
+ }
/**
- * Returns the appropriate {@link Protocol} implementation for a url.
- * @param urlString Url String
+ * Returns the appropriate {@link Protocol} implementation for a url.
+ *
+ * @param urlString
+ * Url String
* @return
- * @throws ProtocolNotFound when Protocol can not be found for urlString
+ * @throws ProtocolNotFound
+ * when Protocol can not be found for urlString
*/
public Protocol getProtocol(String urlString) throws ProtocolNotFound {
try {
URL url = new URL(urlString);
String protocolName = url.getProtocol();
- String cacheId=Protocol.X_POINT_ID + protocolName;
+ String cacheId = Protocol.X_POINT_ID + protocolName;
if (protocolName == null)
throw new ProtocolNotFound(urlString);
@@ -86,17 +91,25 @@
}
}
- private Extension findExtension(String name)
- throws PluginRuntimeException {
+ private Extension findExtension(String name) throws PluginRuntimeException {
Extension[] extensions = this.extensionPoint.getExtensions();
for (int i = 0; i < extensions.length; i++) {
Extension extension = extensions[i];
- if (name.equals(extension.getAttribute("protocolName")))
+ if (contains(name, extension.getAttribute("protocolName")))
return extension;
}
return null;
}
+
+ boolean contains(String what, String where){
+ String parts[]=where.split("[, ]");
+ for(int i=0;i<parts.length;i++) {
+ if(parts[i].equals(what)) return true;
+ }
+ return false;
+ }
+
}
Modified: lucene/nutch/trunk/src/test/org/apache/nutch/protocol/TestProtocolFactory.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/src/test/org/apache/nutch/protocol/TestProtocolFactory.java?rev=432292&r1=432291&r2=432292&view=diff
==============================================================================
--- lucene/nutch/trunk/src/test/org/apache/nutch/protocol/TestProtocolFactory.java (original)
+++ lucene/nutch/trunk/src/test/org/apache/nutch/protocol/TestProtocolFactory.java Thu Aug 17 09:40:50 2006
@@ -23,15 +23,16 @@
public class TestProtocolFactory extends TestCase {
Configuration conf;
+ ProtocolFactory factory;
protected void setUp() throws Exception {
conf = NutchConfiguration.create();
conf.set("plugin.includes", ".*");
conf.set("http.agent.name", "test-bot");
+ factory=new ProtocolFactory(conf);
}
public void testGetProtocol(){
- ProtocolFactory factory=new ProtocolFactory(conf);
//non existing protocol
try {
@@ -64,6 +65,14 @@
} catch (ProtocolNotFound e) {
fail("Must not throw any exception");
}
+ }
+
+ public void testContains(){
+ assertTrue(factory.contains("http", "http"));
+ assertTrue(factory.contains("http", "http,ftp"));
+ assertTrue(factory.contains("http", " http , ftp"));
+ assertTrue(factory.contains("smb", "ftp,smb,http"));
+ assertFalse(factory.contains("smb", "smbb"));
}
}