- import HTML (e.g. FF export) via /api/ymarks/import.html - view your import via /api/ymarks/test.html - get a xml list via /api/ymarks/get_ymark_list.xml?tags=&folders= - delete bookmark tables via standard interface /Tables_p.html it is still very experimental!! git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7299 6c8d7289-2bf4-0310-a012-ef5d649a1542pull/1/head
parent
93c535d111
commit
43586a2ace
@ -0,0 +1,91 @@
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import net.yacy.cora.protocol.RequestHeader;
|
||||
import net.yacy.kelondro.blob.Tables;
|
||||
import net.yacy.kelondro.index.RowSpaceExceededException;
|
||||
import net.yacy.kelondro.logging.Log;
|
||||
import de.anomic.data.YMarkTables;
|
||||
import de.anomic.data.userDB;
|
||||
import de.anomic.search.Switchboard;
|
||||
import de.anomic.server.serverObjects;
|
||||
import de.anomic.server.serverSwitch;
|
||||
|
||||
|
||||
public class get_ymark_list {
|
||||
|
||||
private static Switchboard sb = null;
|
||||
private static serverObjects prop = null;
|
||||
|
||||
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||||
sb = (Switchboard) env;
|
||||
prop = new serverObjects();
|
||||
|
||||
boolean tags = false;
|
||||
|
||||
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);
|
||||
final TreeSet<String> bookmarks = new TreeSet<String>();
|
||||
|
||||
if(isAdmin || isAuthUser) {
|
||||
final String bmk_user = (isAuthUser ? user.getUserName() : YMarkTables.USER_ADMIN);
|
||||
|
||||
if(post.containsKey(YMarkTables.BOOKMARK.TAGS.key())) {
|
||||
tags = true;
|
||||
final String[] tagArray = YMarkTables.cleanTagsString(post.get(YMarkTables.BOOKMARK.TAGS.key())).split(YMarkTables.TAGS_SEPARATOR);
|
||||
try {
|
||||
bookmarks.addAll(sb.tables.bookmarks.tags.getBookmarks(bmk_user, tagArray));
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
} catch (RowSpaceExceededException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
if(post.containsKey(YMarkTables.BOOKMARK.FOLDERS.key())) {
|
||||
final String[] folderArray = YMarkTables.cleanFoldersString(post.get(YMarkTables.BOOKMARK.FOLDERS.key())).split(YMarkTables.TAGS_SEPARATOR);
|
||||
try {
|
||||
if(tags)
|
||||
bookmarks.retainAll(sb.tables.bookmarks.folders.getBookmarks(bmk_user, folderArray));
|
||||
else
|
||||
bookmarks.addAll(sb.tables.bookmarks.folders.getBookmarks(bmk_user, folderArray));
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
} catch (RowSpaceExceededException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
putBookmarks(bookmarks, YMarkTables.TABLES.BOOKMARKS.tablename(bmk_user));
|
||||
|
||||
} else {
|
||||
prop.put(YMarkTables.USER_AUTHENTICATE,YMarkTables.USER_AUTHENTICATE_MSG);
|
||||
}
|
||||
// return rewrite properties
|
||||
return prop;
|
||||
}
|
||||
|
||||
private static void putBookmarks(final TreeSet<String> urlSet, final String bmk_table) {
|
||||
final Iterator<String>urlIter = urlSet.iterator();
|
||||
int count = 0;
|
||||
while(urlIter.hasNext()) {
|
||||
final byte[] urlHash = urlIter.next().getBytes();
|
||||
Tables.Row bmk_row = null;
|
||||
try {
|
||||
bmk_row = sb.tables.select(bmk_table, urlHash);
|
||||
if (bmk_row != null) {
|
||||
prop.putXML("bookmarks_"+count+"_id", new String(urlHash));
|
||||
for (YMarkTables.BOOKMARK bmk : YMarkTables.BOOKMARK.values()) {
|
||||
prop.putXML("bookmarks_"+count+"_"+bmk.key(), new String(bmk_row.get(bmk.key(),bmk.deflt())));
|
||||
}
|
||||
count++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
} catch (RowSpaceExceededException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
prop.put("bookmarks", count);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<posts>
|
||||
#{bookmarks}#
|
||||
<post href="#[url]#" id="#[id]#" title="#[title]#" tag="#[tags]#" folders="#[folders]#" added="#[date_added]#"/>
|
||||
#{/bookmarks}#
|
||||
</posts>
|
@ -0,0 +1,176 @@
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.yacy.cora.protocol.RequestHeader;
|
||||
import net.yacy.kelondro.blob.Tables;
|
||||
import net.yacy.kelondro.index.RowSpaceExceededException;
|
||||
import net.yacy.kelondro.logging.Log;
|
||||
import net.yacy.kelondro.util.DateFormatter;
|
||||
import de.anomic.data.YMarkTables;
|
||||
import de.anomic.data.userDB;
|
||||
import de.anomic.search.Switchboard;
|
||||
import de.anomic.server.serverObjects;
|
||||
import de.anomic.server.serverSwitch;
|
||||
|
||||
public class get_ymark_tree {
|
||||
|
||||
public static final String ROOT = "root";
|
||||
public static final String SOURCE = "source";
|
||||
|
||||
// for some reason enums don't work in servlet classes ?!?!
|
||||
/*
|
||||
private static final Map<String, String> TYPE = createMap();
|
||||
private static Map<String, String> createMap() {
|
||||
Map<String, String> result = new HashMap<String, String>();
|
||||
result.put("tags", "tag");
|
||||
result.put("url", "link");
|
||||
result.put("public", "lock");
|
||||
result.put("visits", "stat");
|
||||
return Collections.unmodifiableMap(result);
|
||||
}
|
||||
*/
|
||||
|
||||
static serverObjects prop;
|
||||
|
||||
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
|
||||
final Switchboard sb = (Switchboard) env;
|
||||
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 bmk_user = (isAuthUser ? user.getUserName() : YMarkTables.USER_ADMIN);
|
||||
|
||||
|
||||
String root = YMarkTables.FOLDERS_ROOT;
|
||||
String[] foldername = null;
|
||||
boolean isFolder = true;
|
||||
|
||||
if (post != null){
|
||||
if (post.containsKey(ROOT)) {
|
||||
if (post.get(ROOT).equals(SOURCE) || post.get(ROOT).equals(YMarkTables.FOLDERS_ROOT)) {
|
||||
root = "";
|
||||
} else if (post.get(ROOT).startsWith(YMarkTables.FOLDERS_ROOT)) {
|
||||
root = post.get(ROOT);
|
||||
} else {
|
||||
// root = YMarkTables.FOLDERS_ROOT + post.get(ROOT);
|
||||
isFolder = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<String> it = null;
|
||||
Tables.Row bmk_row = null;
|
||||
int count = 0;
|
||||
|
||||
if(isFolder) {
|
||||
// loop through folderList
|
||||
try {
|
||||
it = sb.tables.bookmarks.folders.getFolders(bmk_user, root);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
int n = root.split(YMarkTables.FOLDERS_SEPARATOR).length;
|
||||
if (n == 0) n = 1;
|
||||
|
||||
while (it.hasNext()) {
|
||||
String folder = it.next();
|
||||
foldername = folder.split(YMarkTables.FOLDERS_SEPARATOR);
|
||||
if (foldername.length == n+1) {
|
||||
prop.put("folders_"+count+"_foldername", foldername[n]);
|
||||
prop.put("folders_"+count+"_expanded", "false");
|
||||
prop.put("folders_"+count+"_type", "folder");
|
||||
prop.put("folders_"+count+"_hash", folder); //TODO: switch from pathString to folderHash
|
||||
prop.put("folders_"+count+"_url", ""); //TODO: insert folder url
|
||||
prop.put("folders_"+count+"_hasChildren", "true"); //TODO: determine if folder has children
|
||||
prop.put("folders_"+count+"_comma", ",");
|
||||
count++;
|
||||
}
|
||||
}
|
||||
// loop through bookmarkList
|
||||
try {
|
||||
it = sb.tables.bookmarks.folders.getBookmarks(bmk_user, root).iterator();
|
||||
while (it.hasNext()) {
|
||||
final String urlHash = new String(it.next());
|
||||
bmk_row = sb.tables.select(YMarkTables.TABLES.BOOKMARKS.tablename(bmk_user), urlHash.getBytes());
|
||||
if(bmk_row != null) {
|
||||
final String url = new String(bmk_row.get(YMarkTables.BOOKMARK.URL.key()));
|
||||
final String title = new String(bmk_row.get(YMarkTables.BOOKMARK.TITLE.key(), YMarkTables.BOOKMARK.TITLE.deflt()));
|
||||
|
||||
// TODO: get rid of bmtype
|
||||
if (post.containsKey("bmtype")) {
|
||||
if (post.get("bmtype").equals("title")) {
|
||||
prop.put("folders_"+count+"_foldername", title);
|
||||
} else if (post.get("bmtype").equals("href")) {
|
||||
prop.put("folders_"+count+"_foldername",
|
||||
"<a href='"+url+" 'target='_blank'>"+title+"</a>");
|
||||
}
|
||||
} else {
|
||||
prop.put("folders_"+count+"_foldername", url);
|
||||
}
|
||||
prop.put("folders_"+count+"_expanded", "false");
|
||||
prop.put("folders_"+count+"_url", url);
|
||||
prop.put("folders_"+count+"_type", "file");
|
||||
prop.put("folders_"+count+"_hash", urlHash);
|
||||
prop.put("folders_"+count+"_hasChildren", "true");
|
||||
prop.put("folders_"+count+"_comma", ",");
|
||||
count++;
|
||||
}
|
||||
}
|
||||
count--;
|
||||
prop.put("folders_"+count+"_comma", "");
|
||||
count++;
|
||||
prop.put("folders", count);
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
} catch (RowSpaceExceededException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
bmk_row = sb.tables.select(YMarkTables.TABLES.BOOKMARKS.tablename(bmk_user), post.get(ROOT).getBytes());
|
||||
if(bmk_row != null) {
|
||||
it = bmk_row.keySet().iterator();
|
||||
while(it.hasNext()) {
|
||||
final String key = it.next();
|
||||
if(key.startsWith("date")) {
|
||||
final String date = DateFormatter.formatISO8601(new Date(Long.parseLong(new String(bmk_row.get(key)))));
|
||||
prop.put("folders_"+count+"_foldername","<small><b>"+key+":</b> " + date + "</small>");
|
||||
putProp(count, "date");
|
||||
count++;
|
||||
} else {
|
||||
final String value = new String(bmk_row.get(key));
|
||||
prop.put("folders_"+count+"_foldername","<small><b>"+key+":</b> " + value + "</small>");
|
||||
if(YMarkTables.BOOKMARK.contains(key))
|
||||
putProp(count, YMarkTables.BOOKMARK.get(key).type());
|
||||
else
|
||||
putProp(count, "meta");
|
||||
count++;
|
||||
}
|
||||
}
|
||||
count--;
|
||||
prop.put("folders_"+count+"_comma", "");
|
||||
count++;
|
||||
prop.put("folders", count);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.logException(e);
|
||||
} catch (RowSpaceExceededException e) {
|
||||
Log.logException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
// return rewrite properties
|
||||
return prop;
|
||||
}
|
||||
public static void putProp(final int count, final String type) {
|
||||
prop.put("folders_"+count+"_expanded", "false");
|
||||
prop.put("folders_"+count+"_url", "");
|
||||
prop.put("folders_"+count+"_type", type);
|
||||
prop.put("folders_"+count+"_hash", "");
|
||||
prop.put("folders_"+count+"_hasChildren", "false");
|
||||
prop.put("folders_"+count+"_comma", ",");
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
[
|
||||
#{folders}#{
|
||||
"text": "#[foldername]#",
|
||||
"expanded": #[expanded]#,
|
||||
"classes": "#[type]#",
|
||||
"id": "#[hash]#",
|
||||
"hasChildren": #[hasChildren]#
|
||||
}#[comma]##{/folders}#
|
||||
]
|
@ -0,0 +1,11 @@
|
||||
<?xml version='1.0' encoding="UTF-8" standalone='yes'?>
|
||||
<folders>
|
||||
#{folders}#<folder
|
||||
id="#[hash]#"
|
||||
type="#[type]#"
|
||||
name="#[foldername]#"
|
||||
url="#[url]#"
|
||||
hasChildren="#[hasChildren]#"
|
||||
/>
|
||||
#{/folders}#
|
||||
</folders>
|
@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<link media="screen" type="text/css" href="/yacy/ui/css/jquery.treeview.css" rel="stylesheet" />
|
||||
<title>YaCy Bookmarks</title>
|
||||
<script src="/yacy/ui/js/jquery-1.3.1.min.js" type="text/javascript"></script>
|
||||
<script src="/yacy/ui/js/jquery.treeview.min.js" type="text/javascript"></script>
|
||||
<script src="/yacy/ui/js/jquery.treeview.async.js" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
$(document).ready(function() {
|
||||
$("#yfolder").treeview({
|
||||
url: "/api/ymarks/get_ymark_tree.json?bmtype=href",
|
||||
unique: false,
|
||||
toggle: function() {
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
$("button").click(function () {
|
||||
alert("test");
|
||||
});
|
||||
//]]>
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<h3>YaCy Bookmarks</h3>
|
||||
<div>
|
||||
<ul id="yfolder" class="filetree"></ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in new issue