incubator-droids-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1416986 [2/2] - in /incubator/droids/branches/0.2.x-cleanup/droids-core/src: main/java/org/apache/droids/ main/java/org/apache/droids/api/ main/java/org/apache/droids/core/ main/java/org/apache/droids/delay/ main/java/org/apache/droids/exc...
Date Tue, 04 Dec 2012 15:20:45 GMT
Copied: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/parse/ParserNotFoundException.java
(from r1406628, incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/exception/ParserNotFoundException.java)
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/parse/ParserNotFoundException.java?p2=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/parse/ParserNotFoundException.java&p1=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/exception/ParserNotFoundException.java&r1=1406628&r2=1416986&rev=1416986&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/exception/ParserNotFoundException.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/parse/ParserNotFoundException.java
Tue Dec  4 15:20:17 2012
@@ -14,7 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.droids.exception;
+package org.apache.droids.parse;
+
+import org.apache.droids.core.DroidsException;
 
 /**
  * ParserNotFoundException gives a detailed exception for problems that can

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/parse/ParserNotFoundException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/protocol/file/FileProtocol.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/protocol/file/FileProtocol.java?rev=1416986&r1=1416985&r2=1416986&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/protocol/file/FileProtocol.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/protocol/file/FileProtocol.java
Tue Dec  4 15:20:17 2012
@@ -18,16 +18,13 @@
 */
 package org.apache.droids.protocol.file;
 
-import java.io.BufferedInputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URI;
 
-import org.apache.droids.api.ManagedContentEntity;
-import org.apache.droids.api.Parse;
-import org.apache.droids.api.Protocol;
+import org.apache.droids.core.Protocol;
+import org.apache.droids.core.Task;
+import org.apache.droids.robot.walker.FileTask;
 
 /**
  * 
@@ -46,9 +43,9 @@ public class FileProtocol implements Pro
   }
 
   @Override
-  public ManagedContentEntity load(URI uri) throws IOException {
+  public Task load(URI uri) throws IOException {
     File file = new File(extractLocation(uri));
-    return new FileContentEntity(file);
+    return new FileTask(file);
   }
 
   /**
@@ -65,82 +62,5 @@ public class FileProtocol implements Pro
     }
     return location;
   }
-
-  /**
-   * 
-   * Content entity representing the body of a file.
-   * 
-   */
-  static class FileContentEntity implements ManagedContentEntity {
-    
-	/**
-	 * The file represented by the ContentEntity
-	 */
-    private final File file;
-    /**
-     * The mime-type of the file
-     */
-    private final String mimeType;
-    /**
-     * The charset of the file
-     */
-    private final String charset;
-    /**
-     * The parse object
-     */
-    private Parse parse = null;
-    
-    /**
-     * Creates a new FileContentEntity instance for the give file.
-     * 
-     * @param file 
-     * @throws IOException
-     */
-    public FileContentEntity(File file) throws IOException {
-      super();
-      this.file = file;
-      String s = file.getName().toLowerCase();
-      if (s.endsWith(".html") || s.endsWith(".htm")) {
-        this.mimeType = "text/html";
-        this.charset = "ISO-8859-1";
-      } else if (s.endsWith(".txt")) {
-        this.mimeType = "text/plain";
-        this.charset = "ISO-8859-1";
-      } else {
-        this.mimeType = "binary/octet-stream";
-        this.charset = null;
-      }
-    }
-
-    @Override
-    public InputStream obtainContent() throws IOException {
-      return new BufferedInputStream(new FileInputStream(file));
-    }
-
-    @Override
-    public void finish() {
-    }
-
-    @Override
-    public String getMimeType() {
-      return mimeType;
-    }
-
-    @Override
-    public String getCharset() {
-      return charset;
-    }
-
-    @Override
-    public Parse getParse() {
-      return this.parse;
-    }
-
-    @Override
-    public void setParse(Parse parse) {
-      this.parse = parse;
-    }
-
-  }
   
 }

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/FileTask.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/FileTask.java?rev=1416986&r1=1416985&r2=1416986&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/FileTask.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/FileTask.java
Tue Dec  4 15:20:17 2012
@@ -16,60 +16,72 @@
  */
 package org.apache.droids.robot.walker;
 
+import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.URI;
 import java.util.Date;
 
-import org.apache.droids.api.Task;
+import org.apache.droids.core.Task;
 
+public class FileTask implements Task {
+	private static final long serialVersionUID = 122177113684842951L;
 
-public class FileTask implements Task
-{
-  private static final long serialVersionUID = 122177113684842951L;
-
-  private final Date started;
-  private final int depth;
-  private final File file;
-  private boolean aborted = false;
-  
-  public FileTask( File file, int depth )
-  {
-    this.file = file;
-    this.depth = depth;
-    this.started = new Date();
-  }
-
-  @Override
-  public String getId() {
-    return file.getPath();
-  }
-
-  @Override
-  public Date getTaskDate() {
-    return started;
-  }
-
-  @Override
-  public int getDepth() {
-    return depth;
-  }
-
-  public File getFile() {
-    return file;
-  }
-  
-  @Override
-  public String toString()
-  {
-    return "Task["+depth+"]["+file.getAbsolutePath()+"]";
-  }
-  
-  @Override
-  public void abort() {
-    aborted = true;
-  }
-  
-  @Override
-  public boolean isAborted() {
-    return aborted;
-  }
+	private final Date started;
+	private final int depth;
+	private final File file;
+	private boolean aborted = false;
+
+	public FileTask(File file) {
+		this.file = file;
+		this.depth = 0;
+		this.started = new Date();
+	}
+
+	public FileTask(File file, int depth) {
+		this.file = file;
+		this.depth = depth;
+		this.started = new Date();
+	}
+
+	@Override
+	public URI getURI() {
+		return file.toURI();
+	}
+
+	@Override
+	public Date getTaskDate() {
+		return started;
+	}
+
+	@Override
+	public int getDepth() {
+		return depth;
+	}
+
+	public File getFile() {
+		return file;
+	}
+
+	@Override
+	public String toString() {
+		return "Task[" + depth + "][" + file.getAbsolutePath() + "]";
+	}
+
+	@Override
+	public void abort() {
+		aborted = true;
+	}
+
+	@Override
+	public boolean isAborted() {
+		return aborted;
+	}
+
+	@Override
+	public InputStream getContent() throws FileNotFoundException {
+		return new BufferedInputStream(new FileInputStream(file));
+	}
 }
\ No newline at end of file

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/FileWorker.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/FileWorker.java?rev=1416986&r1=1416985&r2=1416986&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/FileWorker.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/FileWorker.java
Tue Dec  4 15:20:17 2012
@@ -19,7 +19,8 @@ package org.apache.droids.robot.walker;
 import java.io.File;
 
 import java.util.Queue;
-import org.apache.droids.api.Worker;
+
+import org.apache.droids.core.Worker;
 import org.apache.droids.exception.InvalidTaskException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java?rev=1416986&r1=1416985&r2=1416986&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/SimpleWalkingDroid.java
Tue Dec  4 15:20:17 2012
@@ -25,10 +25,10 @@ import com.google.common.base.Preconditi
 import java.util.LinkedList;
 import java.util.Queue;
 
-import org.apache.droids.AbstractDroid;
-import org.apache.droids.api.TaskMaster;
+import org.apache.droids.core.AbstractDroid;
+import org.apache.droids.core.MultiThreadedTaskMaster;
+import org.apache.droids.core.TaskMaster;
 import org.apache.droids.exception.InvalidTaskException;
-import org.apache.droids.impl.MultiThreadedTaskMaster;
 
 public class SimpleWalkingDroid extends AbstractDroid<FileTask> implements WalkingDroid
 {

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/WalkingDroid.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/WalkingDroid.java?rev=1416986&r1=1416985&r2=1416986&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/WalkingDroid.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/robot/walker/WalkingDroid.java
Tue Dec  4 15:20:17 2012
@@ -19,7 +19,7 @@ package org.apache.droids.robot.walker;
 import java.io.File;
 import java.util.Collection;
 
-import org.apache.droids.api.Droid;
+import org.apache.droids.core.Droid;
 
 public interface WalkingDroid extends Droid<FileTask>
 {

Copied: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/util/FileUtil.java
(from r1406628, incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/helper/FileUtil.java)
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/util/FileUtil.java?p2=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/util/FileUtil.java&p1=incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/helper/FileUtil.java&r1=1406628&r2=1416986&rev=1416986&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/helper/FileUtil.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/util/FileUtil.java
Tue Dec  4 15:20:17 2012
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.droids.helper;
+package org.apache.droids.util;
 
 import java.io.File;
 import java.io.IOException;

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/util/FileUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/SimpleTask.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/SimpleTask.java?rev=1416986&view=auto
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/SimpleTask.java
(added)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/SimpleTask.java
Tue Dec  4 15:20:17 2012
@@ -0,0 +1,51 @@
+package org.apache.droids.core;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.Date;
+
+public class SimpleTask implements Task {
+	private URI uri;
+	private int depth;
+	private boolean aborted;
+	
+	private static final long serialVersionUID = 2506491803180939447L;
+
+	public SimpleTask(URI uri, int depth) {
+		this.uri = uri;
+		this.depth = depth;
+		this.aborted = false;
+	}
+	
+	@Override
+	public URI getURI() {
+		return uri;
+	}
+
+	@Override
+	public InputStream getContent() throws IOException {
+		return null;
+	}
+
+	@Override
+	public int getDepth() {
+		return depth;
+	}
+
+	@Override
+	public Date getTaskDate() {
+		return new Date();
+	}
+
+	@Override
+	public void abort() {
+		this.aborted = true;
+	}
+
+	@Override
+	public boolean isAborted() {
+		return this.aborted;
+	}
+
+}

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/SimpleTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/SimpleTask.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/SimpleTask.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1416986&r1=1406628&r2=1416986&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 15:20:17 2012
@@ -14,51 +14,46 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.droids.impl;
+package org.apache.droids.core;
 
 import java.io.File;
 
 import junit.framework.Assert;
 
+import org.apache.droids.filter.MaxDepthTaskValidator;
 import org.apache.droids.robot.walker.FileTask;
 import org.junit.Before;
 import org.junit.Test;
 
 public class TestSimpleQueue {
 
-  MaxDepthTaskValidator<FileTask> validator; 
-  
-  @Before
-  public final void initialize(){
-    validator = new MaxDepthTaskValidator<FileTask>();
-    validator.setMaxDepth(5);
-  }
-  
-  @Test
-  public void whenTaskBelowMaxDepthIsValidated_thenTaskIsValid() throws Exception {
-    final FileTask task = new FileTask(new File(""), 3);
-    
-    boolean isValid = validator.validate(task);
-    
-    Assert.assertTrue(isValid);
-  }
-  
-  @Test
-  public void whenTaskEqualToMaxDepthIsValidated_thenTaskIsValid() throws Exception {
-    final FileTask task = new FileTask(new File(""), 5);
-    
-    boolean isValid = validator.validate(task);
-    
-    Assert.assertTrue(isValid);
-  }
-  
-  @Test
-  public void whenTaskOverMaxDepthIsValidated_thenTaskIsNotValid() throws Exception {
-    final FileTask task = new FileTask(new File(""), 7);
-    
-    boolean isValid = validator.validate(task);
-    
-    Assert.assertFalse(isValid);
-  }
-  
+	MaxDepthTaskValidator<FileTask> validator;
+
+	@Before
+	public final void initialize() {
+		validator = new MaxDepthTaskValidator<FileTask>();
+		validator.setMaxDepth(5);
+	}
+
+	@Test
+	public void whenTaskBelowMaxDepthIsValidated_thenTaskIsValid() throws Exception {
+		final FileTask task = new FileTask(new File(""), 3);
+		boolean isValid = validator.validate(task);
+		Assert.assertTrue(isValid);
+	}
+
+	@Test
+	public void whenTaskEqualToMaxDepthIsValidated_thenTaskIsValid() throws Exception {
+		final FileTask task = new FileTask(new File(""), 5);
+		boolean isValid = validator.validate(task);
+		Assert.assertTrue(isValid);
+	}
+
+	@Test
+	public void whenTaskOverMaxDepthIsValidated_thenTaskIsNotValid() throws Exception {
+		final FileTask task = new FileTask(new File(""), 7);
+		boolean isValid = validator.validate(task);
+		Assert.assertFalse(isValid);
+	}
+
 }

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/TestSimpleTaskQueueWithHistory.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/TestSimpleTaskQueueWithHistory.java?rev=1416986&r1=1406628&r2=1416986&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/TestSimpleTaskQueueWithHistory.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/core/TestSimpleTaskQueueWithHistory.java
Tue Dec  4 15:20:17 2012
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.droids.impl;
+package org.apache.droids.core;
 
 import static org.junit.Assert.*;
 
@@ -25,8 +25,9 @@ import java.util.LinkedList;
 import java.util.Queue;
 
 import junit.framework.Assert;
-import org.apache.droids.LinkTask;
-import org.apache.droids.api.Link;
+
+import org.apache.droids.core.SimpleTaskQueueWithHistory;
+import org.apache.droids.core.Task;
 import org.junit.Test;
 
 public class TestSimpleTaskQueueWithHistory
@@ -34,15 +35,15 @@ public class TestSimpleTaskQueueWithHist
   @Test
   public void testOffer() throws Exception
   {
-    Queue<LinkTask> queue;
+    Queue<Task> queue;
     URI	uri;
-    LinkTask task;
+    Task task;
 
-    queue = new SimpleTaskQueueWithHistory<LinkTask>();
+    queue = new SimpleTaskQueueWithHistory<Task>();
     Assert.assertEquals(0, queue.size());
     uri = new URI("http://www.example.com");
     Assert.assertNotNull(uri);
-    task = new LinkTask(null, uri, 1);
+    task = new SimpleTask(uri, 1);
     Assert.assertNotNull(task);
     queue.offer(task);
     Assert.assertEquals(1, queue.size());
@@ -57,21 +58,21 @@ public class TestSimpleTaskQueueWithHist
   @Test
   public void testAddAll() throws URISyntaxException 
   {
-	  Collection<Link> links = new LinkedList<Link>();
-	  links.add(new LinkTask(null, new URI("http://www.example.com"), 0));
-	  links.add(new LinkTask(null, new URI("http://www.example.com/1"), 1));
-	  links.add(new LinkTask(null, new URI("http://www.example.com/2"), 1));
-	  links.add(new LinkTask(null, new URI("http://www.example.com/3"), 1));
-	  links.add(new LinkTask(null, new URI("http://www.example.com/4"), 1));
+	  Collection<Task> links = new LinkedList<Task>();
+	  links.add(new SimpleTask(new URI("http://www.example.com"), 0));
+	  links.add(new SimpleTask(new URI("http://www.example.com/1"), 1));
+	  links.add(new SimpleTask(new URI("http://www.example.com/2"), 1));
+	  links.add(new SimpleTask(new URI("http://www.example.com/3"), 1));
+	  links.add(new SimpleTask(new URI("http://www.example.com/4"), 1));
 	  
-	  Queue<Link> queue = new SimpleTaskQueueWithHistory<Link>();
+	  Queue<Task> queue = new SimpleTaskQueueWithHistory<Task>();
 	  assertEquals(0, queue.size());
 	  queue.addAll(links);
 	  assertEquals(5, queue.size());
 	  
-	  links.add(new LinkTask(null, new URI("http://www.example.com/1"), 1));
-	  links.add(new LinkTask(null, new URI("http://www.example.com/5"), 1));
-	  links.add(new LinkTask(null, new URI("http://www.example.com/2"), 1));
+	  links.add(new SimpleTask(new URI("http://www.example.com/1"), 1));
+	  links.add(new SimpleTask(new URI("http://www.example.com/5"), 1));
+	  links.add(new SimpleTask(new URI("http://www.example.com/2"), 1));
 
 	  queue.addAll(links);
 	  assertEquals(6, queue.size());

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/delay/TestDelay.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/delay/TestDelay.java?rev=1416986&r1=1416985&r2=1416986&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/delay/TestDelay.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/test/java/org/apache/droids/delay/TestDelay.java
Tue Dec  4 15:20:17 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.droids.delay;
 
-import org.apache.droids.api.DelayTimer;
 import org.junit.Test;
 
 import junit.framework.Assert;



Mime
View raw message