- added attributes to /xml/bookmarks/xbel/xbel.xml

- tag=tagName returns only bookmarks which match tagName in a single XBEL-folder tagName
- added metadata for public=true/false to XBEL output
- added the attribute 'added' (date) to XBEL output

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4791 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
apfelmaennchen 17 years ago
parent 6c79edcd56
commit 5c6ff5ebea

@ -1,10 +1,12 @@
package xml.bookmarks.xbel; package xml.bookmarks.xbel;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import de.anomic.data.bookmarksDB; import de.anomic.data.bookmarksDB;
import de.anomic.http.httpHeader; import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaSwitchboard; import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverDate;
import de.anomic.server.serverObjects; import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch; import de.anomic.server.serverSwitch;
@ -27,22 +29,29 @@ public class xbel {
if(post.containsKey("login")) { if(post.containsKey("login")) {
prop.put("AUTHENTICATE","admin log-in"); prop.put("AUTHENTICATE","admin log-in");
} }
} }
} if(post.containsKey("tag")) {
String tagName=(String) post.get("tag");
if(isAdmin) { prop.put("folder", tagName);
count = recurseFolders(switchboard.bookmarksDB.getFolderList(isAdmin),"/",0,true,""); if (!tagName.equals("")) {
prop.put("xbel", count); Iterator<String> bit=switchboard.bookmarksDB.getBookmarksIterator(tagName, isAdmin);
count = print_XBEL(bit, count);
} prop.put("xbel", count);
return prop;
}
}
}
// print bookmark folders as XBEL default
prop.put("folder", "YaCy Bookmark Folder");
count = recurseFolders(switchboard.bookmarksDB.getFolderList(isAdmin),"/",0,true,"");
prop.put("xbel", count);
return prop; // return from serverObjects respond() return prop; // return from serverObjects respond()
} }
private static int recurseFolders(Iterator<String> it, String root, int count, boolean next, String prev){ private static int recurseFolders(Iterator<String> it, String root, int count, boolean next, String prev){
String fn=""; String fn="";
bookmarksDB.Bookmark bookmark;
if(next) fn = it.next().toString(); if(next) fn = it.next().toString();
else fn = prev; else fn = prev;
@ -62,19 +71,7 @@ public class xbel {
prop.put("xbel_"+count+"_elements", "<title>"+fn.replaceFirst(root+"/*","")+"</title>"); prop.put("xbel_"+count+"_elements", "<title>"+fn.replaceFirst(root+"/*","")+"</title>");
count++; count++;
Iterator<String> bit=switchboard.bookmarksDB.getBookmarksIterator(fn, isAdmin); Iterator<String> bit=switchboard.bookmarksDB.getBookmarksIterator(fn, isAdmin);
while(bit.hasNext()){ count = print_XBEL(bit, count);
bookmark=switchboard.bookmarksDB.getBookmark(bit.next());
prop.put("xbel_"+count+"_elements", "<bookmark id=\""+bookmark.getUrlHash()+"\" href=\""+bookmark.getUrl()+"\">");
count++;
prop.put("xbel_"+count+"_elements", "<title>"+bookmark.getTitle()+"</title>");
count++;
prop.put("xbel_"+count+"_elements", "<info><metadata owner=\"Mozilla\" ShortcutURL=\""+bookmark.getTagsString().replaceAll("/.*,", "")+"\"/></info>");
count++;
prop.put("xbel_"+count+"_elements", "<desc>"+bookmark.getDescription()+"</desc>");
count++;
prop.put("xbel_"+count+"_elements", "</bookmark>");
count++;
}
if(it.hasNext()){ if(it.hasNext()){
count = recurseFolders(it, fn, count, true, fn); count = recurseFolders(it, fn, count, true, fn);
} }
@ -87,4 +84,40 @@ public class xbel {
} }
return count; return count;
} }
private static int print_XBEL(Iterator<String> bit, int count) {
bookmarksDB.Bookmark bookmark;
Date date;
while(bit.hasNext()){
bookmark=switchboard.bookmarksDB.getBookmark(bit.next());
date=new Date(bookmark.getTimeStamp());
prop.put("xbel_"+count+"_elements", "<bookmark id=\""+bookmark.getUrlHash()+"\" href=\""+bookmark.getUrl()+"\" added=\""+serverDate.formatISO8601(date)+"\">");
count++;
prop.put("xbel_"+count+"_elements", "<title>");
count++;
prop.putHTML("xbel_"+count+"_elements", bookmark.getTitle(),true);
count++;
prop.put("xbel_"+count+"_elements", "</title>");
count++;
prop.put("xbel_"+count+"_elements", "<info>");
count++;
prop.put("xbel_"+count+"_elements", "<metadata owner=\"Mozilla\" ShortcutURL=\""+bookmark.getTagsString().replaceAll("/.*,", "").toLowerCase()+"\"/>");
count++;
prop.put("xbel_"+count+"_elements", "<metadata owner=\"YaCy\" public=\""+Boolean.toString(bookmark.getPublic())+"\"/>");
count++;
prop.put("xbel_"+count+"_elements", "</info>");
count++;
prop.put("xbel_"+count+"_elements", "<desc>");
count++;
prop.putHTML("xbel_"+count+"_elements", bookmark.getDescription(),true);
count++;
prop.put("xbel_"+count+"_elements", "</desc>");
count++;
prop.put("xbel_"+count+"_elements", "</bookmark>");
count++;
}
return count;
}
} }

@ -2,7 +2,7 @@
<!DOCTYPE xbel PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML" "http://pyxml.sourceforge.net/topics/dtds/xbel-1.0.dtd"> <!DOCTYPE xbel PUBLIC "+//IDN python.org//DTD XML Bookmark Exchange Language 1.0//EN//XML" "http://pyxml.sourceforge.net/topics/dtds/xbel-1.0.dtd">
<xbel> <xbel>
<folder> <folder>
<title>YaCy Bookmark Folder</title> <title>#[folder]#</title>
#{xbel}# #{xbel}#
#[elements]# #[elements]#
#{/xbel}# #{/xbel}#

Loading…
Cancel
Save