[freenet-cvs] r11291 - trunk/plugins/Librarian

toad at freenetproject.org toad at freenetproject.org
Thu Dec 7 21:37:35 UTC 2006


Author: toad
Date: 2006-12-07 21:37:34 +0000 (Thu, 07 Dec 2006)
New Revision: 11291

Modified:
   trunk/plugins/Librarian/Librarian.java
Log:
Fix ClassCastException.
Follow newURI's.

Modified: trunk/plugins/Librarian/Librarian.java
===================================================================
--- trunk/plugins/Librarian/Librarian.java	2006-12-07 21:24:30 UTC (rev 11290)
+++ trunk/plugins/Librarian/Librarian.java	2006-12-07 21:37:34 UTC (rev 11291)
@@ -6,6 +6,8 @@
 import java.util.Random;
 import java.util.Vector;
 
+import freenet.client.FetchException;
+import freenet.client.FetchResult;
 import freenet.client.HighLevelSimpleClient;
 import freenet.clients.http.HTTPRequest;
 import freenet.keys.FreenetURI;
@@ -81,7 +83,7 @@
 		search = HTMLEncoder.encode(search);
 		index = HTMLEncoder.encode(index);
 		out.append("Search for:<br/>");
-        out.append("<form method=\"GET\"><input type=text value=\"").append(search).append("\" name=\"search\" size=80/><br/><br/>");
+        out.append("<form method=\"GET\"><input type=\"text\" value=\"").append(search).append("\" name=\"search\" size=80/><br/><br/>");
 		out.append("Using the index:<br/>");
         out.append("<input type=text name=\"index\" value=\"").append(index).append("\" size=80/>");
 		out.append("<input type=submit value=\"Find!\"/></form>\n");
@@ -92,7 +94,18 @@
 	
 	private HashMap getFullIndex(String uri) throws Exception {
 		HighLevelSimpleClient hlsc = pr.getHLSimpleClient();
-		String index[] = new String(hlsc.fetch(new FreenetURI(uri)).asByteArray()).trim().split("\n");
+		FreenetURI u = new FreenetURI(uri);
+		FetchResult res;
+		while(true) {
+			try {
+				res = hlsc.fetch(u);
+				break;
+			} catch (FetchException e) {
+				if(e.newURI != null)
+					u = e.newURI;
+			}
+		}
+		String index[] = new String(res.asByteArray()).trim().split("\n");
 		
 		Vector uris = new Vector();
 		HashMap keywords = new HashMap();
@@ -192,7 +205,7 @@
 			}
 			synchronized (hs) {
 				for (int i = 0 ; i < searchWords.length ; i++) {
-					HashSet keyuris = (HashSet)index.get(searchWords[i].toLowerCase().trim());
+					Vector keyuris = (Vector)index.get(searchWords[i].toLowerCase().trim());
 					
 					Iterator it = hs.iterator();
 					while (it.hasNext()) {




More information about the cvs mailing list