first version of posts/get from the del.icio.us api

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2713 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 18 years ago
parent 1969522dc1
commit 1d0c0edda3

@ -0,0 +1,70 @@
// /xml/bookmarks/posts/all.java
// -------------------------------
// (C) 2006 Alexander Schier
// part of yacy
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
package xml.bookmarks.posts;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import de.anomic.data.bookmarksDB;
import de.anomic.http.httpHeader;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.server.serverCodings;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
public class get {
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
// return variable that accumulates replacements
plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
boolean isAdmin=switchboard.verifyAuthentication(header, true);
serverObjects prop = new serverObjects();
String tag=null;
String date;
//String url=""; //urlfilter not yet implemented
if(post != null && post.containsKey("tag")){
tag=(String) post.get("tag");
}
if(post != null && post.containsKey("date")){
date=(String)post.get("date");
}else{
date=bookmarksDB.dateToiso8601(new Date(System.currentTimeMillis()));
}
int count=0;
ArrayList bookmark_hashes=switchboard.bookmarksDB.getDate(Long.toString(bookmarksDB.iso8601ToDate(date).getTime())).getBookmarkList();
Iterator it=bookmark_hashes.iterator();
bookmarksDB.Bookmark bookmark=null;
while(it.hasNext()){
bookmark=switchboard.bookmarksDB.getBookmark((String) it.next());
if(bookmarksDB.dateToiso8601(new Date(bookmark.getTimeStamp())) == date &&
tag==null || bookmark.getTags().contains(tag) &&
isAdmin || bookmark.getPublic()){
prop.putNoHTML("posts_"+count+"_url", bookmark.getUrl());
prop.putNoHTML("posts_"+count+"_title", bookmark.getTitle());
prop.putNoHTML("posts_"+count+"_description", bookmark.getDescription());
prop.putNoHTML("posts_"+count+"_md5", serverCodings.encodeMD5Hex(bookmark.getUrl()));
prop.putNoHTML("posts_"+count+"_time", date);
prop.putNoHTML("posts_"+count+"_tags", bookmark.getTagsString().replaceAll(","," "));
count++;
}
}
prop.put("posts", count);
// return rewrite properties
return prop;
}
}

@ -0,0 +1,5 @@
<?xml version='1.0' standalone='yes'?>
<posts>
#{posts}#<post href="#[url]#" description="#[title]#" extended="#[description]#" hash="#[md5]#" tag="#[tags]#" time="#[time]#"/>
#{/posts}#
</posts>

@ -618,17 +618,22 @@ public class bookmarksDB {
public static final String URL_HASHES="urlHashes"; public static final String URL_HASHES="urlHashes";
private Map mem; private Map mem;
String date; String date;
public bookmarksDate(String mydate){ public bookmarksDate(String mydate){
date=mydate; //round to seconds, but store as milliseconds (java timestamp)
date=String.valueOf((Long.parseLong(mydate)/1000)*1000);
mem=new HashMap(); mem=new HashMap();
mem.put(URL_HASHES, ""); mem.put(URL_HASHES, "");
} }
public bookmarksDate(String mydate, Map map){ public bookmarksDate(String mydate, Map map){
date=mydate; //round to seconds, but store as milliseconds (java timestamp)
date=String.valueOf((Long.parseLong(mydate)/1000)*1000);
mem=map; mem=map;
} }
public bookmarksDate(String mydate, ArrayList entries){ public bookmarksDate(String mydate, ArrayList entries){
date=mydate; //round to seconds, but store as milliseconds (java timestamp)
date=String.valueOf((Long.parseLong(mydate)/1000)*1000);
mem=new HashMap(); mem=new HashMap();
mem.put(URL_HASHES, listManager.arraylist2string(entries)); mem.put(URL_HASHES, listManager.arraylist2string(entries));
} }
@ -671,6 +676,9 @@ public class bookmarksDB {
public String getDateString(){ public String getDateString(){
return date; return date;
} }
public ArrayList getBookmarkList(){
return listManager.string2arraylist((String)this.mem.get(URL_HASHES));
}
public int size(){ public int size(){
return listManager.string2arraylist(((String)this.mem.get(URL_HASHES))).size(); return listManager.string2arraylist(((String)this.mem.get(URL_HASHES))).size();
} }

Loading…
Cancel
Save