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

fred at freenetproject.org fred at freenetproject.org
Mon Apr 23 23:12:05 UTC 2007


Author: fred
Date: 2007-04-23 23:12:05 +0000 (Mon, 23 Apr 2007)
New Revision: 12911

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:
minor changes

Modified: trunk/freenet/src/freenet/clients/http/bookmark/Bookmark.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/Bookmark.java	2007-04-23 22:49:37 UTC (rev 12910)
+++ trunk/freenet/src/freenet/clients/http/bookmark/Bookmark.java	2007-04-23 23:12:05 UTC (rev 12911)
@@ -1,35 +1,27 @@
 package freenet.clients.http.bookmark;
 
-public abstract class Bookmark
-{
-	protected boolean privateBookmark;
-	protected String name;
-	protected String desc;
-	
-	public boolean isPrivate()
-	{
-		return privateBookmark;
-	}
+public abstract class Bookmark {
+  protected boolean privateBookmark;
+  protected String name;
+  protected String desc;
 
-	public abstract void setPrivate(boolean bool);
-		
-	public String getName()
-	{
-		return name;
-	}
+  public boolean isPrivate () {
+    return privateBookmark;
+  } public abstract void setPrivate (boolean bool);
 
-	protected void setName(String s)
-	{
-		name = s;
-	}
+  public String getName () {
+    return name;
+  }
 
-	public String getDesc()
-	{
-		return desc;
-	}
+  protected void setName (String s) {
+    name = s;
+  }
 
-	public void setDesc(String s)
-	{
-		desc = 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-23 22:49:37 UTC (rev 12910)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategories.java	2007-04-23 23:12:05 UTC (rev 12911)
@@ -5,39 +5,31 @@
 import java.util.Iterator;
 
 
-public final class BookmarkCategories implements Iterable
+public final class BookmarkCategories	//implements Iterator
 {
 
-	Vector categories;
+  Vector categories;
 
-	public BookmarkCategories()
-	{
-		categories = new Vector();
-	}
+  public BookmarkCategories () {
+    categories = new Vector ();
+  } public BookmarkCategory get (int i) {
+    return (BookmarkCategory) categories.get (i);
+  }
 
-	public BookmarkCategory get(int i)
-	{
-		return (BookmarkCategory) categories.get(i);
-	}
+  public void add (BookmarkCategory bc) {
+    categories.add (bc);
+  }
 
-	public void add(BookmarkCategory bc)
-	{
-		categories.add(bc);
-	}
+  protected void extend (BookmarkCategories bc) {
+    for (int i = 0; i < bc.size (); i++)
+      add (bc.get (i));
+  }
 
-	protected void extend(BookmarkCategories bc)
-	{
-		for(int i = 0; i < bc.size(); i++)
-			add(bc.get(i));
-	}
-	
-	public int size()
-	{
-		return categories.size();
-	}
-	
-	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-23 22:49:37 UTC (rev 12910)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategory.java	2007-04-23 23:12:05 UTC (rev 12911)
@@ -6,150 +6,131 @@
 import freenet.support.StringArray;
 
 
-public class BookmarkCategory extends Bookmark implements Iterable
+public class BookmarkCategory extends Bookmark	// implements Iterator
 {
 
-	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);
-	}	
-	
-	protected Bookmark addBookmark(Bookmark b)
-	{
-		bookmarks.add(b);
-		return b;	
-	}
+  private final Vector bookmarks;
 
-	protected void removeBookmark(Bookmark b)
-	{
-		bookmarks.remove(b);
-	}
+  public BookmarkCategory (String name) {
+    bookmarks = new Vector ();
+    setName (name);
+  } public BookmarkCategory (String name, String desc) {
+    bookmarks = new Vector ();
+    setName (name);
+    setDesc (desc);
+  }
 
-	public Bookmark get(int i)
-	{
-		return (Bookmark) bookmarks.get(i);
-	}
-	
-	protected void moveBookmarkUp(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);
-	}
-	
-	protected void moveBookmarkDown(Bookmark b)
-	{
-		int index = bookmarks.indexOf(b);
-		if(index == -1)
-			return;
-		
-		Bookmark bk = get(index);
-		bookmarks.remove(index);
-		bookmarks.add((++index > size()) ? size() : index, bk);
-	}
-	
-	public int size()
-	{
-		return bookmarks.size();
-	}
-	
-	public BookmarkItems getItems()
-	{
-		BookmarkItems items = new BookmarkItems();
-		for(int i = 0; i < size();  i++) {
-			if(get(i) instanceof BookmarkItem)
-				items.add((BookmarkItem) get(i));
-		}
+  protected Bookmark addBookmark (Bookmark b) {
+    bookmarks.add (b);
+    return b;
+  }
 
-		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;
-	}
+  protected void removeBookmark (Bookmark b) {
+    bookmarks.remove (b);
+  }
 
-	
-	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;
-	}
-	
-	public BookmarkCategories getAllSubCategories()
-	{
-		BookmarkCategories categories = getSubCategories();
-		BookmarkCategories subCategories = getSubCategories();
-		
-		for(int i = 0; i < subCategories.size(); i++) {
-			categories.extend(subCategories.get(i).getAllSubCategories());
-		}
+  public Bookmark get (int i) {
+    return (Bookmark) bookmarks.get (i);
+  }
 
-		return categories;
-	}
-	
+  protected void moveBookmarkUp (Bookmark b) {
+    int index = bookmarks.indexOf (b);
+    if (index == -1)
+      return;
 
-	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 + "/";
-			
-		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));
+    Bookmark bk = get (index);
+    bookmarks.remove (index);
+    bookmarks.add ((--index < 0) ? 0 : index, bk);
+  }
 
-		return strings;
-		
-	}
-	
-	public void setPrivate(boolean bool)
-	{
-		privateBookmark = bool;
-		
-		BookmarkCategories subCategories = getSubCategories();
-		for(int i = 0; i < size(); i++)
-			subCategories.get(i).setPrivate(bool);
-	}
-	
-	public Iterator iterator()
-	{
-		return bookmarks.iterator();
-	}
-	
-}
+  protected void moveBookmarkDown (Bookmark b) {
+    int index = bookmarks.indexOf (b);
+    if (index == -1)
+      return;
 
+    Bookmark bk = get (index);
+    bookmarks.remove (index);
+    bookmarks.add ((++index > size ())? size () : index, bk);
+  }
+
+  public int size () {
+    return bookmarks.size ();
+  }
+
+  public BookmarkItems getItems () {
+    BookmarkItems items = new BookmarkItems ();
+    for (int i = 0; i < size (); i++) {
+      if (get (i) instanceof BookmarkItem)
+	items.add ((BookmarkItem) get (i));
+    }
+
+    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));
+    }
+
+    return categories;
+  }
+
+  public BookmarkCategories getAllSubCategories () {
+    BookmarkCategories categories = getSubCategories ();
+    BookmarkCategories subCategories = getSubCategories ();
+
+    for (int i = 0; i < subCategories.size (); i++) {
+      categories.extend (subCategories.get (i).getAllSubCategories ());
+    }
+
+    return categories;
+  }
+
+
+  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 + "/";
+
+    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));
+
+    return strings;
+
+  }
+
+  public void setPrivate (boolean bool) {
+    privateBookmark = bool;
+
+    BookmarkCategories subCategories = getSubCategories ();
+    for (int i = 0; i < size (); i++)
+      subCategories.get (i).setPrivate (bool);
+  }
+
+  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-23 22:49:37 UTC (rev 12910)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java	2007-04-23 23:12:05 UTC (rev 12911)
@@ -12,132 +12,131 @@
 
 import java.net.MalformedURLException;
 
-public class BookmarkItem extends Bookmark{
-	
-	private FreenetURI key;
-	private boolean updated;
-	private final BookmarkUpdatedUserAlert alert;
-	private UserAlertManager alerts;
-	
-	
-	public BookmarkItem(FreenetURI k, String n, UserAlertManager uam) throws MalformedURLException {
-		this.key = k;
-		this.name = n;
-		this.alerts = uam;
-		alert = new BookmarkUpdatedUserAlert();
-	}
+public class BookmarkItem extends Bookmark {
 
-	public BookmarkItem(FreenetURI k, String n, String d,  UserAlertManager uam) throws MalformedURLException {
-	
-		this.key = k;
-		this.name = n;
-		this.desc = d;
-		this.alerts = uam;
-		alert = new BookmarkUpdatedUserAlert();
-	}
-	
-	private class BookmarkUpdatedUserAlert implements UserAlert {
+  private FreenetURI key;
+  private boolean updated;
+  private final BookmarkUpdatedUserAlert alert;
+  private UserAlertManager alerts;
 
-		public boolean userCanDismiss() {
-			return true;
-		}
 
-		public String getTitle() {
-			return "Bookmark updated: "+ name;
-		}
+  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 {
 
-		public String getText() {
-			return "The bookmarked site "+ name +" has been updated to edition "+key.getSuggestedEdition();
-		}
+    this.key = k;
+    this.name = n;
+    this.desc = d;
+    this.alerts = uam;
+    alert = new BookmarkUpdatedUserAlert ();
+  } private class BookmarkUpdatedUserAlert implements UserAlert {
 
-		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 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 short getPriorityClass() {
-			return UserAlert.MINOR;
-		}
+    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 boolean isValid() {
-			synchronized(BookmarkItem.this) {
-				return updated;
-			}
-		}
+    public short getPriorityClass () {
+      return UserAlert.MINOR;
+    }
 
-		public void isValid(boolean validity) {
-			if(validity) return;
-			disableBookmark();
-		}
+    public boolean isValid () {
+      synchronized (BookmarkItem.this) {
+	return updated;
+      }
+    }
 
-		public String dismissButtonText() {
-			return "Delete notification";
-		}
+    public void isValid (boolean validity) {
+      if (validity)
+	return;
+      disableBookmark ();
+    }
 
-		public boolean shouldUnregisterOnDismiss() {
-			return true;
-		}
+    public String dismissButtonText () {
+      return "Delete notification";
+    }
 
-		public void onDismiss() {
-			disableBookmark();
-		}
-		
-	}
-	
-	private synchronized void disableBookmark() {
-		updated = false;
-		alerts.unregister(alert);
-	}
-	
-	private synchronized void enableBookmark() {
-		if(updated) return;
-		updated = true;
-		alerts.register(alert);
-	}
-	
-	public String getKey() {
-		return key.toString();
-	}
-	
-	public synchronized FreenetURI getURI() {
-		return key;
-	}
-	
-	public synchronized void setKey(FreenetURI uri) {
-		key = uri;
-	}
+    public boolean shouldUnregisterOnDismiss () {
+      return true;
+    }
 
-	public synchronized String getKeyType() {
-		return key.getKeyType();
-	}
+    public void onDismiss () {
+      disableBookmark ();
+    }
 
-	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();
-	}
+  private synchronized void disableBookmark () {
+    updated = false;
+    alerts.unregister (alert);
+  }
 
-	public USK getUSK() throws MalformedURLException {
-		return USK.create(key);
-	}
-}
+  private synchronized void enableBookmark () {
+    if (updated)
+      return;
+    updated = true;
+    alerts.register (alert);
+  }
+
+  public String getKey () {
+    return key.toString ();
+  }
+
+  public synchronized FreenetURI getURI () {
+    return 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-23 22:49:37 UTC (rev 12910)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItems.java	2007-04-23 23:12:05 UTC (rev 12911)
@@ -4,40 +4,32 @@
 import java.util.Iterator;
 
 
-public class BookmarkItems implements Iterable
+public class BookmarkItems	//implements Iterator
 {
 
-	Vector items;
-	
+  Vector items;
 
-	public BookmarkItems()
-	{
-		items = new Vector();
-	}
 
-	public BookmarkItem get(int i)
-	{
-		return (BookmarkItem) items.get(i);
-	}
+  public BookmarkItems () {
+    items = new Vector ();
+  } 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));
-	}
-	
-	public int size()
-	{
-		return items.size();
-	}
-	
-	public Iterator iterator()
-	{
-		return (items).iterator();
-	}
+  protected void extend (BookmarkItems bi) {
+    for (int i = 0; i < bi.size (); i++)
+      add (bi.get (i));
+  }
+
+  public int size () {
+    return items.size ();
+  }
+
+  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-23 22:49:37 UTC (rev 12910)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java	2007-04-23 23:12:05 UTC (rev 12911)
@@ -20,268 +20,301 @@
 
 public class BookmarkManager {
 
-	private final NodeClientCore node;
-	private USKUpdatedCallback uskcb;
-	private boolean started;
-	private BookmarkCategory mainCategory;
-	private HashMap bookmarks;
-	
-	public BookmarkManager(NodeClientCore n, SubConfig sc)
-	{
+  private final NodeClientCore node;
+  private USKUpdatedCallback uskcb;
+  private boolean started;
+  private BookmarkCategory mainCategory;
+  private HashMap bookmarks;
 
-		bookmarks = new HashMap();
-		mainCategory = new BookmarkCategory("/");
-		bookmarks.put("/", mainCategory);
+  public BookmarkManager (NodeClientCore n, SubConfig sc) {
 
-		this.uskcb = new USKUpdatedCallback();
-		this.node = n;
-				
-		try {
-			
-			BookmarkCategory defaultRoot = new BookmarkCategory("/");
-			
-			BookmarkCategory indexes = (BookmarkCategory) defaultRoot.addBookmark(new BookmarkCategory("Indicies"));
-			indexes.addBookmark(new BookmarkItem(new FreenetURI("USK at 7H66rhYmxIFgMyw5Dl11JazXGHPhp7dSN7WMa1pbtEo,jQHUQUPTkeRcjmjgrc7t5cDRdDkK3uKkrSzuw5CO9uk,AQACAAE/ENTRY.POINT/20/full/page1.html"),"Entry point", node.alerts));
-			indexes.addBookmark(new BookmarkItem(new FreenetURI("USK at BPZppy07RyID~NGihHgs4AAw3fUXxgtKIrwRu5rtpWE,k5yjkAFJC93JkydKl6vpY0Zy9D8ec1ymv2XP4Tx5Io0,AQABAAE/FreeHoo/6/"),"Free Hoo", node.alerts));
-	
-			BookmarkCategory flog = (BookmarkCategory) defaultRoot.addBookmark(new BookmarkCategory("Freenet devel's flog"));
-			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));
-			
-			BookmarkCategory apps = (BookmarkCategory) defaultRoot.addBookmark(new BookmarkCategory("Software"));
-			apps.addBookmark(new BookmarkItem(new FreenetURI("USK at XeMBryjuEaxqazEuxwnn~G7wCUOXFOZlVWbscdCOUFs,209eycYVidlZvhgL5V2a3INFxrofxzQctEZvyJaFL7I,AQABAAE/frost/2/"),"Frost", node.alerts));
-				
-			sc.register("bookmarks",defaultRoot.toStrings() , 0, true, false, "List of bookmarks", "A list of bookmarked freesites", makeCB());
-	
-			makeCB().set((sc.getStringArr("bookmarks").length == 0 ? defaultRoot.toStrings() : sc.getStringArr("bookmarks")));
-			
-		
-		} catch (MalformedURLException mue) {
-			// just ignore that one
-		} catch (InvalidConfigValueException icve){
-			//TODO
-			icve.printStackTrace();
-		}
-		
-		synchronized(this) {
-			started = true;
-		}
-	}
-	
-	public class BookmarkCallback implements StringArrCallback 
-	{
-		public String[] get() 
-		{
+    bookmarks = new HashMap ();
+    mainCategory = new BookmarkCategory ("/");
+    bookmarks.put ("/", mainCategory);
 
-			synchronized(BookmarkManager.this) {
+    this.uskcb = new USKUpdatedCallback ();
+    this.node = n;
 
-				return mainCategory.toStrings();
-				
-			}
-		}
+    try {
 
-		public void set(String[] newVals) throws InvalidConfigValueException 
-		{
-			clear();
-			Pattern pattern = Pattern.compile("/(.*/)([^/]*)=([A-Z]{3}@.*).*");
+      BookmarkCategory defaultRoot = new BookmarkCategory ("/");
 
-			FreenetURI key;
-			for (int i = 0; i < newVals.length; i++) {
-				try {
-					Matcher matcher = pattern.matcher(newVals[i]);
-					if(matcher.matches() && matcher.groupCount() == 3) {
+      BookmarkCategory indexes =
+	(BookmarkCategory) defaultRoot.
+	addBookmark (new BookmarkCategory ("Indexes"));
+        indexes.
+	addBookmark (new
+		     BookmarkItem (new
+				   FreenetURI
+				   ("USK at 7H66rhYmxIFgMyw5Dl11JazXGHPhp7dSN7WMa1pbtEo,jQHUQUPTkeRcjmjgrc7t5cDRdDkK3uKkrSzuw5CO9uk,AQACAAE/ENTRY.POINT/20/full/page1.html"),
+				   "Entry point", node.alerts));
+        indexes.
+	addBookmark (new
+		     BookmarkItem (new
+				   FreenetURI
+				   ("USK at BPZppy07RyID~NGihHgs4AAw3fUXxgtKIrwRu5rtpWE,k5yjkAFJC93JkydKl6vpY0Zy9D8ec1ymv2XP4Tx5Io0,AQABAAE/FreeHoo/6/"),
+				   "Free Hoo", node.alerts));
 
-						makeParents(matcher.group(1));
-						key  = new FreenetURI(matcher.group(3));
-						addBookmark(matcher.group(1),new BookmarkItem(key, matcher.group(2), node.alerts), false);
-					
-					}else
-						throw new InvalidConfigValueException("Malformed Bookmark");	
-					
-				} catch (MalformedURLException mue) {
-					throw new InvalidConfigValueException(mue.getMessage());
-				}
-			}
-		}
-	}
-	
-	private class USKUpdatedCallback implements USKCallback {
-		public void onFoundEdition(long edition, USK key) {
-			BookmarkItems items = mainCategory.getAllItems();
-			for (int i = 0; i < items.size(); i++) {
-				
-				
-				if (!items.get(i).getKeyType().equals("USK")) 
-					continue;
-				
-				try {
-					FreenetURI furi = new FreenetURI(items.get(i).getKey());
-					USK usk = USK.create(furi);
-					
-					if (usk.equals(key, false)) {
-						items.get(i).setEdition(key.suggestedEdition, node);
-						break;
-					}
-				} catch (MalformedURLException mue) {
-				}
-			}
-			node.storeConfig();
-		}
-	}
+      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));
 
-	public BookmarkCallback makeCB() {
-		return new BookmarkCallback();
-	}
+      BookmarkCategory apps =
+	(BookmarkCategory) defaultRoot.
+	addBookmark (new BookmarkCategory ("Freenet related software"));
+        apps.
+	addBookmark (new
+		     BookmarkItem (new
+				   FreenetURI
+				   ("USK at XeMBryjuEaxqazEuxwnn~G7wCUOXFOZlVWbscdCOUFs,209eycYVidlZvhgL5V2a3INFxrofxzQctEZvyJaFL7I,AQABAAE/frost/2/"),
+				   "Frost", node.alerts));
 
-	public BookmarkCategory getMainCategory()
-	{
-		return mainCategory;
-	}
+        sc.register ("bookmarks", defaultRoot.toStrings (), 0, true, false,
+		     "List of bookmarks", "A list of bookmarked freesites",
+		     makeCB ());
 
-	public String parentPath(String path)
-	{
-		if(path.equals("/"))
-			return "/";
+        makeCB ().
+	set ((sc.getStringArr ("bookmarks").length ==
+	      0 ? defaultRoot.toStrings () : sc.getStringArr ("bookmarks")));
 
-		return path.substring(0, path.substring(0,path.length() -1).lastIndexOf("/")) + "/";
-	}
 
-	public Bookmark getBookmarkByPath(String path)
-	{
-		return (Bookmark) bookmarks.get(path);
-	}
+    } catch (MalformedURLException mue) {
+      // just ignore that one
+    } catch (InvalidConfigValueException icve) {
+      //TODO
+      icve.printStackTrace ();
+    }
 
-	public BookmarkCategory getCategoryByPath(String path)
-	{
-		if(getBookmarkByPath(path) instanceof BookmarkCategory)
-			return (BookmarkCategory) getBookmarkByPath(path);
+    synchronized (this) {
+      started = true;
+    }
+  }
 
-		return null;
-	}
+  public class BookmarkCallback implements StringArrCallback {
+	  private final Pattern pattern = Pattern.compile ("/(.*/)([^/]*)=([A-Z]{3}@.*).*");
+    public String[] get () {
 
-	public BookmarkItem getItemByPath(String path)
-	{
-		if(getBookmarkByPath(path) instanceof BookmarkItem)
-			return (BookmarkItem) getBookmarkByPath(path);
+      synchronized (BookmarkManager.this) {
 
-		return null;
-	}
+	return mainCategory.toStrings ();
 
-	public void addBookmark(String parentPath, Bookmark b,  boolean store) throws NullPointerException
-	{
-		BookmarkCategory parent = getCategoryByPath(parentPath);
-		if(parent == null)
-			 throw new NullPointerException();
-		else {
-			parent.addBookmark(b);
-			bookmarks.put(parentPath + b.getName() + ((b instanceof BookmarkCategory) ? "/" : ""), b);
-		}	
-			
-		if(store)
-			node.storeConfig();
+    }}
+    
+    public void set (String[]newVals) throws InvalidConfigValueException {
+      clear ();
+
+      FreenetURI key;
+      for (int i = 0; i < newVals.length; i++) {
+	try {
+	  Matcher matcher = pattern.matcher (newVals[i]);
+	  if (matcher.matches () && matcher.groupCount () == 3) {
+
+	    makeParents (matcher.group (1));
+	    key = new FreenetURI (matcher.group (3));
+	    addBookmark (matcher.group (1),
+			 new BookmarkItem (key, matcher.group (2),
+					   node.alerts), false);
+
+	  }
+	  else
+	      throw new InvalidConfigValueException ("Malformed Bookmark");
+
 	}
-	
-	// TODO
-	public void renameBookmark(String path, String newName)
-	{
-		Bookmark bookmark = getBookmarkByPath(path);
-		bookmark.setName(newName);
-		if(bookmark instanceof BookmarkCategory) {
-			try {
-				makeCB().set(makeCB().get());
-				
-			} catch (InvalidConfigValueException icve) {	}
-		}
-	
+	catch (MalformedURLException mue) {
+	  throw new InvalidConfigValueException (mue.getMessage ());
 	}
+      }
+    }
+  }
 
-	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.subscribe(u, this.uskcb, true, this);
-				} catch (MalformedURLException mue) { }
-			}
-		}
+  private class USKUpdatedCallback implements USKCallback {
+    public void onFoundEdition (long edition, USK key) {
+      BookmarkItems items = mainCategory.getAllItems ();
+      for (int i = 0; i < items.size (); i++) {
 
-		getCategoryByPath(parentPath(path)).removeBookmark(getBookmarkByPath(path));
-		bookmarks.remove(path);
-		
-		if(store)
-			node.storeConfig();
 
+	if (!items.get (i).getKeyType ().equals ("USK"))
+	  continue;
+
+	try {
+	  FreenetURI furi = new FreenetURI (items.get (i).getKey ());
+	  USK usk = USK.create (furi);
+
+	  if (usk.equals (key, false)) {
+	    items.get (i).setEdition (key.suggestedEdition, node);
+	    break;
+	}}
+	catch (MalformedURLException mue) {
 	}
+      }
+      node.storeConfig ();
+    }
+  }
 
-	public void moveBookmarkUp(String path, boolean store)
-	{
-		BookmarkCategory parent = getCategoryByPath(parentPath(path));
-		parent.moveBookmarkUp(getBookmarkByPath(path));
-		
-		if(store)
-			node.storeConfig();
+  public BookmarkCallback makeCB () {
+    return new BookmarkCallback ();
+  }
+
+  public BookmarkCategory getMainCategory () {
+    return mainCategory;
+  }
+
+  public String parentPath (String path) {
+    if (path.equals ("/"))
+      return "/";
+
+    return path.substring (0,
+			   path.substring (0,
+					   path.length () -
+					   1).lastIndexOf ("/")) + "/";
+  }
+
+  public Bookmark getBookmarkByPath (String path) {
+    return (Bookmark) bookmarks.get (path);
+  }
+
+  public BookmarkCategory getCategoryByPath (String path) {
+    if (getBookmarkByPath (path) instanceof BookmarkCategory)
+      return (BookmarkCategory) getBookmarkByPath (path);
+
+    return null;
+  }
+
+  public BookmarkItem getItemByPath (String path) {
+    if (getBookmarkByPath (path) instanceof BookmarkItem)
+      return (BookmarkItem) getBookmarkByPath (path);
+
+    return null;
+  }
+
+  public void addBookmark (String parentPath, Bookmark b,
+			   boolean store) throws NullPointerException {
+    BookmarkCategory parent = getCategoryByPath (parentPath);
+    if (parent == null)
+      throw new NullPointerException ();
+    else {
+      parent.addBookmark (b);
+      bookmarks.put (parentPath + b.getName () +
+		     ((b instanceof BookmarkCategory) ? "/" : ""), b);
+    } 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 ());
+
+      }
+      catch (InvalidConfigValueException icve) {
+      }
+    }
+
+  }
+
+  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.subscribe (u, this.uskcb, true, this);
 	}
-		
-	public void moveBookmarkDown(String path, boolean store)
-	{
-		BookmarkCategory parent = getCategoryByPath(parentPath(path));
-		parent.moveBookmarkDown(getBookmarkByPath(path));
-		
-		if(store)
-			node.storeConfig();
+	catch (MalformedURLException mue) {
 	}
+      }
+    }
 
-	private BookmarkCategory makeParents(String path)
-	{
-		if(bookmarks.containsKey(path))
-			return getCategoryByPath(path);
-		else {
-			
-			int index =  path.substring(0, path.length()-1).lastIndexOf("/");
-			String name = path.substring(index +1, path.length() -1);
+    getCategoryByPath (parentPath (path)).
+      removeBookmark (getBookmarkByPath (path));
+    bookmarks.remove (path);
 
-			BookmarkCategory cat = new BookmarkCategory(name);
-			makeParents(parentPath(path));
-			addBookmark(parentPath(path), cat, false);
-	
-			return cat;
-		}	
-	}
-	
-	public void clear()
-	{
+    if (store)
+      node.storeConfig ();
 
-		removeBookmark("/", false);
-		bookmarks.clear();
+  }
 
-		mainCategory = new BookmarkCategory("/");
-		bookmarks.put("/", mainCategory);
+  public void moveBookmarkUp (String path, boolean store) {
+    BookmarkCategory parent = getCategoryByPath (parentPath (path));
+    parent.moveBookmarkUp (getBookmarkByPath (path));
 
-	}
-	
-	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;
-	}
-	
-	
-	
+    if (store)
+      node.storeConfig ();
+  }
+
+  public void moveBookmarkDown (String path, boolean store) {
+    BookmarkCategory parent = getCategoryByPath (parentPath (path));
+    parent.moveBookmarkDown (getBookmarkByPath (path));
+
+    if (store)
+      node.storeConfig ();
+  }
+
+  private BookmarkCategory makeParents (String path) {
+    if (bookmarks.containsKey (path))
+      return getCategoryByPath (path);
+    else {
+
+      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 clear () {
+
+    removeBookmark ("/", false);
+    bookmarks.clear ();
+
+    mainCategory = new BookmarkCategory ("/");
+    bookmarks.put ("/", mainCategory);
+
+  }
+
+  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 void addBookmark(Bookmark b, boolean store) {
 		this.bookmarks.add(b);




More information about the cvs mailing list