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

nextgens at freenetproject.org nextgens at freenetproject.org
Tue Aug 14 03:33:36 UTC 2007


Author: nextgens
Date: 2007-08-14 03:33:35 +0000 (Tue, 14 Aug 2007)
New Revision: 14674

Modified:
   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:
Cleanup the bookmark code a bit

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategories.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategories.java	2007-08-14 03:14:09 UTC (rev 14673)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategories.java	2007-08-14 03:33:35 UTC (rev 14674)
@@ -1,17 +1,10 @@
 package freenet.clients.http.bookmark;
 
 import java.util.Vector;
-import java.util.Iterator;
 
-public final class BookmarkCategories // implements Iterator
-{
+public final class BookmarkCategories {
+	private final Vector categories = new Vector();
 
-	Vector categories;
-
-	public BookmarkCategories() {
-		categories = new Vector();
-	}
-
 	public BookmarkCategory get(int i) {
 		return (BookmarkCategory) categories.get(i);
 	}
@@ -28,8 +21,4 @@
 	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-08-14 03:14:09 UTC (rev 14673)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategory.java	2007-08-14 03:33:35 UTC (rev 14674)
@@ -1,22 +1,18 @@
 package freenet.clients.http.bookmark;
 
 import java.util.Vector;
-import java.util.Iterator;
 
 import freenet.support.StringArray;
 
-public class BookmarkCategory extends Bookmark // implements Iterator
-{
+public class BookmarkCategory extends Bookmark {
 
-	private final Vector bookmarks;
+	private final Vector bookmarks = new Vector();
 
 	public BookmarkCategory(String name) {
-		bookmarks = new Vector();
 		setName(name);
 	}
 
 	public BookmarkCategory(String name, String desc) {
-		bookmarks = new Vector();
 		setName(name);
 		setDesc(desc);
 	}
@@ -127,9 +123,4 @@
 		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-08-14 03:14:09 UTC (rev 14673)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java	2007-08-14 03:33:35 UTC (rev 14674)
@@ -17,11 +17,8 @@
 public class BookmarkItem extends Bookmark {
 
 	private FreenetURI key;
-
 	private boolean updated;
-
 	private final BookmarkUpdatedUserAlert alert;
-
 	private final UserAlertManager alerts;
 
 	public BookmarkItem(FreenetURI k, String n, UserAlertManager uam)
@@ -135,11 +132,7 @@
 	}
 
 	public String getName() {
-		if (name.equals("")) {
-			return l10n("unnamedBookmark");
-		} else {
-			return name;
-		}
+		return ("".equals(name) ? l10n("unnamedBookmark") : name);
 	}
 
 	public void setPrivate(boolean bool) {
@@ -147,7 +140,7 @@
 	}
 
 	public String toString() {
-		return this.name + "=" + this.key.toString();
+		return this.name + '=' + this.key.toString();
 	}
 
 	public synchronized void setEdition(long ed, NodeClientCore node) {

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItems.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItems.java	2007-08-14 03:14:09 UTC (rev 14673)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItems.java	2007-08-14 03:33:35 UTC (rev 14674)
@@ -1,17 +1,10 @@
 package freenet.clients.http.bookmark;
 
 import java.util.Vector;
-import java.util.Iterator;
 
-public class BookmarkItems // implements Iterator
-{
+public class BookmarkItems {
+	private final Vector items = new Vector();
 
-	Vector items;
-
-	public BookmarkItems() {
-		items = new Vector();
-	}
-
 	public BookmarkItem get(int i) {
 		return (BookmarkItem) items.get(i);
 	}
@@ -28,8 +21,4 @@
 	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-08-14 03:14:09 UTC (rev 14673)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java	2007-08-14 03:33:35 UTC (rev 14674)
@@ -20,29 +20,15 @@
 public class BookmarkManager {
 
 	private final NodeClientCore node;
+	private final USKUpdatedCallback uskcb = new USKUpdatedCallback();
+	private final BookmarkCategory mainCategory = new BookmarkCategory("/");;
+	private final HashMap bookmarks = new HashMap();
 
-	private USKUpdatedCallback uskcb;
-
-	private boolean started;
-
-	private BookmarkCategory mainCategory;
-
-	private HashMap bookmarks;
-
-	private SubConfig sc;
-
 	public BookmarkManager(NodeClientCore n, SubConfig sc) {
-
-		bookmarks = new HashMap();
-		mainCategory = new BookmarkCategory("/");
 		bookmarks.put("/", mainCategory);
-
-		this.uskcb = new USKUpdatedCallback();
 		this.node = n;
-		this.sc = sc;
 
 		try {
-
 			BookmarkCategory defaultRoot = new BookmarkCategory("/");
 
 			BookmarkCategory indexes = (BookmarkCategory) defaultRoot
@@ -87,10 +73,7 @@
 					"BookmarkManager.list", "BookmarkManager.listLong",
 					makeCB());
 
-			if (!importOldBookmarks())
-				makeCB().set(
-						(sc.getStringArr("bookmarks").length == 0 ? defaultRoot
-								.toStrings() : sc.getStringArr("bookmarks")));
+			makeCB().set((sc.getStringArr("bookmarks").length == 0 ? defaultRoot.toStrings() : sc.getStringArr("bookmarks")));
 
 		} catch (MalformedURLException mue) {
 			// just ignore that one
@@ -98,28 +81,20 @@
 			// TODO
 			icve.printStackTrace();
 		}
-
-		synchronized (this) {
-			started = true;
-		}
 	}
 
 	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 {
 			clear();
-
+			
 			FreenetURI key;
 			for (int i = 0; i < newVals.length; i++) {
 				try {
@@ -145,8 +120,7 @@
 		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"))
+				if (!"USK".equals(items.get(i).getKeyType()))
 					continue;
 
 				try {
@@ -164,29 +138,6 @@
 		}
 	}
 
-	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) {
-				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;
-		}
-
-		node.storeConfig();
-		return true;
-	}
-
 	public String l10n(String key) {
 		return L10n.getString("BookmarkManager."+key);
 	}
@@ -226,23 +177,18 @@
 		return null;
 	}
 
-	public void addBookmark(String parentPath, Bookmark bookmark, boolean store)
-	throws NullPointerException {
+	public void addBookmark(String parentPath, Bookmark bookmark, boolean store) {
 		BookmarkCategory parent = getCategoryByPath(parentPath);
-		if (parent == null)
-			throw new NullPointerException();
-		else {
-			parent.addBookmark(bookmark);
-			putPaths(parentPath + bookmark.getName()
-					+ ((bookmark instanceof BookmarkCategory) ? "/" : ""),
-					bookmark);
+		parent.addBookmark(bookmark);
+		putPaths(parentPath + bookmark.getName()
+				+ ((bookmark instanceof BookmarkCategory) ? "/" : ""),
+				bookmark);
 
-			if (bookmark instanceof BookmarkItem && ((BookmarkItem) bookmark).getKeyType().equals("USK")) {
-				try {
-					USK u = ((BookmarkItem) bookmark).getUSK();
-					this.node.uskManager.subscribe(u, this.uskcb, true, this);
-				} catch (MalformedURLException mue) {
-				}
+		if (bookmark instanceof BookmarkItem && ((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)
@@ -256,15 +202,11 @@
 		if (bookmark instanceof BookmarkCategory) {
 			try {
 				makeCB().set(makeCB().get());
-
-			} catch (InvalidConfigValueException icve) {
-			}
+			} catch (InvalidConfigValueException icve) {}
 		}
-
 	}
 
-	public void moveBookmark(String bookmarkPath, String newParentPath,
-			boolean store) {
+	public void moveBookmark(String bookmarkPath, String newParentPath, boolean store) {
 		Bookmark b = getBookmarkByPath(bookmarkPath);
 		addBookmark(newParentPath, b, false);
 
@@ -273,7 +215,6 @@
 
 		if (store)
 			node.storeConfig();
-
 	}
 
 	public void removeBookmark(String path, boolean store) {
@@ -306,7 +247,6 @@
 
 		if (store)
 			node.storeConfig();
-
 	}
 
 	public void moveBookmarkUp(String path, boolean store) {
@@ -366,13 +306,9 @@
 	}
 
 	public void clear() {
-
 		removeBookmark("/", false);
 		bookmarks.clear();
-
-		mainCategory = new BookmarkCategory("/");
 		bookmarks.put("/", mainCategory);
-
 	}
 
 	public FreenetURI[] getBookmarkURIs() {
@@ -384,36 +320,4 @@
 
 		return uris;
 	}
-
-	/*
-	 * 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(); }
-	 */
 }




More information about the cvs mailing list