diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.java index f69865abe..d450134e2 100644 --- a/source/de/anomic/data/bookmarksDB.java +++ b/source/de/anomic/data/bookmarksDB.java @@ -159,7 +159,57 @@ public class bookmarksDB { public static String tagHash(String tagName, String user){ return plasmaCondenser.word2hash(user+":"+tagName.toLowerCase()); } - + + public Iterator getFolderList(boolean priv){ + + Set folders = new TreeSet(); + String path = ""; + Iterator it = this.getTagIterator(priv); + Tag tag; + + while(it.hasNext()){ + tag=(Tag) it.next(); + if (tag.getFriendlyName().startsWith("/")) { + path = tag.getFriendlyName(); + path = cleanTagsString(path); + while(path.length() > 0){ + folders.add(path); + path = path.replaceAll("(/.[^/]*$)", ""); // create missing folders in path + } + } + } + folders.add("\uffff"); + return (Iterator) folders.iterator(); + } + + public static String cleanTagsString(String tagsString){ + + // get rid of heading, trailing and double commas since they are useless + while (tagsString.startsWith(",")) { + tagsString = tagsString.substring(1); + } + while (tagsString.endsWith(",")) { + tagsString = tagsString.substring(0,tagsString.length() -1); + } + while(tagsString.contains(",,")){ + tagsString = tagsString.replaceAll(",,", ","); + } + // get rid of double and trailing slashes + while(tagsString.endsWith("/")){ + tagsString = tagsString.substring(0, tagsString.length() -1); + } + while(tagsString.contains("/,")){ + tagsString = tagsString.replaceAll("/,", ","); + } + while(tagsString.contains("//")){ + tagsString = tagsString.replaceAll("//", "/"); + } + // space characters following a comma are removed + tagsString = tagsString.replaceAll(",\\s+", ","); + + return tagsString; + } + // ----------------------------------------------------------- // bookmarksDB's functions for bookmarksTable / bookmarkCache // ----------------------------------------------------------- @@ -303,7 +353,7 @@ public class bookmarksDB { return (Tag) tagCache.get(hash); } return loadTag(hash); //null if it does not exists - } + } /** * store a Tag in tagsTable or remove an empty tag * @param tag an object of type Tag to be stored/removed @@ -900,9 +950,26 @@ public class bookmarksDB { public Set getTags(){ return tags; } - public String getTagsString(){ - return listManager.collection2string(getTags()); - } + public String getTagsString(){ + String s[] = listManager.collection2string(getTags()).split(","); + String tagsString=""; + for (int i=0; i