package xml.bookmarks.xbel; import java.util.Iterator; import de.anomic.data.bookmarksDB; import de.anomic.http.httpHeader; import de.anomic.plasma.plasmaSwitchboard; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; public class xbel { private static serverObjects prop; private static plasmaSwitchboard switchboard; private static boolean isAdmin; public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) { int count = 0;; prop = new serverObjects(); switchboard = (plasmaSwitchboard) env; isAdmin=switchboard.verifyAuthentication(header, true); if(isAdmin) { count = recurseFolders(switchboard.bookmarksDB.getFolderList(isAdmin),"/",0,true,""); prop.put("xbel", count); } return prop; // return from serverObjects respond() } private static int recurseFolders(Iterator it, String root, int count, boolean next, String prev){ String fn=""; bookmarksDB.Bookmark bookmark; if(next) fn = it.next().toString(); else fn = prev; if(fn.equals("\uffff")) { int i = prev.replaceAll("[^/]","").length(); while(i>0){ prop.put("xbel_"+count+"_elements", ""); count++; i--; } return count; } if(fn.startsWith(root)){ prop.put("xbel_"+count+"_elements", ""); count++; prop.put("xbel_"+count+"_elements", ""+fn.replaceFirst(root+"/*","")+""); count++; Iterator bit=switchboard.bookmarksDB.getBookmarksIterator(fn, isAdmin); while(bit.hasNext()){ bookmark=switchboard.bookmarksDB.getBookmark(bit.next()); prop.put("xbel_"+count+"_elements", ""); count++; prop.put("xbel_"+count+"_elements", ""+bookmark.getTitle()+""); count++; prop.put("xbel_"+count+"_elements", ""); count++; prop.put("xbel_"+count+"_elements", ""+bookmark.getDescription()+""); count++; prop.put("xbel_"+count+"_elements", ""); count++; } if(it.hasNext()){ count = recurseFolders(it, fn, count, true, fn); } } else { prop.put("xbel_"+count+"_elements", ""); count++; root = root.replaceAll("(/.[^/]*$)", ""); if(root.equals("")) root = "/"; count = recurseFolders(it, root, count, false, fn); } return count; } }