Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

Experimental code (I need to transfer the code to my macbook, sorry) for the new bookmarks API based on the Tables concept (same as for crawl starts). Currently you can add a bookmark by api/ymarks/add_ymark.xml?url=http://www.yacy.net&title=YaCy and watch the result via the standard view Tables_p.html.

apfelmaennchen4270ed696ce2
diff --git a/htroot/api/ymarks/add_ymark.java b/htroot/api/ymarks/add_ymark.java
new file mode 100644
index 000000000..ec1b87295
--- /dev/null
+++ b/htroot/api/ymarks/add_ymark.java
@@ -0,0 +1,96 @@
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Date;
+
+import net.yacy.cora.protocol.RequestHeader;
+import net.yacy.kelondro.blob.Tables;
+import net.yacy.kelondro.blob.Tables.Data;
+import net.yacy.kelondro.data.meta.DigestURI;
+import net.yacy.kelondro.index.RowSpaceExceededException;
+import net.yacy.kelondro.logging.Log;
+import net.yacy.kelondro.util.DateFormatter;
+import de.anomic.data.YMarkStatics;
+import de.anomic.data.userDB;
+import de.anomic.search.Switchboard;
+import de.anomic.server.serverObjects;
+import de.anomic.server.serverSwitch;
+
+
+public class add_ymark {
+
+ public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
+ final Switchboard sb = (Switchboard) env;
+ final serverObjects prop = new serverObjects();
+
+ final userDB.Entry user = sb.userDB.getUser(header);
+ final boolean isAdmin = (sb.verifyAuthentication(header, true));
+ final boolean isAuthUser = user!= null && user.hasRight(userDB.Entry.BOOKMARK_RIGHT);
+
+ if(isAdmin || isAuthUser) {
+ final String table = (isAuthUser ? user.getUserName() : "admin")+"_"+YMarkStatics.TABLE_BOOKMARKS_BASENAME;
+
+ String url = post.get(YMarkStatics.TABLE_BOOKMARKS_COL_URL,"");
+ if (!url.toLowerCase().startsWith("http://") && !url.toLowerCase().startsWith("https://")) {
+ url="http://"+url;
+ }
+ // generate the url hash
+ byte[] pk = null;
+ try {
+ pk = (new DigestURI(url, null)).hash();
+ } catch (MalformedURLException e) {
+ Log.logException(e);
+ }
+ assert pk != null;
+
+ // read old entry from the bookmarks table (if exists)
+ Tables.Row row = null;
+ try {
+ row = sb.tables.select(table, pk);
+ } catch (IOException e) {
+ Log.logException(e);
+ } catch (RowSpaceExceededException e) {
+ Log.logException(e);
+ }
+
+ // insert or update entry
+ try {
+ if (row == null) {
+ // create and insert new entry
+ Data data = new Data();
+ data.put(YMarkStatics.TABLE_BOOKMARKS_COL_URL, url.getBytes());
+ data.put(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE,"").getBytes());
+ data.put(YMarkStatics.TABLE_BOOKMARKS_COL_DESC, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_DESC,"").getBytes());
+ data.put(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC,"false").getBytes());
+ data.put(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS,"").getBytes());
+
+ byte[] date = DateFormatter.formatShortMilliSecond(new Date()).getBytes();
+ data.put(YMarkStatics.TABLE_BOOKMARKS_COL_DATE_ADDED, date);
+ data.put(YMarkStatics.TABLE_BOOKMARKS_COL_DATE_MODIFIED, date);
+ data.put(YMarkStatics.TABLE_BOOKMARKS_COL_DATE_VISITED, date);
+
+ sb.tables.insert(table, pk, data);
+ } else {
+ // modify and update existing entry
+ row.put(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE,row.get(YMarkStatics.TABLE_BOOKMARKS_COL_TITLE,"")).getBytes());
+ row.put(YMarkStatics.TABLE_BOOKMARKS_COL_DESC, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_DESC,row.get(YMarkStatics.TABLE_BOOKMARKS_COL_DESC,"")).getBytes());
+ row.put(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC,row.get(YMarkStatics.TABLE_BOOKMARKS_COL_PUBLIC,"false")).getBytes());
+ row.put(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS, post.get(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS,row.get(YMarkStatics.TABLE_BOOKMARKS_COL_TAGS,"")).getBytes());
+
+ // modify date attribute
+ row.put(YMarkStatics.TABLE_BOOKMARKS_COL_DATE_MODIFIED, DateFormatter.formatShortMilliSecond(new Date()).getBytes());
+
+ sb.tables.update(table, row);
+ assert pk != null;
+ }
+ } catch (IOException e) {
+ Log.logException(e);
+ }
+ Log.logInfo(YMarkStatics.TABLE_BOOKMARKS_LOG, "insertBookmark: "+url);
+ prop.put("result", "1");
+ } else {
+ prop.put("AUTHENTICATE","Authentication required!");
+ }
+ // return rewrite properties
+ return prop;
+ }
+}
diff --git a/htroot/api/ymarks/add_ymark.xml b/htroot/api/ymarks/add_ymark.xml
new file mode 100644
index 000000000..d6880fb21
--- /dev/null
+++ b/htroot/api/ymarks/add_ymark.xml
@@ -0,0 +1,2 @@
+<?xml version='1.0' encoding="UTF-8" standalone='yes'?>
+<result code="#(result)#something went wrong::done#(/result)#" />
\ No newline at end of file
diff --git a/source/de/anomic/data/YMarkStatics.java b/source/de/anomic/data/YMarkStatics.java
new file mode 100644
index 000000000..8d83488c6
--- /dev/null
+++ b/source/de/anomic/data/YMarkStatics.java
@@ -0,0 +1,20 @@
+package de.anomic.data;
+
+public class YMarkStatics {
+
+ public final static String TABLE_BOOKMARKS_BASENAME = "bookmarks";
+ public final static String TABLE_BOOKMARKS_LOG = "BOOKMARKS";
+
+
+ public final static String TABLE_BOOKMARKS_COL_URL = "url";
+ public final static String TABLE_BOOKMARKS_COL_TITLE = "title";
+ public final static String TABLE_BOOKMARKS_COL_DESC = "desc";
+
+ public final static String TABLE_BOOKMARKS_COL_DATE_ADDED = "added";
+ public final static String TABLE_BOOKMARKS_COL_DATE_MODIFIED = "modified";
+ public final static String TABLE_BOOKMARKS_COL_DATE_VISITED = "visited";
+
+ public final static String TABLE_BOOKMARKS_COL_PUBLIC = "public";
+ public final static String TABLE_BOOKMARKS_COL_TAGS = "tags";
+
+}