Author: nextgens
Date: 2007-11-19 19:01:05 +0000 (Mon, 19 Nov 2007)
New Revision: 15842

Modified:
   trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java
   trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java
   trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
   trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
Log:
BookmarkToadlet: now bookmarks can have an activelink or not... and we can 
change the flag.

It works for me but needs testing.

Modified: trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java   
2007-11-19 18:14:40 UTC (rev 15841)
+++ trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java   
2007-11-19 19:01:05 UTC (rev 15842)
@@ -15,6 +15,7 @@
 import freenet.l10n.L10n;
 import freenet.node.NodeClientCore;
 import freenet.client.HighLevelSimpleClient;
+import freenet.support.Fields;
 import freenet.support.HTMLNode;
 import freenet.support.URLDecoder;
 import freenet.support.URLEncodedFormatException;
@@ -212,9 +213,16 @@

                                        form.addChild("br");
                                        if (("edit".equals(action) && bookmark 
instanceof BookmarkItem) || "addItem".equals(action)) {
-                                               String key = 
(action.equals("edit") ? ((BookmarkItem) bookmark).getKey() : "");
+                                                BookmarkItem item = 
(BookmarkItem) bookmark;
+                                               String key = 
(action.equals("edit") ? item.getKey() : "");
                                                form.addChild("label", "for", 
"key", (L10n.getString("BookmarkEditorToadlet.keyLabel") + ' '));
                                                form.addChild("input", new 
String[]{"type", "id", "name", "size", "value"}, new String []{"text", "key", 
"key", "50", key});
+                                                form.addChild("br");
+                                                form.addChild("label", "for", 
"hasAnActivelink", 
(L10n.getString("BookmarkEditorToadlet.hasAnActivelinkLabel") + ' '));
+                                                if(item.hasAnActivelink())
+                                                    form.addChild("input", new 
String[]{"type", "id", "name", "checked" }, new String[]{"checkbox", 
"hasAnActivelink", "hasAnActivelink", String.valueOf(item.hasAnActivelink()) });
+                                                else
+                                                    form.addChild("input", new 
String[]{"type", "id", "name"}, new String[]{"checkbox", "hasAnActivelink", 
"hasAnActivelink" });
                                        }

                                        form.addChild("input", new String[] 
{"type", "name", "value"}, new String[] {"hidden", "bookmark",bookmarkPath});
@@ -296,8 +304,9 @@

                                if("edit".equals(action)) {
                                        
bookmarkManager.renameBookmark(bookmarkPath, name);
+                                        boolean hasAnActivelink = 
req.getPartAsString("hasAnActivelink", 5).equalsIgnoreCase("on");
                                        if(bookmark instanceof BookmarkItem)
-                                               ((BookmarkItem) 
bookmark).setKey(new FreenetURI(req.getPartAsString("key", MAX_KEY_LENGTH)));
+                                               ((BookmarkItem) 
bookmark).setKey(new FreenetURI(req.getPartAsString("key", MAX_KEY_LENGTH)), 
hasAnActivelink);

                                        HTMLNode successBox = 
content.addChild(pageMaker.getInfobox("infobox-success", 
L10n.getString("BookmarkEditorToadlet.changesSavedTitle")));
                                        
pageMaker.getContentNode(successBox).addChild("p", 
L10n.getString("BookmarkEditorToadlet.changesSaved"));
@@ -307,7 +316,8 @@
                                        Bookmark newBookmark;
                                        if("addItem".equals(action)) {
                                                FreenetURI key = new 
FreenetURI(req.getPartAsString("key", MAX_KEY_LENGTH));
-                                               newBookmark = new 
BookmarkItem(key, name, core.alerts);
+                                                boolean hasAnActivelink = 
req.getPartAsString("hasAnActivelink", 5).equalsIgnoreCase("on");
+                                               newBookmark = new 
BookmarkItem(key, name, hasAnActivelink, core.alerts);
                                        } else
                                                newBookmark = new 
BookmarkCategory(name);


Modified: trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java  2007-11-19 
18:14:40 UTC (rev 15841)
+++ trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java  2007-11-19 
19:01:05 UTC (rev 15842)
@@ -19,6 +19,7 @@
 import freenet.clients.http.bookmark.BookmarkItems;
 import freenet.clients.http.bookmark.BookmarkCategory;
 import freenet.clients.http.bookmark.BookmarkCategories;
+import freenet.clients.http.bookmark.BookmarkItem;
 import freenet.clients.http.bookmark.BookmarkManager;
 import freenet.keys.FreenetURI;
 import freenet.l10n.L10n;
@@ -72,11 +73,14 @@
        {
                BookmarkItems items = cat.getItems();
                for(int i = 0; i < items.size(); i++) {
+                        BookmarkItem item = items.get(i);
                        HTMLNode li = list.addChild("li", "class","item");
-                       HTMLNode a = li.addChild("a", "href", '/' + 
items.get(i).getKey());
-                        HTMLNode img = a.addChild("img", new String[] { "src", 
"height", "width", "alt"},
-                                new String[] { '/' + items.get(i).getKey() + 
"/activelink.png", "36px", "108px", "activelink"});
-                        img.addChild("#", "  " + items.get(i).getName());
+                       HTMLNode a = li.addChild("a", "href", '/' + 
item.getKey());
+                        if(item.hasAnActivelink()) {
+                            a.addChild("img", new String[] { "src", "height", 
"width", "alt"},
+                                new String[] { '/' + item.getKey() + 
"/activelink.png", "36px", "108px", "activelink"});
+                        }
+                        a.addChild("#", "  " + item.getName());
                }

                BookmarkCategories cats = cat.getSubCategories();

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java   
2007-11-19 18:14:40 UTC (rev 15841)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkItem.java   
2007-11-19 19:01:05 UTC (rev 15842)
@@ -19,23 +19,26 @@

        private FreenetURI key;
        private boolean updated;
+        private boolean hasAnActivelink = false;
        private final BookmarkUpdatedUserAlert alert;
        private final UserAlertManager alerts;

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

-       public BookmarkItem(FreenetURI k, String n, String d, UserAlertManager 
uam)
+       public BookmarkItem(FreenetURI k, String n, String d, boolean 
hasAnActivelink, UserAlertManager uam)
                        throws MalformedURLException {

                this.key = k;
                this.name = n;
                this.desc = d;
+                this.hasAnActivelink = hasAnActivelink;
                this.alerts = uam;
                alert = new BookmarkUpdatedUserAlert();
        }
@@ -116,8 +119,9 @@
                return key;
        }

-       public synchronized void setKey(FreenetURI uri) {
+       public synchronized void setKey(FreenetURI uri, boolean 
hasAnActivelink) {
                key = uri;
+                this.hasAnActivelink = hasAnActivelink;
        }

        public synchronized String getKeyType() {
@@ -133,7 +137,7 @@
        }

        public String toString() {
-               return this.name + '=' + this.key.toString();
+               return this.name + '=' + (hasAnActivelink ? "|=" : "=") + 
this.key.toString();
        }

        public synchronized void setEdition(long ed, NodeClientCore node) {
@@ -159,7 +163,12 @@
                                } else return false;
                        }
                        if(b.alerts != alerts) return false; // Belongs to a 
different node???
+                        if(b.hasAnActivelink != hasAnActivelink) return false;
                        return true;
                } else return false;
        }
+        
+        public boolean hasAnActivelink() {
+            return hasAnActivelink;
 }
+}

Modified: trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java        
2007-11-19 18:14:40 UTC (rev 15841)
+++ trunk/freenet/src/freenet/clients/http/bookmark/BookmarkManager.java        
2007-11-19 19:01:05 UTC (rev 15842)
@@ -16,6 +16,7 @@
 import freenet.l10n.L10n;
 import freenet.node.NodeClientCore;
 import freenet.support.api.StringArrCallback;
+import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

 public class BookmarkManager {

@@ -35,31 +36,31 @@
                        indexes.addBookmark(new BookmarkItem(
                                        new FreenetURI(
                                                        "USK at 
zQyF2O1o8B4y40w7Twz8y2I9haW3d2DTlxjTHPu7zc8,h2mhQNNE9aQvF~2yKAmKV1uorr7141-QOroBf5hrlbw,AQACAAE/AnotherIndex/33/"),
-                                                       "Another Index (large 
categorised index, many sites have no description)",
+                                                       "Another Index (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 (small French index with descriptions)",
+                                                       "Index des sites 
Fran?ais (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)",
+                                                       "The Start Of Freenet 
(another human-maintained index, so far relatively small)", false,
                                                        node.alerts));

                        indexes.addBookmark(new BookmarkItem(
                                        new FreenetURI(
                                                        "USK at 
7H66rhYmxIFgMyw5Dl11JazXGHPhp7dSN7WMa1pbtEo,jQHUQUPTkeRcjmjgrc7t5cDRdDkK3uKkrSzuw5CO9uk,AQACAAE/ENTRY.POINT/36/"),
-                                                       "Entry point (old, 
large index, hasn't been updated for a while)",
+                                                       "Entry point (old, 
large index, 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 (new one page index)",
+                                                       "The Ultimate FreeNet 
Index (new one page index)", false,
                                                        node.alerts));


@@ -67,20 +68,19 @@
                        flog.addBookmark(new BookmarkItem(
                                        new FreenetURI(
                                                        "USK at 
yGvITGZzrY1vUZK-4AaYLgcjZ7ysRqNTMfdcO8gS-LY,-ab5bJVD3Lp-LXEQqBAhJpMKrKJ19RnNaZMIkusU79s,AQACAAE/toad/7/"),
-                                                       "Toad", node.alerts));
+                                                       "Toad", true, 
node.alerts));
                        flog.addBookmark(new BookmarkItem(
                                        new FreenetURI(
                                                        "USK at 
hM9XRwjXIzU8xTSBXNZvTn2KuvTSRFnVn4EER9FQnpM,gsth24O7ud4gL4NwNuYJDUqfaWASOG2zxZY~ChtgPxc,AQACAAE/Flog/7/"),
-                                                       "Nextgen$", 
node.alerts));
+                                                       "Nextgen$", true, 
node.alerts));

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

                        sc.register("bookmarks", defaultRoot.toStrings(), 0, 
true, false,"BookmarkManager.list", "BookmarkManager.listLong", configCB);
-                       
                        configCB.set(sc.getStringArr("bookmarks"));
                } catch (MalformedURLException mue) {
                } catch (InvalidConfigValueException icve) {
@@ -89,7 +89,7 @@
        }

        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) {
@@ -102,17 +102,27 @@
                        clear();
                        for (int i = 0; i < newVals.length; i++) {
                                try {
-                                       Matcher matcher = 
pattern.matcher(newVals[i]);
-                                       if (matcher.matches() && 
matcher.groupCount() == 3) {
+                                Matcher matcher = pattern.matcher(newVals[i]);
+                                // FIXME: remove
+                                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);
+                                    makeParents(matcher.group(1));
+                                    key = new FreenetURI(matcher.group(3));
+                                    addBookmark(matcher.group(1), new 
BookmarkItem(key,
+                                            matcher.group(2), false, 
node.alerts), false);

-                                       } else
-                                               throw new 
InvalidConfigValueException(l10n("malformedBookmark"));
+                                } else if (matcher.matches() && 
matcher.groupCount() == 4) {

+                                    makeParents(matcher.group(1));
+                                    boolean hasAnActiveLink = 
"|=".equals(matcher.group(3));
+                                    key = new FreenetURI(matcher.group(4));
+                                    addBookmark(matcher.group(1), new 
BookmarkItem(key,
+                                            matcher.group(2), hasAnActiveLink, 
node.alerts), false);
+
+                                } else {
+                                    throw new 
InvalidConfigValueException(l10n("malformedBookmark"));
+                                }
+
                                } catch (MalformedURLException mue) {
                                        throw new 
InvalidConfigValueException(mue.getMessage());
                                }

Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2007-11-19 
18:14:40 UTC (rev 15841)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2007-11-19 
19:01:05 UTC (rev 15842)
@@ -22,6 +22,7 @@
 BookmarkEditorToadlet.editBookmarkTitle=Edit Bookmark
 BookmarkEditorToadlet.editCategoryTitle=Edit Category
 BookmarkEditorToadlet.error=Error
+BookmarkEditorToadlet.hasAnActivelinkLabel=Does the freesite have an active 
link?
 BookmarkEditorToadlet.invalidKeyTitle=Invalid Key
 BookmarkEditorToadlet.invalidKeyWithReason=Invalid Freenet key.
 BookmarkEditorToadlet.invalidKey=The Freenet key is invalid.


Reply via email to