[freenet-cvs] r12919 - trunk/freenet/src/freenet/clients/http/bookmark

fred at freenetproject.org fred at freenetproject.org
Tue Apr 24 12:47:53 UTC 2007


Author: fred
Date: 2007-04-24 12:47:53 +0000 (Tue, 24 Apr 2007)
New Revision: 12919

Modified:
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
Log:
Fix : import old bookmarks

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java	2007-04-24 12:40:22 UTC (rev 12918)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java	2007-04-24 12:47:53 UTC (rev 12919)
@@ -25,6 +25,7 @@
   private boolean started;
   private BookmarkCategory mainCategory;
   private HashMap bookmarks;
+  private SubConfig sc;
 
   public BookmarkManager (NodeClientCore n, SubConfig sc) {
 
@@ -34,6 +35,7 @@
 
     this.uskcb = new USKUpdatedCallback ();
     this.node = n;
+    this.sc = sc;
 
     try {
 
@@ -85,14 +87,18 @@
 		     "List of bookmarks", "A list of bookmarked freesites",
 		     makeCB ());
 
-        makeCB ().
-	set ((sc.getStringArr ("bookmarks").length ==
-	      0 ? defaultRoot.toStrings () : sc.getStringArr ("bookmarks")));
+      if (!importOldBookmarks ())
+	  makeCB ().
+	  set ((sc.getStringArr ("bookmarks").length ==
+		0 ? defaultRoot.toStrings () : sc.
+		getStringArr ("bookmarks")));
 
 
-    } catch (MalformedURLException mue) {
+    }
+    catch (MalformedURLException mue) {
       // just ignore that one
-    } catch (InvalidConfigValueException icve) {
+    }
+    catch (InvalidConfigValueException icve) {
       //TODO
       icve.printStackTrace ();
     }
@@ -103,16 +109,16 @@
   }
 
   public class BookmarkCallback implements StringArrCallback {
-	  private final Pattern pattern = Pattern.compile ("/(.*/)([^/]*)=([A-Z]{3}@.*).*");
+    private final Pattern pattern =
+      Pattern.compile ("/(.*/)([^/]*)=([A-Z]{3}@.*).*");
     public String[] get () {
 
       synchronized (BookmarkManager.this) {
 
 	return mainCategory.toStrings ();
 
-    }}
-    
-    public void set (String[]newVals) throws InvalidConfigValueException {
+      }
+    } public void set (String[]newVals) throws InvalidConfigValueException {
       clear ();
 
       FreenetURI key;
@@ -155,14 +161,38 @@
 	  if (usk.equals (key, false)) {
 	    items.get (i).setEdition (key.suggestedEdition, node);
 	    break;
-	}}
-	catch (MalformedURLException mue) {
+	  }
+	} catch (MalformedURLException mue) {
 	}
       }
       node.storeConfig ();
     }
   }
 
+  private boolean importOldBookmarks () {
+    String[]strs = sc.getStringArr ("bookmarks");
+
+    final Pattern pattern = Pattern.compile ("([A-Z]{3}@.*)=(.*)");
+    for (int i = 0; i < strs.length; i++) {
+      Matcher matcher = pattern.matcher (strs[i]);
+      if (matcher.matches () && matcher.groupCount () == 2) {
+	try {
+	  addBookmark ("/",
+		       new BookmarkItem (new FreenetURI (matcher.group (1)),
+					 matcher.group (2), node.alerts),
+		       false);
+	}
+	catch (MalformedURLException mue) {
+	}
+      }
+      else
+	return false;
+    }
+
+    node.storeConfig ();
+    return true;
+  }
+
   public BookmarkCallback makeCB () {
     return new BookmarkCallback ();
   }
@@ -208,7 +238,8 @@
       parent.addBookmark (b);
       bookmarks.put (parentPath + b.getName () +
 		     ((b instanceof BookmarkCategory) ? "/" : ""), b);
-    } if (store)
+    }
+    if (store)
         node.storeConfig ();
   }
 




More information about the cvs mailing list