incubator-droids-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r711953 - in /incubator/droids/trunk/src: java/org/apache/droids/api/ java/org/apache/droids/handle/ java/org/apache/droids/helper/factories/ java/org/apache/droids/robot/crawler/ test/java/org/apache/droids/impl/
Date Thu, 06 Nov 2008 19:53:56 GMT
Author: olegk
Date: Thu Nov  6 11:53:24 2008
New Revision: 711953

URL: http://svn.apache.org/viewvc?rev=711953&view=rev
Log:
Replaced URL class with URI in the public API

Modified:
    incubator/droids/trunk/src/java/org/apache/droids/api/Handler.java
    incubator/droids/trunk/src/java/org/apache/droids/handle/Save.java
    incubator/droids/trunk/src/java/org/apache/droids/handle/Sysout.java
    incubator/droids/trunk/src/java/org/apache/droids/helper/factories/HandlerFactory.java
    incubator/droids/trunk/src/java/org/apache/droids/robot/crawler/CrawlingWorker.java
    incubator/droids/trunk/src/test/java/org/apache/droids/impl/TestSimpleDroid.java

Modified: incubator/droids/trunk/src/java/org/apache/droids/api/Handler.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/src/java/org/apache/droids/api/Handler.java?rev=711953&r1=711952&r2=711953&view=diff
==============================================================================
--- incubator/droids/trunk/src/java/org/apache/droids/api/Handler.java (original)
+++ incubator/droids/trunk/src/java/org/apache/droids/api/Handler.java Thu Nov  6 11:53:24
2008
@@ -18,7 +18,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
+import java.net.URI;
 
 import org.apache.droids.exception.DroidsException;
 
@@ -33,12 +33,12 @@
   /**
    * @param openStream
    *                the underlying stream
-   * @param url
-   *                the url we are currently processing
+   * @param uri
+   *                the uri we are currently processing
    * @param parse
    *                the parse object from a former processing step
    * @throws Exception
    */
-  void handle(InputStream openStream, URL url, Parse parse) 
+  void handle(InputStream openStream, URI uri, Parse parse) 
     throws IOException, DroidsException;
 }

Modified: incubator/droids/trunk/src/java/org/apache/droids/handle/Save.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/src/java/org/apache/droids/handle/Save.java?rev=711953&r1=711952&r2=711953&view=diff
==============================================================================
--- incubator/droids/trunk/src/java/org/apache/droids/handle/Save.java (original)
+++ incubator/droids/trunk/src/java/org/apache/droids/handle/Save.java Thu Nov  6 11:53:24
2008
@@ -22,7 +22,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.net.URL;
+import java.net.URI;
 
 import org.apache.droids.api.Handler;
 import org.apache.droids.api.Parse;
@@ -41,7 +41,7 @@
 
   private String outputDir = null;
 
-  private URL url = null;
+  private URI uri = null;
 
   private boolean includeHost = false;
   protected int bufferSize=8192;
@@ -51,24 +51,24 @@
    * @see org.apache.droids.api.Handler#handle(java.io.InputStream,
    *      java.net.URL, org.apache.droids.api.Parse)
    */
-  public void handle(InputStream stream, URL urlToHandle, Parse parse)
+  public void handle(InputStream stream, URI urlToHandle, Parse parse)
       throws IOException {
-    this.url = urlToHandle;
+    this.uri = urlToHandle;
     writeOutput(stream);
   }
 
   private void writeOutput(InputStream stream) throws IOException {
-    if (!url.getFile().endsWith("/")) {
+    if (!uri.getPath().endsWith("/")) {
       byte[] buffer = new byte[bufferSize];
       int length = -1;
      
       String file = outputDir;
       if (includeHost) {
-        file += url.getHost() + url.getFile();
+        file += uri.getHost() + uri.getPath();
       } else {
-        file += url.getFile().substring(1);
+        file += uri.getPath().substring(1);
       }
-      log.info("Trying to save " + url + " to " + file);
+      log.info("Trying to save " + uri + " to " + file);
       File cache = new File(file);
       createFile(cache);
       OutputStream output = new BufferedOutputStream(new FileOutputStream(cache));

Modified: incubator/droids/trunk/src/java/org/apache/droids/handle/Sysout.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/src/java/org/apache/droids/handle/Sysout.java?rev=711953&r1=711952&r2=711953&view=diff
==============================================================================
--- incubator/droids/trunk/src/java/org/apache/droids/handle/Sysout.java (original)
+++ incubator/droids/trunk/src/java/org/apache/droids/handle/Sysout.java Thu Nov  6 11:53:24
2008
@@ -22,7 +22,7 @@
 import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
-import java.net.URL;
+import java.net.URI;
 
 import org.apache.droids.api.Handler;
 import org.apache.droids.api.Parse;
@@ -48,7 +48,7 @@
    * @see org.apache.droids.api.Handler#handle(java.io.InputStream,
    *      java.net.URL, org.apache.droids.api.Parse)
    */
-  public void handle(InputStream stream, URL url, Parse parse) throws IOException {
+  public void handle(InputStream stream, URI uri, Parse parse) throws IOException {
     writeOutput(stream);
   }
 

Modified: incubator/droids/trunk/src/java/org/apache/droids/helper/factories/HandlerFactory.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/src/java/org/apache/droids/helper/factories/HandlerFactory.java?rev=711953&r1=711952&r2=711953&view=diff
==============================================================================
--- incubator/droids/trunk/src/java/org/apache/droids/helper/factories/HandlerFactory.java
(original)
+++ incubator/droids/trunk/src/java/org/apache/droids/helper/factories/HandlerFactory.java
Thu Nov  6 11:53:24 2008
@@ -20,7 +20,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
+import java.net.URI;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.droids.api.Handler;
@@ -47,7 +47,7 @@
    *                the underlying parse object
    * @return false if we found a problem, true if all went well
    */
-  public boolean handle(InputStream stream, URL url, Parse parse) 
+  public boolean handle(InputStream stream, URI uri, Parse parse) 
       throws DroidsException, IOException {
     byte[] streamCopy = null;
     if(stream==null){
@@ -61,7 +61,7 @@
       if (streamCopy == null) {
         return false;
       }
-      handler.handle(new ByteArrayInputStream(streamCopy), url, parse);
+      handler.handle(new ByteArrayInputStream(streamCopy), uri, parse);
     }
     return true;
   }

Modified: incubator/droids/trunk/src/java/org/apache/droids/robot/crawler/CrawlingWorker.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/src/java/org/apache/droids/robot/crawler/CrawlingWorker.java?rev=711953&r1=711952&r2=711953&view=diff
==============================================================================
--- incubator/droids/trunk/src/java/org/apache/droids/robot/crawler/CrawlingWorker.java (original)
+++ incubator/droids/trunk/src/java/org/apache/droids/robot/crawler/CrawlingWorker.java Thu
Nov  6 11:53:24 2008
@@ -18,7 +18,6 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
 import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -96,8 +95,7 @@
   protected void handle( Parse parse, InputStream openStream, Link link ) 
       throws DroidsException, IOException
   {
-    String url = link.getId();
-    droid.getHandlerFactory().handle(openStream, new URL(url), parse);
+    droid.getHandlerFactory().handle(openStream, link.getURI(), parse);
   }
   
   protected Collection<Link> getFilteredOutlinks( Parse parse )

Modified: incubator/droids/trunk/src/test/java/org/apache/droids/impl/TestSimpleDroid.java
URL: http://svn.apache.org/viewvc/incubator/droids/trunk/src/test/java/org/apache/droids/impl/TestSimpleDroid.java?rev=711953&r1=711952&r2=711953&view=diff
==============================================================================
--- incubator/droids/trunk/src/test/java/org/apache/droids/impl/TestSimpleDroid.java (original)
+++ incubator/droids/trunk/src/test/java/org/apache/droids/impl/TestSimpleDroid.java Thu Nov
 6 11:53:24 2008
@@ -18,11 +18,9 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URL;
+import java.net.URI;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 import junit.framework.Assert;
@@ -34,7 +32,6 @@
 import org.apache.droids.api.Parse;
 import org.apache.droids.api.TaskExceptionHandler;
 import org.apache.droids.api.TaskExceptionResult;
-import org.apache.droids.api.TaskMaster;
 import org.apache.droids.localserver.LocalHttpServer;
 import org.apache.droids.localserver.ResourceHandler;
 import org.junit.After;
@@ -65,12 +62,12 @@
     String baseURI = "http:/" + this.testserver.getServiceAddress();     
     String targetURI = baseURI + "/start_html";     
     
-    final List<URL> visitedLinks = new ArrayList<URL>();
+    final List<URI> visitedLinks = new ArrayList<URI>();
 
     Handler testHandler = new Handler() {
 
-      public void handle(InputStream openStream, URL url, Parse parse) {
-        visitedLinks.add(url); 
+      public void handle(InputStream openStream, URI uri, Parse parse) {
+        visitedLinks.add(uri); 
       }
   
     };
@@ -85,11 +82,11 @@
     
     Assert.assertFalse(visitedLinks.isEmpty());
     Assert.assertEquals(5, visitedLinks.size());
-    Assert.assertEquals(new URL(baseURI + "/start_html"), visitedLinks.get(0));
-    Assert.assertEquals(new URL(baseURI + "/page1_html"), visitedLinks.get(1));
-    Assert.assertEquals(new URL(baseURI + "/page2_html"), visitedLinks.get(2));
-    Assert.assertEquals(new URL(baseURI + "/page3_html"), visitedLinks.get(3));
-    Assert.assertEquals(new URL(baseURI + "/page4_html"), visitedLinks.get(4));
+    Assert.assertEquals(new URI(baseURI + "/start_html"), visitedLinks.get(0));
+    Assert.assertEquals(new URI(baseURI + "/page1_html"), visitedLinks.get(1));
+    Assert.assertEquals(new URI(baseURI + "/page2_html"), visitedLinks.get(2));
+    Assert.assertEquals(new URI(baseURI + "/page3_html"), visitedLinks.get(3));
+    Assert.assertEquals(new URI(baseURI + "/page4_html"), visitedLinks.get(4));
   }
   
   @Test
@@ -101,13 +98,13 @@
     String baseURI = "http:/" + this.testserver.getServiceAddress();     
     String targetURI = baseURI + "/start_html";     
     
-    final Set<URL> visitedLinks = new HashSet<URL>();
+    final List<URI> visitedLinks = new ArrayList<URI>();
 
     Handler testHandler = new Handler() {
 
-      public void handle(InputStream openStream, URL url, Parse parse) {
-        visitedLinks.add(url);
-        if (url.getPath().equals("/page3_html")) {
+      public void handle(InputStream openStream, URI uri, Parse parse) {
+        visitedLinks.add(uri);
+        if (uri.getPath().equals("/page3_html")) {
           throw new RuntimeException("Oppsie!!!");
         }
       }
@@ -136,10 +133,10 @@
     
     Assert.assertFalse(visitedLinks.isEmpty());
     Assert.assertEquals(4, visitedLinks.size());
-    Assert.assertTrue(visitedLinks.contains(new URL(baseURI + "/start_html")));
-    Assert.assertTrue(visitedLinks.contains(new URL(baseURI + "/page1_html")));
-    Assert.assertTrue(visitedLinks.contains(new URL(baseURI + "/page2_html")));
-    Assert.assertTrue(visitedLinks.contains(new URL(baseURI + "/page3_html")));
+    Assert.assertEquals(new URI(baseURI + "/start_html"), visitedLinks.get(0));
+    Assert.assertEquals(new URI(baseURI + "/page1_html"), visitedLinks.get(1));
+    Assert.assertEquals(new URI(baseURI + "/page2_html"), visitedLinks.get(2));
+    Assert.assertEquals(new URI(baseURI + "/page3_html"), visitedLinks.get(3));
   }
 
 }



Mime
View raw message