001: package xml.bookmarks.xbel;
002:
003: import java.util.Iterator;
004:
005: import de.anomic.data.bookmarksDB;
006: import de.anomic.http.httpHeader;
007: import de.anomic.plasma.plasmaSwitchboard;
008: import de.anomic.server.serverObjects;
009: import de.anomic.server.serverSwitch;
010:
011: public class xbel {
012:
013: private static serverObjects prop;
014: private static plasmaSwitchboard switchboard;
015: private static boolean isAdmin;
016:
017: public static serverObjects respond(httpHeader header,
018: serverObjects post, serverSwitch env) {
019:
020: int count = 0;
021: ;
022:
023: prop = new serverObjects();
024: switchboard = (plasmaSwitchboard) env;
025: isAdmin = switchboard.verifyAuthentication(header, true);
026:
027: if (isAdmin) {
028: count = recurseFolders(switchboard.bookmarksDB
029: .getFolderList(isAdmin), "/", 0, true, "");
030: prop.put("xbel", count);
031:
032: }
033: return prop; // return from serverObjects respond()
034:
035: }
036:
037: private static int recurseFolders(Iterator<String> it, String root,
038: int count, boolean next, String prev) {
039: String fn = "";
040: bookmarksDB.Bookmark bookmark;
041:
042: if (next)
043: fn = it.next().toString();
044: else
045: fn = prev;
046:
047: if (fn.equals("\uffff")) {
048: int i = prev.replaceAll("[^/]", "").length();
049: while (i > 0) {
050: prop.put("xbel_" + count + "_elements", "</folder>");
051: count++;
052: i--;
053: }
054: return count;
055: }
056:
057: if (fn.startsWith(root)) {
058: prop.put("xbel_" + count + "_elements", "<folder id=\""
059: + bookmarksDB.tagHash(fn) + "\">");
060: count++;
061: prop.put("xbel_" + count + "_elements", "<title>"
062: + fn.replaceFirst(root + "/*", "") + "</title>");
063: count++;
064: Iterator<String> bit = switchboard.bookmarksDB
065: .getBookmarksIterator(fn, isAdmin);
066: while (bit.hasNext()) {
067: bookmark = switchboard.bookmarksDB.getBookmark(bit
068: .next());
069: prop.put("xbel_" + count + "_elements",
070: "<bookmark id=\"" + bookmark.getUrlHash()
071: + "\" href=\"" + bookmark.getUrl()
072: + "\">");
073: count++;
074: prop.put("xbel_" + count + "_elements", "<title>"
075: + bookmark.getTitle() + "</title>");
076: count++;
077: prop.put("xbel_" + count + "_elements",
078: "<info><metadata owner=\"Mozilla\" ShortcutURL=\""
079: + bookmark.getTagsString().replaceAll(
080: "/.*,", "") + "\"/></info>");
081: count++;
082: prop.put("xbel_" + count + "_elements", "<desc>"
083: + bookmark.getDescription() + "</desc>");
084: count++;
085: prop.put("xbel_" + count + "_elements", "</bookmark>");
086: count++;
087: }
088: if (it.hasNext()) {
089: count = recurseFolders(it, fn, count, true, fn);
090: }
091: } else {
092: prop.put("xbel_" + count + "_elements", "</folder>");
093: count++;
094: root = root.replaceAll("(/.[^/]*$)", "");
095: if (root.equals(""))
096: root = "/";
097: count = recurseFolders(it, root, count, false, fn);
098: }
099: return count;
100: }
101: }
|