incubator-droids-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1417023 - in /incubator/droids/branches/0.2.x-cleanup/droids-core/src: main/java/org/apache/droids/core/ main/java/org/apache/droids/exception/ main/java/org/apache/droids/filter/ main/java/org/apache/droids/helper/factories/ test/java/org...
Date Tue, 04 Dec 2012 16:33:37 GMT
Author: tobr
Date: Tue Dec  4 16:33:34 2012
New Revision: 1417023

URL: http://svn.apache.org/viewvc?rev=1417023&view=rev
Log:
changed Validators to Filters

Added:
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/exception/DefaultTaskExceptionHandler.java
      - copied, changed from r1417006, incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/DefaultTaskExceptionHandler.java
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/ChainTaskFilter.java
      - copied, changed from r1417006, incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/ChainTaskValidator.java
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/Filter.java
      - copied, changed from r1417006, incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/URLFilter.java
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/MaxDepthTaskFilter.java
      - copied, changed from r1417006, incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/MaxDepthTaskValidator.java
Removed:
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/DefaultTaskExceptionHandler.java
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/ChainTaskValidator.java
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/MaxDepthTaskValidator.java
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/TaskValidator.java
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/URLFilter.java
Modified:
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/AlreadyVisitedFilter.java
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/HostFilter.java
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/RegexURLFilter.java
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/package-info.java
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/helper/factories/URLFiltersFactory.java
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/TestSimpleQueue.java

Copied: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/exception/DefaultTaskExceptionHandler.java
(from r1417006, incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/DefaultTaskExceptionHandler.java)
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/exception/DefaultTaskExceptionHandler.java?p2=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/exception/DefaultTaskExceptionHandler.java&p1=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/DefaultTaskExceptionHandler.java&r1=1417006&r2=1417023&rev=1417023&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/core/DefaultTaskExceptionHandler.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/exception/DefaultTaskExceptionHandler.java
Tue Dec  4 16:33:34 2012
@@ -14,12 +14,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.droids.core;
+package org.apache.droids.exception;
 
 import java.io.IOException;
 
-import org.apache.droids.exception.TaskExceptionHandler;
-import org.apache.droids.exception.TaskExceptionResult;
+import org.apache.droids.core.DroidsException;
 
 
 public class DefaultTaskExceptionHandler implements TaskExceptionHandler {

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/AlreadyVisitedFilter.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/AlreadyVisitedFilter.java?rev=1417023&r1=1417022&r2=1417023&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/AlreadyVisitedFilter.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/AlreadyVisitedFilter.java
Tue Dec  4 16:33:34 2012
@@ -21,13 +21,14 @@ import java.net.URISyntaxException;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.droids.core.Task;
 import org.apache.http.client.utils.URIUtils;
 
 /**
  * 
  * @version 1.0
  */
-public class AlreadyVisitedFilter implements URLFilter {
+public class AlreadyVisitedFilter<T extends Task> implements Filter<T> {
 
   private Set<URI> visited;
 
@@ -37,16 +38,16 @@ public class AlreadyVisitedFilter implem
   }
 
   @Override
-  public String filter(final String url) {
+  public Task filter(final T task) {
     try {
-      URI uri = new URI(url);
+      URI uri = task.getURI();
       URI key = URIUtils.createURI(
           uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), null, null);
       synchronized (this.visited)
       {
         if (!this.visited.contains(key)) {
           this.visited.add(key);
-          return url;
+          return task;
         } else {
           return null;
         }

Copied: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/ChainTaskFilter.java
(from r1417006, incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/ChainTaskValidator.java)
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/ChainTaskFilter.java?p2=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/ChainTaskFilter.java&p1=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/ChainTaskValidator.java&r1=1417006&r2=1417023&rev=1417023&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/ChainTaskValidator.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/ChainTaskFilter.java
Tue Dec  4 16:33:34 2012
@@ -24,28 +24,27 @@ import org.apache.droids.core.Task;
 /**
  * A chain task validator executes a chain of unique validators
  */
-public final class ChainTaskValidator<T extends Task> implements
-    TaskValidator<T> {
-  private final Set<TaskValidator<T>> validatorChain;
+public final class ChainTaskFilter<T extends Task> implements Filter<T> {
+  private final Set<Filter<T>> filterChain;
 
-  public ChainTaskValidator() {
+  public ChainTaskFilter() {
     super();
 
-    this.validatorChain = new LinkedHashSet<TaskValidator<T>>();
+    this.filterChain = new LinkedHashSet<Filter<T>>();
   }
 
   @Override
-  public boolean validate(final T task) {
-    for (final TaskValidator<T> taskValidator : this.validatorChain) {
-      if (!taskValidator.validate(task)) {
-        return false; 
+  public Task filter(final T task) {
+    for (final Filter<T> filter : this.filterChain) {
+      if (filter.filter(task) == null) {
+        return null; 
       }
     }
-    return true;
+    return task;
   }
 
-  public void addTaskValidator(final TaskValidator<T> taskValidator) {
-    this.validatorChain.add(taskValidator);
+  public void addFilter(final Filter<T> filter) {
+    this.filterChain.add(filter);
   }
 
 }

Copied: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/Filter.java
(from r1417006, incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/URLFilter.java)
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/Filter.java?p2=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/Filter.java&p1=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/URLFilter.java&r1=1417006&r2=1417023&rev=1417023&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/URLFilter.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/Filter.java
Tue Dec  4 16:33:34 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.droids.filter;
 
+import org.apache.droids.core.Task;
+
 /**
  * Filter to limit the urls that we want to allow in our queue.
  * <p>
@@ -25,7 +27,7 @@ package org.apache.droids.filter;
  * @version 1.0
  * 
  */
-public interface URLFilter {
+public interface Filter<T extends Task> {
 
   /**
    * Transforms the URL: can pass the original URL through or "delete" the URL
@@ -35,5 +37,5 @@ public interface URLFilter {
    *                the url to filter
    * @return null if the filter excludes the url or the url again if allowed
    */
-  String filter(String urlString);
+  Task filter(T task);
 }

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/HostFilter.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/HostFilter.java?rev=1417023&r1=1417022&r2=1417023&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/HostFilter.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/HostFilter.java
Tue Dec  4 16:33:34 2012
@@ -16,49 +16,43 @@
  */
 package org.apache.droids.filter;
 
-import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.droids.core.Task;
 
 /**
- * Simple hostname based implementation of {@link URLFilter).
+ * Simple hostname based implementation of {@link Filter).
  * 
  * @version 1.0
  */
-public class HostFilter implements URLFilter {
+public class HostFilter<T extends Task> implements Filter<T> {
 
-  private Set<String> allowedHosts;
+	private Set<String> allowedHosts;
 
-  public HostFilter(final Set<String> allowedHosts) {
-    super();
-    this.allowedHosts = new HashSet<String>();
-    if (allowedHosts != null) {
-      this.allowedHosts.addAll(allowedHosts);
-    }
-  }
-  
-  public HostFilter(final String allowedHost) {
-    super();
-    this.allowedHosts = new HashSet<String>();
-    if (allowedHost != null) {
-      this.allowedHosts.add(allowedHost);
-    }
-  }
-
-  @Override
-  public String filter(final String url) {
-    try {
-      URI uri = new URI(url);
-      if (this.allowedHosts.contains(uri.getHost())) {
-        return url;
-      } else {
-        return null;
-      }
-    } catch (URISyntaxException ex) {
-      return null;
-    }
-  }
+	public HostFilter(final Set<String> allowedHosts) {
+		super();
+		this.allowedHosts = new HashSet<String>();
+		if (allowedHosts != null) {
+			this.allowedHosts.addAll(allowedHosts);
+		}
+	}
+
+	public HostFilter(final String allowedHost) {
+		super();
+		this.allowedHosts = new HashSet<String>();
+		if (allowedHost != null) {
+			this.allowedHosts.add(allowedHost);
+		}
+	}
+
+	@Override
+	public Task filter(final T task) {
+		if (this.allowedHosts.contains(task.getURI().getHost())) {
+			return task;
+		} else {
+			return null;
+		}
+	}
 
 }

Copied: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/MaxDepthTaskFilter.java
(from r1417006, incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/MaxDepthTaskValidator.java)
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/MaxDepthTaskFilter.java?p2=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/MaxDepthTaskFilter.java&p1=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/MaxDepthTaskValidator.java&r1=1417006&r2=1417023&rev=1417023&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/MaxDepthTaskValidator.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/MaxDepthTaskFilter.java
Tue Dec  4 16:33:34 2012
@@ -21,23 +21,23 @@ import org.apache.droids.core.Task;
 /**
  * A simple task validator that honors task depth.
  */
-public class MaxDepthTaskValidator<T extends Task> implements TaskValidator<T>
{
+public class MaxDepthTaskFilter<T extends Task> implements Filter<T> {
   private int maxDepth = -1;
 
-  public MaxDepthTaskValidator() {
+  public MaxDepthTaskFilter() {
     super();
   }
 
-  public MaxDepthTaskValidator(int maxDepth) {
+  public MaxDepthTaskFilter(int maxDepth) {
     this.maxDepth = maxDepth;
   }
 
   @Override
-  public boolean validate(final T task) {
+  public Task filter(final T task) {
     if (maxDepth > 0 && task.getDepth() > maxDepth) {
-      return false;
+      return null;
     }
-    return true;
+    return task;
   }
 
   public int getMaxDepth() {

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/RegexURLFilter.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/RegexURLFilter.java?rev=1417023&r1=1417022&r2=1417023&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/RegexURLFilter.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/RegexURLFilter.java
Tue Dec  4 16:33:34 2012
@@ -25,6 +25,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.regex.Pattern;
 
+import org.apache.droids.core.Task;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -35,7 +36,7 @@ import org.slf4j.LoggerFactory;
  * @version 1.0
  * 
  */
-public class RegexURLFilter implements URLFilter {
+public class RegexURLFilter<T extends Task> implements Filter<T> {
 
   private static final Logger LOG = LoggerFactory.getLogger(RegexURLFilter.class);
 
@@ -66,11 +67,11 @@ public class RegexURLFilter implements U
    * @see org.apache.droids.api.URLFilter#filter(java.lang.String)
    */
   @Override
-  public String filter(String url) {
+  public Task filter(T task) {
     synchronized (rules) {
       for (RegexRule rule : rules) {
-        if (rule.match(url)) {
-          return rule.accept() ? url : null;
+        if (rule.match(task.getURI().toString())) {
+          return rule.accept() ? task : null;
         }
       }
     }

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/package-info.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/package-info.java?rev=1417023&r1=1417022&r2=1417023&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/package-info.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/package-info.java
Tue Dec  4 16:33:34 2012
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 /**
- * This package contains various helper for the work with protocols and network communication.
+ * This package contains filter for filtering or changing tasks of the droids.
  */
 package org.apache.droids.filter;
 

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/helper/factories/URLFiltersFactory.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/helper/factories/URLFiltersFactory.java?rev=1417023&r1=1417022&r2=1417023&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/helper/factories/URLFiltersFactory.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/helper/factories/URLFiltersFactory.java
Tue Dec  4 16:33:34 2012
@@ -16,9 +16,8 @@
  */
 package org.apache.droids.helper.factories;
 
-import java.net.URI;
-
-import org.apache.droids.filter.URLFilter;
+import org.apache.droids.core.Task;
+import org.apache.droids.filter.Filter;
 
 /**
  * Factory that will traverse all registered filter and execute them.
@@ -26,55 +25,54 @@ import org.apache.droids.filter.URLFilte
  * @version 1.0
  * 
  */
-public class URLFiltersFactory extends GenericFactory<URLFilter> {
+public class URLFiltersFactory extends GenericFactory<Filter> {
 
-  /**
-   * Run all defined filters. Assume logical AND.
-   * 
-   * @param urlString -
-   *                url to test
-   * @return true if filter plugin accept the url, false if excluded.
-   */
-  public boolean accept(URI uri) {
-  	if (uri == null) {
-  		return false;
-  	}
-  		
-    for (String key : getMap().keySet()) {
-      if(!accept(uri.toString(), key)) {
-      	return false;
-      }
-    }
-    return true;
-  }
-
-  /**
-   * Run a specific filter class.
-   * 
-   * @param urlString -
-   *                url to test
-   * @param filterName -
-   *                name of the specific filter class.
-   * @return true if filter plugin accept the url, false if excluded.
-   */
-  public boolean accept(String urlString, String filterName) {
-    if (urlString == null ||
-    		doFilter(urlString, filterName) == null) {
-      return false;
-    }
-    return true;
-  }
-
-  /**
-   * Check string against filters list
-   * 
-   * @param urlString -
-   *                url to test
-   * @param filterName -
-   *                name of the specific filter class.
-   * @return the URL if it's allowed, NULL otherwise
-   */
-	protected String doFilter(String urlString, String filterName) {
-	  return getMap().get(filterName).filter(urlString);
-  }
+	/**
+	 * Run all defined filters. Assume logical AND.
+	 * 
+	 * @param task
+	 *            the current Task
+	 * @return true if filter plugin accept the url, false if excluded.
+	 */
+	public boolean accept(Task task) {
+		if (task == null) {
+			return false;
+		}
+
+		for (String key : getMap().keySet()) {
+			if (!accept(task, key)) {
+				return false;
+			}
+		}
+		return true;
+	}
+
+	/**
+	 * Run a specific filter class.
+	 * 
+	 * @param task
+	 *            the task to test
+	 * @param filterName
+	 *            - name of the specific filter class.
+	 * @return true if filter plugin accept the url, false if excluded.
+	 */
+	public boolean accept(Task task, String filterName) {
+		if (task == null || doFilter(task, filterName) == null) {
+			return false;
+		}
+		return true;
+	}
+
+	/**
+	 * Check string against filters list
+	 * 
+	 * @param task
+	 *            - task to test
+	 * @param filterName
+	 *            - name of the specific filter class.
+	 * @return the URL if it's allowed, NULL otherwise
+	 */
+	protected Task doFilter(Task task, String filterName) {
+		return getMap().get(filterName).filter(task);
+	}
 }

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/TestSimpleQueue.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/TestSimpleQueue.java?rev=1417023&r1=1417022&r2=1417023&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/TestSimpleQueue.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/TestSimpleQueue.java
Tue Dec  4 16:33:34 2012
@@ -20,18 +20,18 @@ import java.io.File;
 
 import junit.framework.Assert;
 
-import org.apache.droids.filter.MaxDepthTaskValidator;
+import org.apache.droids.filter.MaxDepthTaskFilter;
 import org.apache.droids.robot.walker.FileTask;
 import org.junit.Before;
 import org.junit.Test;
 
 public class TestSimpleQueue {
 
-	MaxDepthTaskValidator<FileTask> validator;
+	MaxDepthTaskFilter<FileTask> validator;
 
 	@Before
 	public final void initialize() {
-		validator = new MaxDepthTaskValidator<FileTask>();
+		validator = new MaxDepthTaskFilter<FileTask>();
 		validator.setMaxDepth(5);
 	}
 



Mime
View raw message