Author: nextgens
Date: 2007-11-30 00:05:10 +0000 (Fri, 30 Nov 2007)
New Revision: 16107
Added:
trunk/freenet/src/freenet/clients/http/staticfiles/defaultbookmarks.dat
Modified:
trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategory.java
trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
Log:
BookmarkManager: restore the same level of functionality as we had on 1075.
We probably want to be able to show "new" bookmarks to the user somehow though
Modified: trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2007-11-29
23:55:39 UTC (rev 16106)
+++ trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2007-11-30
00:05:10 UTC (rev 16107)
@@ -552,7 +552,6 @@
HTMLNode bookmarkBoxContent = bookmarkBox.addChild("div", "class",
"infobox-content");
HTMLNode bookmarksList = bookmarkBoxContent.addChild("ul", "id",
"bookmarks");
addCategoryToList(BookmarkManager.MAIN_CATEGORY, bookmarksList);
- addCategoryToList(BookmarkManager.PROTECTED_CATEGORY, bookmarksList);
// Fetch-a-key box
HTMLNode fetchKeyBox =
contentNode.addChild(ctx.getPageMaker().getInfobox("infobox-normal",
l10n("fetchKeyLabel")));
Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategory.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategory.java
2007-11-29 23:55:39 UTC (rev 16106)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkCategory.java
2007-11-30 00:05:10 UTC (rev 16107)
@@ -25,9 +25,10 @@
if (b == null) {
return null;
}
+ // Overwrite any existing bookmark
int x = bookmarks.indexOf(b);
if (x >= 0) {
- return (Bookmark) bookmarks.get(x);
+ bookmarks.remove(x);
}
bookmarks.add(b);
return b;
Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
2007-11-29 23:55:39 UTC (rev 16106)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
2007-11-30 00:05:10 UTC (rev 16107)
@@ -25,58 +25,41 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Iterator;
public class BookmarkManager {
-
+ public static SimpleFieldSet DEFAULT_BOOKMARKS = null;
private final NodeClientCore node;
private final USKUpdatedCallback uskCB = new USKUpdatedCallback();
public static final BookmarkCategory MAIN_CATEGORY = new
BookmarkCategory("/");
- public static final BookmarkCategory PROTECTED_CATEGORY = new
BookmarkCategory("/protected");
private final HashMap bookmarks = new HashMap();
private final File bookmarksFile = new
File("bookmarks.dat").getAbsoluteFile();
private final File backupBookmarksFile = new
File(bookmarksFile.getParentFile(), bookmarksFile.getName()+".bak");
private boolean isSavingBookmarks = false;
+ static {
+ String name =
"freenet/clients/http/staticfiles/defaultbookmarks.dat";
+ InputStream in = null;
+ try {
+ ClassLoader loader = ClassLoader.getSystemClassLoader();
+
+ // Returns null on lookup failures:
+ in = loader.getResourceAsStream(name);
+ if(in != null)
+ DEFAULT_BOOKMARKS = SimpleFieldSet.readFrom(in,
false, false);
+ } catch(Exception e) {
+ Logger.error("BookmarkManager", "Error while loading
the default bookmark file from " + name + " :" + e.getMessage(), e);
+ } finally {
+ Closer.close(in);
+ }
+ }
+
public BookmarkManager(NodeClientCore n, SimpleFieldSet oldConfig) {
- bookmarks.put("/", MAIN_CATEGORY);
+ putPaths("/", MAIN_CATEGORY);
this.node = n;
try {
- BookmarkCategory indexes = (BookmarkCategory)
PROTECTED_CATEGORY.addBookmark(new BookmarkCategory("Indexes"));
- indexes.addBookmark(new BookmarkItem(new FreenetURI("USK at
zQyF2O1o8B4y40w7Twz8y2I9haW3d2DTlxjTHPu7zc8,h2mhQNNE9aQvF~2yKAmKV1uorr7141-QOroBf5hrlbw,AQACAAE/AnotherIndex/33/"),
- "Another Index", "A large categorised index, many sites
have no description", false,
- node.alerts));
-
- indexes.addBookmark(new BookmarkItem(new FreenetURI("USK at
RJnh1EnvOSPwOWVRS2nyhC4eIQkKoNE5hcTv7~yY-sM,pOloLxnKWM~AL24iDMHOAvTvCqMlB-p2BO9zK96TOZA,AQACAAE/index_fr/21/"),
- "Index des sites Fran?ais", "A small French index with
descriptions", false,
- node.alerts));
-
- indexes.addBookmark(new BookmarkItem(new FreenetURI("USK at
cvZEZFWynx~4hmakaimts4Ruusl9mEUpU6mSvNvZ9p8,K2Xopc6GWPkKrs27EDuqzTcca2bE5H2YAXw0qKnkON4,AQACAAE/TSOF/2/"),
- "The Start Of Freenet", "Another human-maintained index,
so far relatively small", true,
- node.alerts));
-
- indexes.addBookmark(new BookmarkItem(new FreenetURI("USK at
7H66rhYmxIFgMyw5Dl11JazXGHPhp7dSN7WMa1pbtEo,jQHUQUPTkeRcjmjgrc7t5cDRdDkK3uKkrSzuw5CO9uk,AQACAAE/ENTRY.POINT/36/"),
- "Entry point", "An old, large index, wich hasn't been
updated for a while", true,
- node.alerts));
-
- indexes.addBookmark(new BookmarkItem(new FreenetURI("USK at
0I8gctpUE32CM0iQhXaYpCMvtPPGfT4pjXm01oid5Zc,3dAcn4fX2LyxO6uCnWFTx-2HKZ89uruurcKwLSCxbZ4,AQACAAE/Ultimate-Freenet-Index/1/"),
- "The Ultimate FreeNet Index", "A new one; page index",
false,
- node.alerts));
-
-
- BookmarkCategory flog = (BookmarkCategory)
PROTECTED_CATEGORY.addBookmark(new BookmarkCategory("Freenet devel's flogs"));
- flog.addBookmark(new BookmarkItem(new FreenetURI("USK at
yGvITGZzrY1vUZK-4AaYLgcjZ7ysRqNTMfdcO8gS-LY,-ab5bJVD3Lp-LXEQqBAhJpMKrKJ19RnNaZMIkusU79s,AQACAAE/toad/7/"),
- "Toad", "Toad's blog", true, node.alerts));
- flog.addBookmark(new BookmarkItem(new FreenetURI("USK at
hM9XRwjXIzU8xTSBXNZvTn2KuvTSRFnVn4EER9FQnpM,gsth24O7ud4gL4NwNuYJDUqfaWASOG2zxZY~ChtgPxc,AQACAAE/Flog/7/"),
- "Nextgen$", "NextGen$' blog", true, node.alerts));
- flog.addBookmark(new BookmarkItem(new FreenetURI("USK at
e3myoFyp5avg6WYN16ImHri6J7Nj8980Fm~aQe4EX1U,QvbWT0ImE0TwLODTl7EoJx2NBnwDxTbLTE6zkB-eGPs,AQACAAE/bombe/10/"),
- "Bombe", "Bombe's blog", true, node.alerts));
-
- BookmarkCategory apps = (BookmarkCategory)
PROTECTED_CATEGORY.addBookmark(new BookmarkCategory("Freenet related
software"));
- apps.addBookmark(new BookmarkItem(new FreenetURI("USK at
QRZAI1nSm~dAY2hTdzVWXmEhkaI~dso0OadnppBR7kE,wq5rHGBI7kpChBe4yRmgBChIGDug7Xa5SG9vYGXdxR0,AQACAAE/frost/4"),
- "Frost", "The official freesite of Frost", true,
node.alerts));
-
//TODO: remove
String[] oldBookmarks = null;
if(oldConfig != null) {
@@ -112,14 +95,31 @@
Logger.normal(this, "Attempting to read the backup
bookmark file from " + backupBookmarksFile.toString());
SimpleFieldSet sfs =
SimpleFieldSet.readFrom(backupBookmarksFile, false, true);
readBookmarks(MAIN_CATEGORY, sfs);
- } else
+ } else {
Logger.normal(this, "We couldn't find the backup either! -
"+FileUtil.getCanonicalFile(backupBookmarksFile));
+ // restore the default bookmark set
+ readBookmarks(MAIN_CATEGORY, DEFAULT_BOOKMARKS);
+ }
} catch (IOException e) {
Logger.error(this, "Error reading the backup bookmark file !"
+ e.getMessage(), e);
}
}
}
+ private void registerProtectedItems(String prefix, BookmarkCategory
current) {
+ BookmarkCategories categories = current.getSubCategories();
+ for(int i=0; i<categories.size(); i++) {
+ BookmarkCategory cat = categories.get(i);
+ String name = ("".equals(prefix) ? "" : prefix+'/') + cat.name;
+ addBookmark(prefix, cat);
+ registerProtectedItems(name, cat);
+ }
+
+ BookmarkItems items = current.getItems();
+ for(int i=0; i<items.size(); i++)
+ addBookmark(prefix, items.get(i));
+ }
+
private void migrateOldBookmarks(String[] newVals) {
if(Logger.shouldLog(Logger.MINOR, this))
Logger.minor(this, "Migrating bookmarks:
"+StringArray.toString(newVals));
Added: trunk/freenet/src/freenet/clients/http/staticfiles/defaultbookmarks.dat
===================================================================
--- trunk/freenet/src/freenet/clients/http/staticfiles/defaultbookmarks.dat
(rev 0)
+++ trunk/freenet/src/freenet/clients/http/staticfiles/defaultbookmarks.dat
2007-11-30 00:05:10 UTC (rev 16107)
@@ -0,0 +1,49 @@
+BookmarkCategory=3
+Version=1
+Bookmark=0
+BookmarkCategory0.Name=Indexes
+BookmarkCategory0.Content.BookmarkCategory=0
+BookmarkCategory0.Content.Bookmark=5
+BookmarkCategory0.Content.Bookmark4.Name=The Ultimate FreeNet Index
+BookmarkCategory0.Content.Bookmark4.Description=A new one; page index
+BookmarkCategory0.Content.Bookmark4.hasAnActivelink=false
+BookmarkCategory0.Content.Bookmark4.URI=USK at
0I8gctpUE32CM0iQhXaYpCMvtPPGfT4pjXm01oid5Zc,3dAcn4fX2LyxO6uCnWFTx-2HKZ89uruurcKwLSCxbZ4,AQACAAE/Ultimate-Freenet-Index/1/
+BookmarkCategory0.Content.Bookmark3.Name=Entry point
+BookmarkCategory0.Content.Bookmark3.Description=An old, large index, wich
hasn't been updated for a while
+BookmarkCategory0.Content.Bookmark3.hasAnActivelink=true
+BookmarkCategory0.Content.Bookmark3.URI=USK at
7H66rhYmxIFgMyw5Dl11JazXGHPhp7dSN7WMa1pbtEo,jQHUQUPTkeRcjmjgrc7t5cDRdDkK3uKkrSzuw5CO9uk,AQACAAE/ENTRY.POINT/36/
+BookmarkCategory0.Content.Bookmark2.Name=The Start Of Freenet
+BookmarkCategory0.Content.Bookmark2.Description=Another human-maintained
index, so far relatively small
+BookmarkCategory0.Content.Bookmark2.hasAnActivelink=true
+BookmarkCategory0.Content.Bookmark2.URI=USK at
cvZEZFWynx~4hmakaimts4Ruusl9mEUpU6mSvNvZ9p8,K2Xopc6GWPkKrs27EDuqzTcca2bE5H2YAXw0qKnkON4,AQACAAE/TSOF/2/
+BookmarkCategory0.Content.Bookmark1.Name=Index des sites Fran?ais
+BookmarkCategory0.Content.Bookmark1.Description=A small French index with
descriptions
+BookmarkCategory0.Content.Bookmark1.hasAnActivelink=false
+BookmarkCategory0.Content.Bookmark1.URI=USK at
RJnh1EnvOSPwOWVRS2nyhC4eIQkKoNE5hcTv7~yY-sM,pOloLxnKWM~AL24iDMHOAvTvCqMlB-p2BO9zK96TOZA,AQACAAE/index_fr/21/
+BookmarkCategory0.Content.Bookmark0.Name=Another Index
+BookmarkCategory0.Content.Bookmark0.Description=A large categorised index,
many sites have no description
+BookmarkCategory0.Content.Bookmark0.hasAnActivelink=false
+BookmarkCategory0.Content.Bookmark0.URI=USK at
zQyF2O1o8B4y40w7Twz8y2I9haW3d2DTlxjTHPu7zc8,h2mhQNNE9aQvF~2yKAmKV1uorr7141-QOroBf5hrlbw,AQACAAE/AnotherIndex/33/
+BookmarkCategory1.Name=Freenet devel's flogs
+BookmarkCategory1.Content.BookmarkCategory=0
+BookmarkCategory1.Content.Bookmark=3
+BookmarkCategory1.Content.Bookmark2.Name=Bombe
+BookmarkCategory1.Content.Bookmark2.Description=Bombe's blog
+BookmarkCategory1.Content.Bookmark2.hasAnActivelink=true
+BookmarkCategory1.Content.Bookmark2.URI=USK at
e3myoFyp5avg6WYN16ImHri6J7Nj8980Fm~aQe4EX1U,QvbWT0ImE0TwLODTl7EoJx2NBnwDxTbLTE6zkB-eGPs,AQACAAE/bombe/10/
+BookmarkCategory1.Content.Bookmark1.Name=Nextgen$
+BookmarkCategory1.Content.Bookmark1.Description=NextGen$' blog
+BookmarkCategory1.Content.Bookmark1.hasAnActivelink=true
+BookmarkCategory1.Content.Bookmark1.URI=USK at
hM9XRwjXIzU8xTSBXNZvTn2KuvTSRFnVn4EER9FQnpM,gsth24O7ud4gL4NwNuYJDUqfaWASOG2zxZY~ChtgPxc,AQACAAE/Flog/7/
+BookmarkCategory1.Content.Bookmark0.Name=Toad
+BookmarkCategory1.Content.Bookmark0.Description=Toad's blog
+BookmarkCategory1.Content.Bookmark0.hasAnActivelink=true
+BookmarkCategory1.Content.Bookmark0.URI=USK at
yGvITGZzrY1vUZK-4AaYLgcjZ7ysRqNTMfdcO8gS-LY,-ab5bJVD3Lp-LXEQqBAhJpMKrKJ19RnNaZMIkusU79s,AQACAAE/toad/7/
+BookmarkCategory2.Name=Freenet related software
+BookmarkCategory2.Content.BookmarkCategory=0
+BookmarkCategory2.Content.Bookmark=1
+BookmarkCategory2.Content.Bookmark0.Name=Frost
+BookmarkCategory2.Content.Bookmark0.Description=The official freesite of Frost
+BookmarkCategory2.Content.Bookmark0.hasAnActivelink=true
+BookmarkCategory2.Content.Bookmark0.URI=USK at
QRZAI1nSm~dAY2hTdzVWXmEhkaI~dso0OadnppBR7kE,wq5rHGBI7kpChBe4yRmgBChIGDug7Xa5SG9vYGXdxR0,AQACAAE/frost/4
+End
\ No newline at end of file