Author: toad
Date: 2007-04-26 16:27:31 +0000 (Thu, 26 Apr 2007)
New Revision: 12988

Modified:
   trunk/freenet/src/freenet/clients/http/bookmark/Bookmark.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategories.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategory.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItems.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
Log:
Indent!

Modified: trunk/freenet/src/freenet/clients/http/bookmark/Bookmark.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/Bookmark.java       
2007-04-26 16:25:31 UTC (rev 12987)
+++ trunk/freenet/src/freenet/clients/http/bookmark/Bookmark.java       
2007-04-26 16:27:31 UTC (rev 12988)
@@ -1,27 +1,31 @@
 package freenet.clients.http.bookmark;

 public abstract class Bookmark {
-  protected boolean privateBookmark;
-  protected String name;
-  protected String desc;
+       protected boolean privateBookmark;

-  public boolean isPrivate () {
-    return privateBookmark;
-  } public abstract void setPrivate (boolean bool);
+       protected String name;

-  public String getName () {
-    return name;
-  }
+       protected String desc;

-  protected void setName (String s) {
-    name = s;
-  }
+       public boolean isPrivate() {
+               return privateBookmark;
+       }

-  public String getDesc () {
-    return desc;
-  }
+       public abstract void setPrivate(boolean bool);

-  public void setDesc (String s) {
-    desc = s;
-  }
+       public String getName() {
+               return name;
+       }
+
+       protected void setName(String s) {
+               name = s;
+       }
+
+       public String getDesc() {
+               return desc;
+       }
+
+       public void setDesc(String s) {
+               desc = s;
+       }
 }

Modified: 
trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategories.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategories.java     
2007-04-26 16:25:31 UTC (rev 12987)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategories.java     
2007-04-26 16:27:31 UTC (rev 12988)
@@ -1,35 +1,35 @@
-
 package freenet.clients.http.bookmark;

 import java.util.Vector;
 import java.util.Iterator;

-
-public final class BookmarkCategories  //implements Iterator
+public final class BookmarkCategories // implements Iterator
 {

-  Vector categories;
+       Vector categories;

-  public BookmarkCategories () {
-    categories = new Vector ();
-  } public BookmarkCategory get (int i) {
-    return (BookmarkCategory) categories.get (i);
-  }
+       public BookmarkCategories() {
+               categories = new Vector();
+       }

-  public void add (BookmarkCategory bc) {
-    categories.add (bc);
-  }
+       public BookmarkCategory get(int i) {
+               return (BookmarkCategory) categories.get(i);
+       }

-  protected void extend (BookmarkCategories bc) {
-    for (int i = 0; i < bc.size (); i++)
-      add (bc.get (i));
-  }
+       public void add(BookmarkCategory bc) {
+               categories.add(bc);
+       }

-  public int size () {
-    return categories.size ();
-  }
+       protected void extend(BookmarkCategories bc) {
+               for (int i = 0; i < bc.size(); i++)
+                       add(bc.get(i));
+       }

-  public Iterator iterator () {
-    return categories.iterator ();
-  }
+       public int size() {
+               return categories.size();
+       }
+
+       public Iterator iterator() {
+               return categories.iterator();
+       }
 }

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategory.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategory.java       
2007-04-26 16:25:31 UTC (rev 12987)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategory.java       
2007-04-26 16:27:31 UTC (rev 12988)
@@ -5,132 +5,131 @@

 import freenet.support.StringArray;

-
-public class BookmarkCategory extends Bookmark // implements Iterator
+public class BookmarkCategory extends Bookmark // implements Iterator
 {

-  private final Vector bookmarks;
+       private final Vector bookmarks;

-  public BookmarkCategory (String name) {
-    bookmarks = new Vector ();
-    setName (name);
-  } public BookmarkCategory (String name, String desc) {
-    bookmarks = new Vector ();
-    setName (name);
-    setDesc (desc);
-  }
+       public BookmarkCategory(String name) {
+               bookmarks = new Vector();
+               setName(name);
+       }

-  protected Bookmark addBookmark (Bookmark b) {
-    bookmarks.add (b);
-    return b;
-  }
+       public BookmarkCategory(String name, String desc) {
+               bookmarks = new Vector();
+               setName(name);
+               setDesc(desc);
+       }

-  protected void removeBookmark (Bookmark b) {
-    bookmarks.remove (b);
-  }
+       protected Bookmark addBookmark(Bookmark b) {
+               bookmarks.add(b);
+               return b;
+       }

-  public Bookmark get (int i) {
-    return (Bookmark) bookmarks.get (i);
-  }
+       protected void removeBookmark(Bookmark b) {
+               bookmarks.remove(b);
+       }

-  protected void moveBookmarkUp (Bookmark b) {
-    int index = bookmarks.indexOf (b);
-    if (index == -1)
-      return;
+       public Bookmark get(int i) {
+               return (Bookmark) bookmarks.get(i);
+       }

-    Bookmark bk = get (index);
-    bookmarks.remove (index);
-    bookmarks.add ((--index < 0) ? 0 : index, bk);
-  }
+       protected void moveBookmarkUp(Bookmark b) {
+               int index = bookmarks.indexOf(b);
+               if (index == -1)
+                       return;

-  protected void moveBookmarkDown (Bookmark b) {
-    int index = bookmarks.indexOf (b);
-    if (index == -1)
-      return;
+               Bookmark bk = get(index);
+               bookmarks.remove(index);
+               bookmarks.add((--index < 0) ? 0 : index, bk);
+       }

-    Bookmark bk = get (index);
-    bookmarks.remove (index);
-    bookmarks.add ((++index > size ())? size () : index, bk);
-  }
+       protected void moveBookmarkDown(Bookmark b) {
+               int index = bookmarks.indexOf(b);
+               if (index == -1)
+                       return;

-  public int size () {
-    return bookmarks.size ();
-  }
+               Bookmark bk = get(index);
+               bookmarks.remove(index);
+               bookmarks.add((++index > size()) ? size() : index, bk);
+       }

-  public BookmarkItems getItems () {
-    BookmarkItems items = new BookmarkItems ();
-    for (int i = 0; i < size (); i++) {
-      if (get (i) instanceof BookmarkItem)
-       items.add ((BookmarkItem) get (i));
-    }
+       public int size() {
+               return bookmarks.size();
+       }

-    return items;
-  }
+       public BookmarkItems getItems() {
+               BookmarkItems items = new BookmarkItems();
+               for (int i = 0; i < size(); i++) {
+                       if (get(i) instanceof BookmarkItem)
+                               items.add((BookmarkItem) get(i));
+               }

-  public BookmarkItems getAllItems () {
-    BookmarkItems items = getItems ();
-    BookmarkCategories subCategories = getSubCategories ();
+               return items;
+       }

-    for (int i = 0; i < subCategories.size (); i++) {
-      items.extend (subCategories.get (i).getAllItems ());
-    }
-    return items;
-  }
+       public BookmarkItems getAllItems() {
+               BookmarkItems items = getItems();
+               BookmarkCategories subCategories = getSubCategories();

+               for (int i = 0; i < subCategories.size(); i++) {
+                       items.extend(subCategories.get(i).getAllItems());
+               }
+               return items;
+       }

-  public BookmarkCategories getSubCategories () {
-    BookmarkCategories categories = new BookmarkCategories ();
-    for (int i = 0; i < size (); i++) {
-      if (get (i) instanceof BookmarkCategory)
-       categories.add ((BookmarkCategory) get (i));
-    }
+       public BookmarkCategories getSubCategories() {
+               BookmarkCategories categories = new BookmarkCategories();
+               for (int i = 0; i < size(); i++) {
+                       if (get(i) instanceof BookmarkCategory)
+                               categories.add((BookmarkCategory) get(i));
+               }

-    return categories;
-  }
+               return categories;
+       }

-  public BookmarkCategories getAllSubCategories () {
-    BookmarkCategories categories = getSubCategories ();
-    BookmarkCategories subCategories = getSubCategories ();
+       public BookmarkCategories getAllSubCategories() {
+               BookmarkCategories categories = getSubCategories();
+               BookmarkCategories subCategories = getSubCategories();

-    for (int i = 0; i < subCategories.size (); i++) {
-      categories.extend (subCategories.get (i).getAllSubCategories ());
-    }
+               for (int i = 0; i < subCategories.size(); i++) {
+                       
categories.extend(subCategories.get(i).getAllSubCategories());
+               }

-    return categories;
-  }
+               return categories;
+       }

+       public String[] toStrings() {
+               return StringArray.toArray(toStrings("").toArray());
+       }

-  public String[] toStrings () {
-    return StringArray.toArray (toStrings ("").toArray ());
-  }
+       // Iternal use only
+       private Vector toStrings(String prefix) {
+               Vector strings = new Vector();
+               BookmarkItems items = getItems();
+               BookmarkCategories subCategories = getSubCategories();
+               prefix += this.name + "/";

-  // Iternal use only
-  private Vector toStrings (String prefix) {
-    Vector strings = new Vector ();
-    BookmarkItems items = getItems ();
-    BookmarkCategories subCategories = getSubCategories ();
-    prefix += this.name + "/";
+               for (int i = 0; i < items.size(); i++)
+                       strings.add(prefix + items.get(i).toString());

-    for (int i = 0; i < items.size (); i++)
-      strings.add (prefix + items.get (i).toString ());
+               for (int i = 0; i < subCategories.size(); i++)
+                       strings.addAll(subCategories.get(i).toStrings(prefix));

-    for (int i = 0; i < subCategories.size (); i++)
-      strings.addAll (subCategories.get (i).toStrings (prefix));
+               return strings;

-    return strings;
+       }

-  }
+       public void setPrivate(boolean bool) {
+               privateBookmark = bool;

-  public void setPrivate (boolean bool) {
-    privateBookmark = bool;
+               BookmarkCategories subCategories = getSubCategories();
+               for (int i = 0; i < size(); i++)
+                       subCategories.get(i).setPrivate(bool);
+       }

-    BookmarkCategories subCategories = getSubCategories ();
-    for (int i = 0; i < size (); i++)
-      subCategories.get (i).setPrivate (bool);
-  }
+       public Iterator iterator() {
+               return bookmarks.iterator();
+       }

-  public Iterator iterator () {
-    return bookmarks.iterator ();
-  }
-
 }

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java   
2007-04-26 16:25:31 UTC (rev 12987)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java   
2007-04-26 16:27:31 UTC (rev 12988)
@@ -14,129 +14,139 @@

 public class BookmarkItem extends Bookmark {

-  private FreenetURI key;
-  private boolean updated;
-  private final BookmarkUpdatedUserAlert alert;
-  private UserAlertManager alerts;
+       private FreenetURI key;

+       private boolean updated;

-  public BookmarkItem (FreenetURI k, String n,
-                      UserAlertManager uam) throws MalformedURLException {
-    this.key = k;
-    this.name = n;
-    this.alerts = uam;
-    alert = new BookmarkUpdatedUserAlert ();
-  } public BookmarkItem (FreenetURI k, String n, String d,
-                        UserAlertManager uam) throws MalformedURLException {
+       private final BookmarkUpdatedUserAlert alert;

-    this.key = k;
-    this.name = n;
-    this.desc = d;
-    this.alerts = uam;
-    alert = new BookmarkUpdatedUserAlert ();
-  } private class BookmarkUpdatedUserAlert implements UserAlert {
+       private UserAlertManager alerts;

-    public boolean userCanDismiss () {
-      return true;
-    } public String getTitle () {
-      return "Bookmark updated: " + name;
-    } public String getText () {
-      return "The bookmarked site " + name + " has been updated to edition " +
-       key.getSuggestedEdition ();
-    }
+       public BookmarkItem(FreenetURI k, String n, UserAlertManager uam)
+                       throws MalformedURLException {
+               this.key = k;
+               this.name = n;
+               this.alerts = uam;
+               alert = new BookmarkUpdatedUserAlert();
+       }

-    public HTMLNode getHTMLText () {
-      HTMLNode n = new HTMLNode ("div");
-      n.addChild ("#", "The bookmarked site ");
-      n.addChild ("a", "href", '/' + key.toString ()).addChild ("#", name);
-      n.addChild ("#",
-                 " has been updated to edition " +
-                 key.getSuggestedEdition () + ".");
-      return n;
-    }
+       public BookmarkItem(FreenetURI k, String n, String d, UserAlertManager 
uam)
+                       throws MalformedURLException {

-    public short getPriorityClass () {
-      return UserAlert.MINOR;
-    }
+               this.key = k;
+               this.name = n;
+               this.desc = d;
+               this.alerts = uam;
+               alert = new BookmarkUpdatedUserAlert();
+       }

-    public boolean isValid () {
-      synchronized (BookmarkItem.this) {
-       return updated;
-      }
-    }
+       private class BookmarkUpdatedUserAlert implements UserAlert {

-    public void isValid (boolean validity) {
-      if (validity)
-       return;
-      disableBookmark ();
-    }
+               public boolean userCanDismiss() {
+                       return true;
+               }

-    public String dismissButtonText () {
-      return "Delete notification";
-    }
+               public String getTitle() {
+                       return "Bookmark updated: " + name;
+               }

-    public boolean shouldUnregisterOnDismiss () {
-      return true;
-    }
+               public String getText() {
+                       return "The bookmarked site " + name
+                                       + " has been updated to edition "
+                                       + key.getSuggestedEdition();
+               }

-    public void onDismiss () {
-      disableBookmark ();
-    }
+               public HTMLNode getHTMLText() {
+                       HTMLNode n = new HTMLNode("div");
+                       n.addChild("#", "The bookmarked site ");
+                       n.addChild("a", "href", '/' + 
key.toString()).addChild("#", name);
+                       n.addChild("#", " has been updated to edition "
+                                       + key.getSuggestedEdition() + ".");
+                       return n;
+               }

-  }
+               public short getPriorityClass() {
+                       return UserAlert.MINOR;
+               }

-  private synchronized void disableBookmark () {
-    updated = false;
-    alerts.unregister (alert);
-  }
+               public boolean isValid() {
+                       synchronized (BookmarkItem.this) {
+                               return updated;
+                       }
+               }

-  private synchronized void enableBookmark () {
-    if (updated)
-      return;
-    updated = true;
-    alerts.register (alert);
-  }
+               public void isValid(boolean validity) {
+                       if (validity)
+                               return;
+                       disableBookmark();
+               }

-  public String getKey () {
-    return key.toString ();
-  }
+               public String dismissButtonText() {
+                       return "Delete notification";
+               }

-  public synchronized FreenetURI getURI () {
-    return key;
-  }
+               public boolean shouldUnregisterOnDismiss() {
+                       return true;
+               }

-  public synchronized void setKey (FreenetURI uri) {
-    key = uri;
-  }
+               public void onDismiss() {
+                       disableBookmark();
+               }

-  public synchronized String getKeyType () {
-    return key.getKeyType ();
-  }
+       }

-  public String getName () {
-    if (name.equals ("")) {
-      return "Unnamed Bookmark";
-    }
-    else {
-      return name;
-    }
-  }
+       private synchronized void disableBookmark() {
+               updated = false;
+               alerts.unregister(alert);
+       }

-  public void setPrivate (boolean bool) {
-    privateBookmark = bool;
-  }
+       private synchronized void enableBookmark() {
+               if (updated)
+                       return;
+               updated = true;
+               alerts.register(alert);
+       }

-  public String toString () {
-    return this.name + "=" + this.key.toString ();
-  }
+       public String getKey() {
+               return key.toString();
+       }

-  public synchronized void setEdition (long ed, NodeClientCore node) {
-    if (key.getSuggestedEdition () >= ed)
-      return;
-    key = key.setSuggestedEdition (ed);
-    enableBookmark ();
-  }
+       public synchronized FreenetURI getURI() {
+               return key;
+       }

-  public USK getUSK () throws MalformedURLException {
-    return USK.create (key);
-}}
+       public synchronized void setKey(FreenetURI uri) {
+               key = uri;
+       }
+
+       public synchronized String getKeyType() {
+               return key.getKeyType();
+       }
+
+       public String getName() {
+               if (name.equals("")) {
+                       return "Unnamed Bookmark";
+               } else {
+                       return name;
+               }
+       }
+
+       public void setPrivate(boolean bool) {
+               privateBookmark = bool;
+       }
+
+       public String toString() {
+               return this.name + "=" + this.key.toString();
+       }
+
+       public synchronized void setEdition(long ed, NodeClientCore node) {
+               if (key.getSuggestedEdition() >= ed)
+                       return;
+               key = key.setSuggestedEdition(ed);
+               enableBookmark();
+       }
+
+       public USK getUSK() throws MalformedURLException {
+               return USK.create(key);
+       }
+}

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItems.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItems.java  
2007-04-26 16:25:31 UTC (rev 12987)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItems.java  
2007-04-26 16:27:31 UTC (rev 12988)
@@ -3,33 +3,33 @@
 import java.util.Vector;
 import java.util.Iterator;

-
-public class BookmarkItems     //implements Iterator
+public class BookmarkItems // implements Iterator
 {

-  Vector items;
+       Vector items;

+       public BookmarkItems() {
+               items = new Vector();
+       }

-  public BookmarkItems () {
-    items = new Vector ();
-  } public BookmarkItem get (int i) {
-    return (BookmarkItem) items.get (i);
-  }
+       public BookmarkItem get(int i) {
+               return (BookmarkItem) items.get(i);
+       }

-  public void add (BookmarkItem bi) {
-    items.add (bi);
-  }
+       public void add(BookmarkItem bi) {
+               items.add(bi);
+       }

-  protected void extend (BookmarkItems bi) {
-    for (int i = 0; i < bi.size (); i++)
-      add (bi.get (i));
-  }
+       protected void extend(BookmarkItems bi) {
+               for (int i = 0; i < bi.size(); i++)
+                       add(bi.get(i));
+       }

-  public int size () {
-    return items.size ();
-  }
+       public int size() {
+               return items.size();
+       }

-  public Iterator iterator () {
-    return (items).iterator ();
-  }
+       public Iterator iterator() {
+               return (items).iterator();
+       }
 }

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java        
2007-04-26 16:25:31 UTC (rev 12987)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java        
2007-04-26 16:27:31 UTC (rev 12988)
@@ -2,7 +2,6 @@
  * Public License, version 2 (or at your option any later version). See
  * http://www.gnu.org/ for further details of the GPL. */

-
 package freenet.clients.http.bookmark;

 import java.net.MalformedURLException;
@@ -17,437 +16,407 @@
 import freenet.node.NodeClientCore;
 import freenet.support.api.StringArrCallback;

-
 public class BookmarkManager {

-  private final NodeClientCore node;
-  private USKUpdatedCallback uskcb;
-  private boolean started;
-  private BookmarkCategory mainCategory;
-  private HashMap bookmarks;
-  private SubConfig sc;
+       private final NodeClientCore node;

-  public BookmarkManager (NodeClientCore n, SubConfig sc) {
+       private USKUpdatedCallback uskcb;

-    bookmarks = new HashMap ();
-    mainCategory = new BookmarkCategory ("/");
-    bookmarks.put ("/", mainCategory);
+       private boolean started;

-    this.uskcb = new USKUpdatedCallback ();
-    this.node = n;
-    this.sc = sc;
+       private BookmarkCategory mainCategory;

-    try {
+       private HashMap bookmarks;

-      BookmarkCategory defaultRoot = new BookmarkCategory ("/");
+       private SubConfig sc;

-      BookmarkCategory indexes =
-       (BookmarkCategory) defaultRoot.
-       addBookmark (new BookmarkCategory ("Indexes"));
-        indexes.
-       addBookmark (new
-                    BookmarkItem (new
-                                  FreenetURI
-                                  ("USK at 
7H66rhYmxIFgMyw5Dl11JazXGHPhp7dSN7WMa1pbtEo,jQHUQUPTkeRcjmjgrc7t5cDRdDkK3uKkrSzuw5CO9uk,AQACAAE/ENTRY.POINT/21/"),
-                                  "Entry point (freesites with descriptions 
but no categories)", node.alerts));
+       public BookmarkManager(NodeClientCore n, SubConfig sc) {

-        indexes.
-       addBookmark (new
-                    BookmarkItem (new
-                                  FreenetURI
-                                  ("USK at 
e4TEIN5l1nkn6kjl63XBgYTYobmwGvtnyK2YW0b0ajo,hv-2~OfetXkb0FhDuPxorWIf0wXeZKPEfdIhwyh-mhk,AQABAAE/AnotherIndex/106/"),
-                                  "Another Index (freesites with categories 
but no descriptions)", node.alerts));
-        
-        indexes.
-       addBookmark (new
-                    BookmarkItem (new
-                                  FreenetURI
-                                  ("USK at 
BPZppy07RyID~NGihHgs4AAw3fUXxgtKIrwRu5rtpWE,k5yjkAFJC93JkydKl6vpY0Zy9D8ec1ymv2XP4Tx5Io0,AQABAAE/FreeHoo/6/"),
-                                  "Free Hoo (very old freesite reviews site)", 
node.alerts));
-        
-      BookmarkCategory flog =
-       (BookmarkCategory) defaultRoot.
-       addBookmark (new BookmarkCategory ("Freenet devel's flogs"));
-        flog.
-       addBookmark (new
-                    BookmarkItem (new
-                                  FreenetURI
-                                  ("USK at 
J585KtAJ7UN2~4i17hf7C9XbufMnticJeUDYLcB0dvo,lxZhX2snsExxemocIlI~ZJRFVdVLBLIFZhqV3yswR9U,AQABAAE/toad/10/"),
-                                  "Toad", node.alerts));
-        flog.
-       addBookmark (new
-                    BookmarkItem (new
-                                  FreenetURI
-                                  ("USK at 
hM9XRwjXIzU8xTSBXNZvTn2KuvTSRFnVn4EER9FQnpM,gsth24O7ud4gL4NwNuYJDUqfaWASOG2zxZY~ChtgPxc,AQACAAE/Flog/2/"),
-                                  "Nextgen$", node.alerts));
+               bookmarks = new HashMap();
+               mainCategory = new BookmarkCategory("/");
+               bookmarks.put("/", mainCategory);

-      BookmarkCategory apps =
-       (BookmarkCategory) defaultRoot.
-       addBookmark (new BookmarkCategory ("Freenet related software"));
-        apps.
-       addBookmark (new
-                    BookmarkItem (new
-                                  FreenetURI
-                                  ("USK at 
QRZAI1nSm~dAY2hTdzVWXmEhkaI~dso0OadnppBR7kE,wq5rHGBI7kpChBe4yRmgBChIGDug7Xa5SG9vYGXdxR0,AQACAAE/frost/1"),
-                                  "Frost", node.alerts));
+               this.uskcb = new USKUpdatedCallback();
+               this.node = n;
+               this.sc = sc;

-        sc.register ("bookmarks", defaultRoot.toStrings (), 0, true, false,
-                    "BookmarkManager.list", "BookmarkManager.listLong",
-                    makeCB ());
+               try {

-      if (!importOldBookmarks ())
-         makeCB ().
-         set ((sc.getStringArr ("bookmarks").length ==
-               0 ? defaultRoot.toStrings () : sc.
-               getStringArr ("bookmarks")));
+                       BookmarkCategory defaultRoot = new 
BookmarkCategory("/");

+                       BookmarkCategory indexes = (BookmarkCategory) 
defaultRoot
+                                       .addBookmark(new 
BookmarkCategory("Indexes"));
+                       indexes
+                                       .addBookmark(new BookmarkItem(
+                                                       new FreenetURI(
+                                                                       "USK at 
7H66rhYmxIFgMyw5Dl11JazXGHPhp7dSN7WMa1pbtEo,jQHUQUPTkeRcjmjgrc7t5cDRdDkK3uKkrSzuw5CO9uk,AQACAAE/ENTRY.POINT/21/"),
+                                                       "Entry point (freesites 
with descriptions but no categories)",
+                                                       node.alerts));

-    }
-    catch (MalformedURLException mue) {
-      // just ignore that one
-    }
-    catch (InvalidConfigValueException icve) {
-      //TODO
-      icve.printStackTrace ();
-    }
+                       indexes
+                                       .addBookmark(new BookmarkItem(
+                                                       new FreenetURI(
+                                                                       "USK at 
e4TEIN5l1nkn6kjl63XBgYTYobmwGvtnyK2YW0b0ajo,hv-2~OfetXkb0FhDuPxorWIf0wXeZKPEfdIhwyh-mhk,AQABAAE/AnotherIndex/106/"),
+                                                       "Another Index 
(freesites with categories but no descriptions)",
+                                                       node.alerts));

-    synchronized (this) {
-      started = true;
-    }
-  }
+                       indexes
+                                       .addBookmark(new BookmarkItem(
+                                                       new FreenetURI(
+                                                                       "USK at 
BPZppy07RyID~NGihHgs4AAw3fUXxgtKIrwRu5rtpWE,k5yjkAFJC93JkydKl6vpY0Zy9D8ec1ymv2XP4Tx5Io0,AQABAAE/FreeHoo/6/"),
+                                                       "Free Hoo (very old 
freesite reviews site)",
+                                                       node.alerts));

-  public class BookmarkCallback implements StringArrCallback {
-    private final Pattern pattern =
-      Pattern.compile ("/(.*/)([^/]*)=([A-Z]{3}@.*).*");
-    public String[] get () {
+                       BookmarkCategory flog = (BookmarkCategory) defaultRoot
+                                       .addBookmark(new 
BookmarkCategory("Freenet devel's flogs"));
+                       flog
+                                       .addBookmark(new BookmarkItem(
+                                                       new FreenetURI(
+                                                                       "USK at 
J585KtAJ7UN2~4i17hf7C9XbufMnticJeUDYLcB0dvo,lxZhX2snsExxemocIlI~ZJRFVdVLBLIFZhqV3yswR9U,AQABAAE/toad/10/"),
+                                                       "Toad", node.alerts));
+                       flog
+                                       .addBookmark(new BookmarkItem(
+                                                       new FreenetURI(
+                                                                       "USK at 
hM9XRwjXIzU8xTSBXNZvTn2KuvTSRFnVn4EER9FQnpM,gsth24O7ud4gL4NwNuYJDUqfaWASOG2zxZY~ChtgPxc,AQACAAE/Flog/2/"),
+                                                       "Nextgen$", 
node.alerts));

-      synchronized (BookmarkManager.this) {
+                       BookmarkCategory apps = (BookmarkCategory) defaultRoot
+                                       .addBookmark(new BookmarkCategory(
+                                                       "Freenet related 
software"));
+                       apps
+                                       .addBookmark(new BookmarkItem(
+                                                       new FreenetURI(
+                                                                       "USK at 
QRZAI1nSm~dAY2hTdzVWXmEhkaI~dso0OadnppBR7kE,wq5rHGBI7kpChBe4yRmgBChIGDug7Xa5SG9vYGXdxR0,AQACAAE/frost/1"),
+                                                       "Frost", node.alerts));

-       return mainCategory.toStrings ();
+                       sc.register("bookmarks", defaultRoot.toStrings(), 0, 
true, false,
+                                       "BookmarkManager.list", 
"BookmarkManager.listLong",
+                                       makeCB());

-      }
-    } public void set (String[]newVals) throws InvalidConfigValueException {
-      clear ();
+                       if (!importOldBookmarks())
+                               makeCB().set(
+                                               
(sc.getStringArr("bookmarks").length == 0 ? defaultRoot
+                                                               .toStrings() : 
sc.getStringArr("bookmarks")));

-      FreenetURI key;
-      for (int i = 0; i < newVals.length; i++) {
-       try {
-         Matcher matcher = pattern.matcher (newVals[i]);
-         if (matcher.matches () && matcher.groupCount () == 3) {
+               } catch (MalformedURLException mue) {
+                       // just ignore that one
+               } catch (InvalidConfigValueException icve) {
+                       // TODO
+                       icve.printStackTrace();
+               }

-           makeParents (matcher.group (1));
-           key = new FreenetURI (matcher.group (3));
-           addBookmark (matcher.group (1),
-                        new BookmarkItem (key, matcher.group (2),
-                                          node.alerts), false);
+               synchronized (this) {
+                       started = true;
+               }
+       }

-         }
-         else
-             throw new InvalidConfigValueException ("Malformed Bookmark");
+       public class BookmarkCallback implements StringArrCallback {
+               private final Pattern pattern = Pattern
+                               .compile("/(.*/)([^/]*)=([A-Z]{3}@.*).*");

-       }
-       catch (MalformedURLException mue) {
-         throw new InvalidConfigValueException (mue.getMessage ());
-       }
-      }
-    }
-  }
+               public String[] get() {

-  private class USKUpdatedCallback implements USKCallback {
-    public void onFoundEdition (long edition, USK key) {
-      BookmarkItems items = mainCategory.getAllItems ();
-      for (int i = 0; i < items.size (); i++) {
+                       synchronized (BookmarkManager.this) {

+                               return mainCategory.toStrings();

-       if (!items.get (i).getKeyType ().equals ("USK"))
-         continue;
+                       }
+               }

-       try {
-         FreenetURI furi = new FreenetURI (items.get (i).getKey ());
-         USK usk = USK.create (furi);
+               public void set(String[] newVals) throws 
InvalidConfigValueException {
+                       clear();

-         if (usk.equals (key, false)) {
-           items.get (i).setEdition (key.suggestedEdition, node);
-           break;
-         }
-       } catch (MalformedURLException mue) {
-       }
-      }
-      node.storeConfig ();
-    }
-  }
+                       FreenetURI key;
+                       for (int i = 0; i < newVals.length; i++) {
+                               try {
+                                       Matcher matcher = 
pattern.matcher(newVals[i]);
+                                       if (matcher.matches() && 
matcher.groupCount() == 3) {

-  private boolean importOldBookmarks () {
-    String[]strs = sc.getStringArr ("bookmarks");
+                                               makeParents(matcher.group(1));
+                                               key = new 
FreenetURI(matcher.group(3));
+                                               addBookmark(matcher.group(1), 
new BookmarkItem(key,
+                                                               
matcher.group(2), node.alerts), false);

-    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) {
-             if(getCategoryByPath("/Imported/") == null)
-                      addBookmark ("/",new BookmarkCategory("Imported"), 
false);
-       try {
-         addBookmark ("/Imported/",
-                      new BookmarkItem (new FreenetURI (matcher.group (1)),
-                                        matcher.group (2), node.alerts),
-                      false);
+                                       } else
+                                               throw new 
InvalidConfigValueException(
+                                                               "Malformed 
Bookmark");
+
+                               } catch (MalformedURLException mue) {
+                                       throw new 
InvalidConfigValueException(mue.getMessage());
+                               }
+                       }
+               }
        }
-       catch (MalformedURLException mue) {     }
-      }
-      else
-       return false;
-    }

-    node.storeConfig ();
-    return true;
-  }
+       private class USKUpdatedCallback implements USKCallback {
+               public void onFoundEdition(long edition, USK key) {
+                       BookmarkItems items = mainCategory.getAllItems();
+                       for (int i = 0; i < items.size(); i++) {

-  public BookmarkCallback makeCB () {
-    return new BookmarkCallback ();
-  }
+                               if (!items.get(i).getKeyType().equals("USK"))
+                                       continue;

-  public BookmarkCategory getMainCategory () {
-    return mainCategory;
-  }
+                               try {
+                                       FreenetURI furi = new 
FreenetURI(items.get(i).getKey());
+                                       USK usk = USK.create(furi);

-  public String parentPath (String path) {
-    if (path.equals ("/"))
-      return "/";
+                                       if (usk.equals(key, false)) {
+                                               
items.get(i).setEdition(key.suggestedEdition, node);
+                                               break;
+                                       }
+                               } catch (MalformedURLException mue) {
+                               }
+                       }
+                       node.storeConfig();
+               }
+       }

-    return path.substring (0,
-                          path.substring (0,
-                                          path.length () -
-                                          1).lastIndexOf ("/")) + "/";
-  }
+       private boolean importOldBookmarks() {
+               String[] strs = sc.getStringArr("bookmarks");

-  public Bookmark getBookmarkByPath (String path) {
-    return (Bookmark) bookmarks.get (path);
-  }
+               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) {
+                               if (getCategoryByPath("/Imported/") == null)
+                                       addBookmark("/", new 
BookmarkCategory("Imported"), false);
+                               try {
+                                       addBookmark("/Imported/", new 
BookmarkItem(new FreenetURI(
+                                                       matcher.group(1)), 
matcher.group(2), node.alerts),
+                                                       false);
+                               } catch (MalformedURLException mue) {
+                               }
+                       } else
+                               return false;
+               }

-  public BookmarkCategory getCategoryByPath (String path) {
-    if (getBookmarkByPath (path) instanceof BookmarkCategory)
-      return (BookmarkCategory) getBookmarkByPath (path);
+               node.storeConfig();
+               return true;
+       }

-    return null;
-  }
+       public BookmarkCallback makeCB() {
+               return new BookmarkCallback();
+       }

-  public BookmarkItem getItemByPath (String path) {
-    if (getBookmarkByPath (path) instanceof BookmarkItem)
-      return (BookmarkItem) getBookmarkByPath (path);
+       public BookmarkCategory getMainCategory() {
+               return mainCategory;
+       }

-    return null;
-  }
+       public String parentPath(String path) {
+               if (path.equals("/"))
+                       return "/";

-  public void addBookmark (String parentPath, Bookmark bookmark,
-                          boolean store) throws NullPointerException {
-    BookmarkCategory parent = getCategoryByPath (parentPath);
-    if (parent == null)
-      throw new NullPointerException ();
-    else {
-      parent.addBookmark (bookmark);
-      putPaths(parentPath + bookmark.getName () + ((bookmark instanceof 
BookmarkCategory) ? "/" : ""), bookmark);
-      
-      if (((BookmarkItem) bookmark).getKeyType ().equals ("USK")) {
-               try {
-                 USK u = ((BookmarkItem) bookmark).getUSK ();
-                 this.node.uskManager.subscribe (u, this.uskcb, true, this);
-               }
-               catch (MalformedURLException mue) {
-               }
-           }
-    }
-    if (store)
-        node.storeConfig ();
-  }
+               return path.substring(0, path.substring(0, path.length() - 1)
+                               .lastIndexOf("/"))
+                               + "/";
+       }

-  // TODO
-  public void renameBookmark (String path, String newName) {
-    Bookmark bookmark = getBookmarkByPath (path);
-    bookmark.setName (newName);
-    if (bookmark instanceof BookmarkCategory) {
-      try {
-       makeCB ().set (makeCB ().get ());
+       public Bookmark getBookmarkByPath(String path) {
+               return (Bookmark) bookmarks.get(path);
+       }

-      }
-      catch (InvalidConfigValueException icve) {
-      }
-    }
+       public BookmarkCategory getCategoryByPath(String path) {
+               if (getBookmarkByPath(path) instanceof BookmarkCategory)
+                       return (BookmarkCategory) getBookmarkByPath(path);

-  }
-  
-  public void moveBookmark(String bookmarkPath, String newParentPath, boolean 
store) {
-       Bookmark b = getBookmarkByPath(bookmarkPath);
-       addBookmark(newParentPath, b, false);
-       
-       getCategoryByPath(parentPath(bookmarkPath)).removeBookmark(b);
-       removePaths(bookmarkPath);
-       
-       if (store)
-               node.storeConfig ();
-       
-  }
-  
-  public void removeBookmark (String path, boolean store) {
-    Bookmark bookmark = getBookmarkByPath (path);
-    if (bookmark == null)
-      return;
-
-    if (bookmark instanceof BookmarkCategory) {
-      BookmarkCategory cat = (BookmarkCategory) bookmark;
-      for (int i = 0; i < cat.size (); i++) {
-       removeBookmark (path + cat.get (i).getName () +
-                       ((cat.
-                         get (i) instanceof BookmarkCategory) ? "/" : ""),
-                       false);
-      }
-    }
-    else {
-      if (((BookmarkItem) bookmark).getKeyType ().equals ("USK")) {
-       try {
-         USK u = ((BookmarkItem) bookmark).getUSK ();
-         this.node.uskManager.unsubscribe (u, this.uskcb, true);
+               return null;
        }
-       catch (MalformedURLException mue) {
-       }
-      }
-    }

-    getCategoryByPath (parentPath (path)).
-      removeBookmark (getBookmarkByPath (path));
-    bookmarks.remove (path);
+       public BookmarkItem getItemByPath(String path) {
+               if (getBookmarkByPath(path) instanceof BookmarkItem)
+                       return (BookmarkItem) getBookmarkByPath(path);

-    if (store)
-      node.storeConfig ();
+               return null;
+       }

-  }
+       public void addBookmark(String parentPath, Bookmark bookmark, boolean 
store)
+                       throws NullPointerException {
+               BookmarkCategory parent = getCategoryByPath(parentPath);
+               if (parent == null)
+                       throw new NullPointerException();
+               else {
+                       parent.addBookmark(bookmark);
+                       putPaths(parentPath + bookmark.getName()
+                                       + ((bookmark instanceof 
BookmarkCategory) ? "/" : ""),
+                                       bookmark);

-  public void moveBookmarkUp (String path, boolean store) {
-    BookmarkCategory parent = getCategoryByPath (parentPath (path));
-    parent.moveBookmarkUp (getBookmarkByPath (path));
+                       if (((BookmarkItem) 
bookmark).getKeyType().equals("USK")) {
+                               try {
+                                       USK u = ((BookmarkItem) 
bookmark).getUSK();
+                                       this.node.uskManager.subscribe(u, 
this.uskcb, true, this);
+                               } catch (MalformedURLException mue) {
+                               }
+                       }
+               }
+               if (store)
+                       node.storeConfig();
+       }

-    if (store)
-      node.storeConfig ();
-  }
+       // TODO
+       public void renameBookmark(String path, String newName) {
+               Bookmark bookmark = getBookmarkByPath(path);
+               bookmark.setName(newName);
+               if (bookmark instanceof BookmarkCategory) {
+                       try {
+                               makeCB().set(makeCB().get());

-  public void moveBookmarkDown (String path, boolean store) {
-    BookmarkCategory parent = getCategoryByPath (parentPath (path));
-    parent.moveBookmarkDown (getBookmarkByPath (path));
+                       } catch (InvalidConfigValueException icve) {
+                       }
+               }

-    if (store)
-      node.storeConfig ();
-  }
+       }

-  private BookmarkCategory makeParents (String path) {
-    if (bookmarks.containsKey (path))
-      return getCategoryByPath (path);
-    else {
+       public void moveBookmark(String bookmarkPath, String newParentPath,
+                       boolean store) {
+               Bookmark b = getBookmarkByPath(bookmarkPath);
+               addBookmark(newParentPath, b, false);

-      int index = path.substring (0, path.length () - 1).lastIndexOf ("/");
-      String name = path.substring (index + 1, path.length () - 1);
+               getCategoryByPath(parentPath(bookmarkPath)).removeBookmark(b);
+               removePaths(bookmarkPath);

-      BookmarkCategory cat = new BookmarkCategory (name);
-      makeParents (parentPath (path));
-      addBookmark (parentPath (path), cat, false);
+               if (store)
+                       node.storeConfig();

-      return cat;
-    }
-  }
-  
-    private void putPaths(String path, Bookmark b) {
+       }

-    bookmarks.put(path , b);
-    if(b instanceof BookmarkCategory) {  
-         for(int i=0; i < ((BookmarkCategory) b).size(); i++) {
-                Bookmark child = ((BookmarkCategory) b).get(i);
-                putPaths(path + child.getName () + (child instanceof 
BookmarkItem ? "" : "/"), child);
-         }
-      }
+       public void removeBookmark(String path, boolean store) {
+               Bookmark bookmark = getBookmarkByPath(path);
+               if (bookmark == null)
+                       return;

-  }
-  
-    private void removePaths(String path) {
-       if(getBookmarkByPath(path) instanceof BookmarkCategory){
-               BookmarkCategory cat = getCategoryByPath(path);
-               for (int i=0; i < cat.size(); i++) {
-                       removePaths(path +cat.get(i).getName() + (cat.get(i) 
instanceof BookmarkCategory ? "/" : ""));
+               if (bookmark instanceof BookmarkCategory) {
+                       BookmarkCategory cat = (BookmarkCategory) bookmark;
+                       for (int i = 0; i < cat.size(); i++) {
+                               removeBookmark(
+                                               path
+                                                               + 
cat.get(i).getName()
+                                                               + ((cat.get(i) 
instanceof BookmarkCategory) ? "/"
+                                                                               
: ""), false);
+                       }
+               } else {
+                       if (((BookmarkItem) 
bookmark).getKeyType().equals("USK")) {
+                               try {
+                                       USK u = ((BookmarkItem) 
bookmark).getUSK();
+                                       this.node.uskManager.unsubscribe(u, 
this.uskcb, true);
+                               } catch (MalformedURLException mue) {
+                               }
+                       }
                }
+
+               getCategoryByPath(parentPath(path)).removeBookmark(
+                               getBookmarkByPath(path));
+               bookmarks.remove(path);
+
+               if (store)
+                       node.storeConfig();
+
        }
-       bookmarks.remove(path);
-  }

-  public void clear () {
+       public void moveBookmarkUp(String path, boolean store) {
+               BookmarkCategory parent = getCategoryByPath(parentPath(path));
+               parent.moveBookmarkUp(getBookmarkByPath(path));

-    removeBookmark ("/", false);
-    bookmarks.clear ();
+               if (store)
+                       node.storeConfig();
+       }

-    mainCategory = new BookmarkCategory ("/");
-    bookmarks.put ("/", mainCategory);
+       public void moveBookmarkDown(String path, boolean store) {
+               BookmarkCategory parent = getCategoryByPath(parentPath(path));
+               parent.moveBookmarkDown(getBookmarkByPath(path));

-  }
+               if (store)
+                       node.storeConfig();
+       }

-  public FreenetURI[] getBookmarkURIs () {
-    BookmarkItems items = mainCategory.getAllItems ();
-    FreenetURI[]uris = new FreenetURI[items.size ()];
-    for (int i = 0; i < items.size (); i++) {
-      uris[i] = items.get (i).getURI ();
-    }
+       private BookmarkCategory makeParents(String path) {
+               if (bookmarks.containsKey(path))
+                       return getCategoryByPath(path);
+               else {

-    return uris;
-  }
+                       int index = path.substring(0, path.length() - 
1).lastIndexOf("/");
+                       String name = path.substring(index + 1, path.length() - 
1);

+                       BookmarkCategory cat = new BookmarkCategory(name);
+                       makeParents(parentPath(path));
+                       addBookmark(parentPath(path), cat, false);

+                       return cat;
+               }
+       }

-/*
-       public void addBookmark(Bookmark b, boolean store) {
-               this.bookmarks.add(b);
-               if (b.getKeyType().equals("USK")) {
-                       try {
-                               USK u = b.getUSK();
-                               this.node.uskManager.subscribe(u, this.uskcb, 
true, this);
-                       } catch (MalformedURLException mue) {
-                               
+       private void putPaths(String path, Bookmark b) {
+
+               bookmarks.put(path, b);
+               if (b instanceof BookmarkCategory) {
+                       for (int i = 0; i < ((BookmarkCategory) b).size(); i++) 
{
+                               Bookmark child = ((BookmarkCategory) b).get(i);
+                               putPaths(path + child.getName()
+                                               + (child instanceof 
BookmarkItem ? "" : "/"), child);
                        }
                }
-               if(store && started) node.storeConfig();
+
        }
-       
-       public void removeBookmark(Bookmark b, boolean store) {
-               if (b.getKeyType().equals("USK")) {
-                       try {
-                               USK u = b.getUSK();
-                               this.node.uskManager.unsubscribe(u, this.uskcb, 
true);
-                       } catch (MalformedURLException mue) {
-                       
+
+       private void removePaths(String path) {
+               if (getBookmarkByPath(path) instanceof BookmarkCategory) {
+                       BookmarkCategory cat = getCategoryByPath(path);
+                       for (int i = 0; i < cat.size(); i++) {
+                               removePaths(path + cat.get(i).getName()
+                                               + (cat.get(i) instanceof 
BookmarkCategory ? "/" : ""));
                        }
                }
-               this.bookmarks.remove(b);
-               if(store && started) node.storeConfig();
+               bookmarks.remove(path);
        }
-       
-       public void moveBookmarkDown (Bookmark b, boolean store) {              
-               int i = this.bookmarks.indexOf(b);
-               if (i == -1) return;
-               
-               Bookmark bk = (Bookmark)this.bookmarks.get(i);
-               this.bookmarks.remove(i);
-               this.bookmarks.add((i+1)%(this.bookmarks.size()+1), bk);
-               
-               if(store && started) node.storeConfig();
+
+       public void clear() {
+
+               removeBookmark("/", false);
+               bookmarks.clear();
+
+               mainCategory = new BookmarkCategory("/");
+               bookmarks.put("/", mainCategory);
+
        }

-       public void moveBookmarkUp (Bookmark b, boolean store) {
-               int i = this.bookmarks.indexOf(b);
-               if (i == -1) return;
-               
-               Bookmark bk = (Bookmark)this.bookmarks.get(i);
-               this.bookmarks.remove(i);
-               if (--i < 0) i = this.bookmarks.size();
-               this.bookmarks.add(i, bk);
-               
-               if(store && started) node.storeConfig();
+       public FreenetURI[] getBookmarkURIs() {
+               BookmarkItems items = mainCategory.getAllItems();
+               FreenetURI[] uris = new FreenetURI[items.size()];
+               for (int i = 0; i < items.size(); i++) {
+                       uris[i] = items.get(i).getURI();
+               }
+
+               return uris;
        }
-       
-       public int getSize() {
-               return this.bookmarks.size();
-       }*/
+
+       /*
+        * public void addBookmark(Bookmark b, boolean store) {
+        * this.bookmarks.add(b); if (b.getKeyType().equals("USK")) { try { USK 
u =
+        * b.getUSK(); this.node.uskManager.subscribe(u, this.uskcb, true, 
this); }
+        * catch (MalformedURLException mue) {
+        *  } } if(store && started) node.storeConfig(); }
+        * 
+        * public void removeBookmark(Bookmark b, boolean store) { if
+        * (b.getKeyType().equals("USK")) { try { USK u = b.getUSK();
+        * this.node.uskManager.unsubscribe(u, this.uskcb, true); } catch
+        * (MalformedURLException mue) {
+        *  } } this.bookmarks.remove(b); if(store && started) 
node.storeConfig(); }
+        * 
+        * public void moveBookmarkDown (Bookmark b, boolean store) { int i =
+        * this.bookmarks.indexOf(b); if (i == -1) return;
+        * 
+        * Bookmark bk = (Bookmark)this.bookmarks.get(i); 
this.bookmarks.remove(i);
+        * this.bookmarks.add((i+1)%(this.bookmarks.size()+1), bk);
+        * 
+        * if(store && started) node.storeConfig(); }
+        * 
+        * public void moveBookmarkUp (Bookmark b, boolean store) { int i =
+        * this.bookmarks.indexOf(b); if (i == -1) return;
+        * 
+        * Bookmark bk = (Bookmark)this.bookmarks.get(i); 
this.bookmarks.remove(i);
+        * if (--i < 0) i = this.bookmarks.size(); this.bookmarks.add(i, bk);
+        * 
+        * if(store && started) node.storeConfig(); }
+        * 
+        * public int getSize() { return this.bookmarks.size(); }
+        */
 }


Reply via email to