Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

timestamps sorted by timestamps

allo0619051c4b74
diff --git a/htroot/Bookmarks_p.html b/htroot/Bookmarks_p.html
index 51972729f..cbbbc4443 100644
--- a/htroot/Bookmarks_p.html
+++ b/htroot/Bookmarks_p.html
@@ -37,7 +37,7 @@ Tagged with #[tags]#. <br />
#(/next-page)#
&nbsp;
</td>
-<td>
+<td valign="top">
<a href="Bookmarks_p.html">All</a><br />
#{tags}#
<a href="Bookmarks_p.html?tag=#[name]#">#[name]#</a><br />
diff --git a/htroot/Bookmarks_p.java b/htroot/Bookmarks_p.java
index 94fc14d4f..9a3f5486f 100644
--- a/htroot/Bookmarks_p.java
+++ b/htroot/Bookmarks_p.java
@@ -82,6 +82,7 @@ public class Bookmarks_p {
if(bookmark != null){
bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_TITLE, title);
bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_PUBLIC, (String) post.get("public"));
+ bookmark.setProperty(bookmarksDB.Bookmark.BOOKMARK_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
bookmark.setTags(tags);
bookmark.setBookmarksTable();
}else{
@@ -107,18 +108,10 @@ public class Bookmarks_p {
}
prop.put("tags", count);
count=0;
- boolean viewTag=false;
if(!tag.equals("")){
- tagUrlHashes=switchboard.bookmarksDB.getTag(tag).getUrlHashes();
- if(tagUrlHashes != null){
- it=tagUrlHashes.iterator();
- viewTag=true;
- }else{ //tag does not exist
- //TODO: Errorpage?
- it=switchboard.bookmarksDB.bookmarkIterator(true);
- }
+ it=switchboard.bookmarksDB.getBookmarksIterator(tag);
}else{
- it=switchboard.bookmarksDB.bookmarkIterator(true);
+ it=switchboard.bookmarksDB.getBookmarksIterator();
}
bookmarksDB.Bookmark bookmark;
//skip the first entries (display next page)
@@ -129,11 +122,7 @@ public class Bookmarks_p {
}
count=0;
while(count<MAX_COUNT && it.hasNext()){
- if(viewTag){
- bookmark=switchboard.bookmarksDB.getBookmark((String)it.next());
- }else{
- bookmark=(Bookmark) it.next();
- }
+ bookmark=switchboard.bookmarksDB.getBookmark((String)it.next());
if(bookmark!=null){
prop.put("bookmarks_"+count+"_link", bookmark.getUrl());
prop.put("bookmarks_"+count+"_title", bookmark.getTitle());
diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.java
index 35a32a65f..a3d95c9b1 100644
--- a/source/de/anomic/data/bookmarksDB.java
+++ b/source/de/anomic/data/bookmarksDB.java
@@ -44,10 +44,13 @@ package de.anomic.data;
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
+import java.util.TreeMap;
+import java.util.TreeSet;
import java.util.Vector;
import de.anomic.kelondro.kelondroDyn;
@@ -161,6 +164,22 @@ public class bookmarksDB {
return null;
}
}
+ public Iterator getBookmarksIterator(){
+ TreeSet set=new TreeSet(new bookmarkComparator());
+ Iterator it=bookmarkIterator(true);
+ Bookmark bm;
+ while(it.hasNext()){
+ bm=(Bookmark)it.next();
+ set.add(bm.getUrlHash());
+ }
+ return set.iterator();
+ }
+ public Iterator getBookmarksIterator(String tag){
+ TreeSet set=new TreeSet(new bookmarkComparator());
+ Vector hashes=getTag(tag).getUrlHashes();
+ set.addAll(hashes);
+ return set.iterator();
+ }
public void removeBookmark(String urlHash){
Bookmark bookmark = getBookmark(urlHash);
if(bookmark == null) return; //does not exist
@@ -250,9 +269,16 @@ public class bookmarksDB {
}
public void setTagsTable(){
try {
- bookmarksDB.this.tagsTable.set(getTagName(), mem);
+ if(this.size() >0){
+ bookmarksDB.this.tagsTable.set(getTagName(), mem);
+ }else{
+ bookmarksDB.this.tagsTable.remove(getTagName());
+ }
} catch (IOException e) {}
}
+ public int size(){
+ return ((String)this.mem.get(URL_HASHES)).length();
+ }
}
/**
* Subclass, which stores the bookmark
@@ -263,6 +289,7 @@ public class bookmarksDB {
public static final String BOOKMARK_TITLE="bookmarkTitle";
public static final String BOOKMARK_TAGS="bookmarkTags";
public static final String BOOKMARK_PUBLIC="bookmarkPublic";
+ public static final String BOOKMARK_TIMESTAMP="bookmarkTimestamp";
private String urlHash;
private Map mem;
public Bookmark(String urlHash, Map map){
@@ -337,6 +364,13 @@ public class bookmarksDB {
bookmarksDB.this.bookmarksTable.set(getUrlHash(), mem);
} catch (IOException e) {}
}
+ public long getTimeStamp(){
+ if(mem.containsKey(BOOKMARK_TIMESTAMP)){
+ return Long.parseLong((String)mem.get(BOOKMARK_TIMESTAMP));
+ }else{
+ return 0;
+ }
+ }
}
public class tagIterator implements Iterator{
kelondroDyn.dynKeyIterator tagIter;
@@ -406,4 +440,15 @@ public class bookmarksDB {
}
}
}
+ /**
+ * Comparator to sort the Bookmarks with Timestamps
+ */
+ public class bookmarkComparator implements Comparator{
+ public int compare(Object obj1, Object obj2){
+ Bookmark bm1=getBookmark((String)obj1);
+ Bookmark bm2=getBookmark((String)obj2);
+ //TODO: what happens, if there is a big difference? (to much for int)
+ return (new Long(bm1.getTimeStamp() - bm2.getTimeStamp())).intValue();
+ }
+ }
}