git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1248 6c8d7289-2bf4-0310-a012-ef5d649a1542pull/1/head
parent
d7b6dcbe2e
commit
4ac0fd328a
@ -0,0 +1,41 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>YaCy '#[clientname]#': Bookmarks</title>
|
||||
#%env/templates/metas.template%#
|
||||
</head>
|
||||
<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">
|
||||
#%env/templates/header.template%#
|
||||
<br><br>
|
||||
<h2>Bookmarks</h2>
|
||||
<!-- todo: div layout? -->
|
||||
<table border="1" width="100%" height="100%">
|
||||
<tr><td colspan="2">
|
||||
<h3>Add Bookmark</h3>
|
||||
<form action="Bookmarks_p.html" method="GET">
|
||||
Url: <input type="text" name="url"><br />
|
||||
Title: <input type="text" name="title"><br />
|
||||
Tags(comma separated): <input type="text" name="tags"><br />
|
||||
<input type="submit" name="add" value="create">
|
||||
</form>
|
||||
</td></tr>
|
||||
<tr height="100%">
|
||||
<td width="100%">
|
||||
#{bookmarks}#
|
||||
<a href="#[link]#">#[title]#</a><br />
|
||||
Tagged with #[tags]#
|
||||
<p />
|
||||
#{/bookmarks}#
|
||||
|
||||
</td>
|
||||
<td>
|
||||
#{tags}#
|
||||
<a href="Bookmarks_p.html?tag=#[name]#">#[name]#</a><br />
|
||||
#{/tags}#
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
#%env/templates/footer.template%#
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,102 @@
|
||||
// Bookmarks_p.java
|
||||
// -----------------------
|
||||
// part of YACY
|
||||
// (C) by Michael Peter Christen; mc@anomic.de
|
||||
// first published on http://www.anomic.de
|
||||
// Frankfurt, Germany, 2004
|
||||
//
|
||||
// This File is contributed by Alexander Schier
|
||||
// last change: 26.12.2005
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Using this software in any meaning (reading, learning, copying, compiling,
|
||||
// running) means that you agree that the Author(s) is (are) not responsible
|
||||
// for cost, loss of data or any harm that may be caused directly or indirectly
|
||||
// by usage of this softare or this documentation. The usage of this software
|
||||
// is on your own risk. The installation and usage (starting/running) of this
|
||||
// software may allow other people or application to access your computer and
|
||||
// any attached devices and is highly dependent on the configuration of the
|
||||
// software which must be done by the user of the software; the author(s) is
|
||||
// (are) also not responsible for proper configuration and usage of the
|
||||
// software, even if provoked by documentation provided together with
|
||||
// the software.
|
||||
//
|
||||
// Any changes to this file according to the GPL as documented in the file
|
||||
// gpl.txt aside this file in the shipment you received can be done to the
|
||||
// lines that follows this copyright notice here, but changes must not be
|
||||
// done inside the copyright notive above. A re-distribution must contain
|
||||
// the intact and unchanged copyright notice.
|
||||
// Contributions and changes to the program code must be marked as such.
|
||||
|
||||
// You must compile this file with
|
||||
// javac -classpath .:../Classes Blacklist_p.java
|
||||
// if the shell's current path is HTROOT
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import de.anomic.data.bookmarksDB;
|
||||
import de.anomic.data.bookmarksDB.Bookmark;
|
||||
import de.anomic.http.httpHeader;
|
||||
import de.anomic.plasma.plasmaSwitchboard;
|
||||
import de.anomic.server.serverObjects;
|
||||
import de.anomic.server.serverSwitch;
|
||||
|
||||
public class Bookmarks_p {
|
||||
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
|
||||
serverObjects prop = new serverObjects();
|
||||
plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
|
||||
|
||||
if(post != null){
|
||||
if(post.containsKey("add")){ //add an Entry
|
||||
String url=(String) post.get("url");
|
||||
String title=(String) post.get("title");
|
||||
Vector tags=new Vector();
|
||||
String[] tagsArray=((String)post.get("tags")).split(",");
|
||||
for(int i=0;i<tagsArray.length; i++){
|
||||
tags.add(tagsArray[i].trim());
|
||||
}
|
||||
|
||||
bookmarksDB.Bookmark bookmark = switchboard.bookmarksDB.createBookmark(url);
|
||||
bookmark.setProperty("title", title);
|
||||
bookmark.setTags(tags);
|
||||
bookmark.setBookmarksTable();
|
||||
}
|
||||
}
|
||||
Iterator it=switchboard.bookmarksDB.tagIterator(true);
|
||||
int count=0;
|
||||
while(it.hasNext()){
|
||||
prop.put("tags_"+count+"_name", ((bookmarksDB.Tag)it.next()).getTagName());
|
||||
count++;
|
||||
}
|
||||
prop.put("tags", count);
|
||||
count=0;
|
||||
it=switchboard.bookmarksDB.bookmarkIterator(true);
|
||||
bookmarksDB.Bookmark bookmark;
|
||||
while(it.hasNext() && count<10){
|
||||
bookmark=(Bookmark) it.next();
|
||||
if(bookmark!=null){
|
||||
prop.put("bookmarks_"+count+"_link", bookmark.getUrl());
|
||||
prop.put("bookmarks_"+count+"_title", bookmark.getTitle());
|
||||
prop.put("bookmarks_"+count+"_tags", bookmark.getTags());
|
||||
count++;
|
||||
}
|
||||
}
|
||||
prop.put("bookmarks", count);
|
||||
return prop;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,381 @@
|
||||
//bookmarksDB.java
|
||||
//-------------------------------------
|
||||
//part of YACY
|
||||
//(C) by Michael Peter Christen; mc@anomic.de
|
||||
//first published on http://www.anomic.de
|
||||
//Frankfurt, Germany, 2004
|
||||
//
|
||||
//This file ist contributed by Alexander Schier
|
||||
//
|
||||
//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.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with this program; if not, write to the Free Software
|
||||
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
//Using this software in any meaning (reading, learning, copying, compiling,
|
||||
//running) means that you agree that the Author(s) is (are) not responsible
|
||||
//for cost, loss of data or any harm that may be caused directly or indirectly
|
||||
//by usage of this softare or this documentation. The usage of this software
|
||||
//is on your own risk. The installation and usage (starting/running) of this
|
||||
//software may allow other people or application to access your computer and
|
||||
//any attached devices and is highly dependent on the configuration of the
|
||||
//software which must be done by the user of the software; the author(s) is
|
||||
//(are) also not responsible for proper configuration and usage of the
|
||||
//software, even if provoked by documentation provided together with
|
||||
//the software.
|
||||
//
|
||||
//Any changes to this file according to the GPL as documented in the file
|
||||
//gpl.txt aside this file in the shipment you received can be done to the
|
||||
//lines that follows this copyright notice here, but changes must not be
|
||||
//done inside the copyright notive above. A re-distribution must contain
|
||||
//the intact and unchanged copyright notice.
|
||||
//Contributions and changes to the program code must be marked as such.
|
||||
package de.anomic.data;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import de.anomic.kelondro.kelondroDyn;
|
||||
import de.anomic.kelondro.kelondroException;
|
||||
import de.anomic.kelondro.kelondroMap;
|
||||
import de.anomic.plasma.plasmaURL;
|
||||
|
||||
public class bookmarksDB {
|
||||
kelondroMap tagsTable;
|
||||
kelondroMap bookmarksTable;
|
||||
private final File bookmarksFile;
|
||||
private final File tagsFile;
|
||||
private final int bufferkb;
|
||||
public bookmarksDB(File bookmarksFile, File tagsFile, int bufferkb){
|
||||
this.bookmarksFile=bookmarksFile;
|
||||
this.tagsFile=tagsFile;
|
||||
this.bufferkb=bufferkb;
|
||||
if(bookmarksFile.exists() && tagsFile.exists()){
|
||||
try {
|
||||
this.bookmarksTable=new kelondroMap(new kelondroDyn(bookmarksFile, 1024*bufferkb));
|
||||
this.tagsTable=new kelondroMap(new kelondroDyn(tagsFile, 1024*bufferkb));
|
||||
} catch (IOException e) {
|
||||
//TODO: check if both are corrupted
|
||||
bookmarksFile.delete();
|
||||
bookmarksFile.getParentFile().mkdirs();
|
||||
this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true));
|
||||
tagsFile.delete();
|
||||
tagsFile.getParentFile().mkdirs();
|
||||
this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true));
|
||||
}
|
||||
|
||||
}else{
|
||||
bookmarksFile.getParentFile().mkdirs();
|
||||
this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true));
|
||||
tagsFile.getParentFile().mkdirs();
|
||||
this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true));
|
||||
}
|
||||
}
|
||||
public void close(){
|
||||
try {
|
||||
bookmarksTable.close();
|
||||
} catch (IOException e) {}
|
||||
try {
|
||||
tagsTable.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
public int bookmarksSize(){
|
||||
return bookmarksTable.size();
|
||||
}
|
||||
public int tagsSize(){
|
||||
return tagsTable.size();
|
||||
}
|
||||
public String addTag(Tag tag){
|
||||
try {
|
||||
tagsTable.set(tag.getTagName(), tag.mem);
|
||||
return tag.getTagName();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
//TODO: Move it in listmanager?
|
||||
private String vector2string(Vector vector){
|
||||
Iterator it=vector.iterator();
|
||||
String ret="";
|
||||
if(it.hasNext()){
|
||||
ret=(String) it.next();
|
||||
while(it.hasNext()){
|
||||
ret+=","+(String)it.next();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
private Vector string2vector(String string){
|
||||
Vector ret=new Vector();
|
||||
ret.copyInto(string.split(","));
|
||||
return ret;
|
||||
}
|
||||
public Tag getTag(String tagName){
|
||||
Map map;
|
||||
try {
|
||||
map = tagsTable.get(tagName);
|
||||
if(map==null) return null;
|
||||
return new Tag(tagName, map);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public void removeTag(String tagName){
|
||||
try {
|
||||
tagsTable.remove(tagName);
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
public String addBookmark(Bookmark bookmark){
|
||||
try {
|
||||
bookmarksTable.set(bookmark.getUrlHash(), bookmark.mem);
|
||||
return bookmark.getUrlHash();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public Bookmark getBookmark(String urlHash){
|
||||
Map map;
|
||||
try {
|
||||
map = bookmarksTable.get(urlHash);
|
||||
if(map==null) return null;
|
||||
return new Bookmark(urlHash, map);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public void removeBookmark(String urlHash){
|
||||
try {
|
||||
bookmarksTable.remove(urlHash);
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
public Bookmark createBookmark(String url){
|
||||
return new Bookmark(url);
|
||||
}
|
||||
public Iterator tagIterator(boolean up){
|
||||
try {
|
||||
return new tagIterator(up);
|
||||
} catch (IOException e) {
|
||||
return new HashSet().iterator();
|
||||
}
|
||||
}
|
||||
public Iterator bookmarkIterator(boolean up){
|
||||
try {
|
||||
return new bookmarkIterator(up);
|
||||
} catch (IOException e) {
|
||||
return new HashSet().iterator();
|
||||
}
|
||||
}
|
||||
public void addBookmark(String url, String title, Vector tags){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclass, which stores an Tag
|
||||
*
|
||||
*/
|
||||
public class Tag{
|
||||
public static final String URL_HASHES="urlHashes";
|
||||
private String tagName;
|
||||
private Map mem;
|
||||
public Tag(String name, Map map){
|
||||
tagName=name;
|
||||
mem=map;
|
||||
}
|
||||
public Tag(String name, Vector entries){
|
||||
tagName=name;
|
||||
mem=new HashMap();
|
||||
mem.put(URL_HASHES, vector2string(entries));
|
||||
}
|
||||
public Tag(String name){
|
||||
tagName=name;
|
||||
mem=new HashMap();
|
||||
mem.put(URL_HASHES, "");
|
||||
}
|
||||
public String getTagName(){
|
||||
return tagName;
|
||||
}
|
||||
public Vector getUrlHashes(){
|
||||
return string2vector((String)this.mem.get(URL_HASHES));
|
||||
}
|
||||
public void add(String urlHash){
|
||||
Vector list=string2vector((String)this.mem.get(URL_HASHES));
|
||||
list.add(urlHash);
|
||||
this.mem.put(URL_HASHES, vector2string(list));
|
||||
}
|
||||
public void delete(String urlHash){
|
||||
Vector list=string2vector((String) this.mem.get(URL_HASHES));
|
||||
if(list.contains(urlHash)){
|
||||
list.remove(urlHash);
|
||||
}
|
||||
this.mem.put(URL_HASHES, list);
|
||||
}
|
||||
public void setTagsTable(){
|
||||
try {
|
||||
bookmarksDB.this.tagsTable.set(getTagName(), mem);
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Subclass, which stores the bookmark
|
||||
*
|
||||
*/
|
||||
public class Bookmark{
|
||||
public static final String BOOKMARK_URL="bookmarkUrl";
|
||||
public static final String BOOKMARK_TITLE="bookmarkTitle";
|
||||
public static final String BOOKMARK_TAGS="bookmarkTags";
|
||||
private String urlHash;
|
||||
private Map mem;
|
||||
public Bookmark(String urlHash, Map map){
|
||||
this.urlHash=urlHash;
|
||||
this.mem=map;
|
||||
}
|
||||
public Bookmark(String url){
|
||||
this.urlHash=plasmaURL.urlHash(url);
|
||||
mem=new HashMap();
|
||||
mem.put(BOOKMARK_URL, url);
|
||||
}
|
||||
public Bookmark(String urlHash, URL url){
|
||||
this.urlHash=urlHash;
|
||||
mem=new HashMap();
|
||||
mem.put(BOOKMARK_URL, url.toString());
|
||||
}
|
||||
public Bookmark(String urlHash, String url){
|
||||
this.urlHash=urlHash;
|
||||
mem=new HashMap();
|
||||
mem.put(BOOKMARK_URL, url);
|
||||
}
|
||||
public String getUrlHash(){
|
||||
return urlHash;
|
||||
}
|
||||
public String getUrl(){
|
||||
return (String) this.mem.get(BOOKMARK_URL);
|
||||
}
|
||||
public String getTags(){
|
||||
if(this.mem.containsKey(BOOKMARK_TAGS)){
|
||||
return (String)this.mem.get(BOOKMARK_TAGS);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
public String getTitle(){
|
||||
if(this.mem.containsKey(BOOKMARK_TITLE)){
|
||||
return (String) this.mem.get(BOOKMARK_TITLE);
|
||||
}
|
||||
return (String) this.mem.get(BOOKMARK_URL);
|
||||
}
|
||||
public void setProperty(String name, String value){
|
||||
mem.put(name, value);
|
||||
//setBookmarksTable();
|
||||
}
|
||||
public void addTag(String tag){
|
||||
Vector tags;
|
||||
if(!mem.containsKey(BOOKMARK_TAGS)){
|
||||
tags=new Vector();
|
||||
}else{
|
||||
tags=(Vector)mem.get(BOOKMARK_TAGS);
|
||||
}
|
||||
tags.add(tag);
|
||||
this.setTags(tags);
|
||||
}
|
||||
public void setTags(Vector tags){
|
||||
mem.put(BOOKMARK_TAGS, vector2string(tags));
|
||||
Iterator it=tags.iterator();
|
||||
while(it.hasNext()){
|
||||
String tagName=(String) it.next();
|
||||
Tag tag=getTag((String) tagName);
|
||||
if(tag == null){
|
||||
tag=new Tag(tagName);
|
||||
}
|
||||
tag.add(getUrlHash());
|
||||
tag.setTagsTable();
|
||||
}
|
||||
}
|
||||
public void setBookmarksTable(){
|
||||
try {
|
||||
bookmarksDB.this.bookmarksTable.set(getUrlHash(), mem);
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
public class tagIterator implements Iterator{
|
||||
kelondroDyn.dynKeyIterator tagIter;
|
||||
bookmarksDB.Tag nextEntry;
|
||||
public tagIterator(boolean up) throws IOException {
|
||||
this.tagIter = bookmarksDB.this.tagsTable.keys(up, false);
|
||||
this.nextEntry = null;
|
||||
}
|
||||
public boolean hasNext() {
|
||||
try {
|
||||
return this.tagIter.hasNext();
|
||||
} catch (kelondroException e) {
|
||||
//resetDatabase();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public Object next() {
|
||||
try {
|
||||
return getTag((String) this.tagIter.next());
|
||||
} catch (kelondroException e) {
|
||||
//resetDatabase();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public void remove() {
|
||||
if (this.nextEntry != null) {
|
||||
try {
|
||||
Object tagName = this.nextEntry.getTagName();
|
||||
if (tagName != null) removeTag((String) tagName);
|
||||
} catch (kelondroException e) {
|
||||
//resetDatabase();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public class bookmarkIterator implements Iterator{
|
||||
kelondroDyn.dynKeyIterator bookmarkIter;
|
||||
bookmarksDB.Bookmark nextEntry;
|
||||
public bookmarkIterator(boolean up) throws IOException {
|
||||
this.bookmarkIter = bookmarksDB.this.bookmarksTable.keys(up, false);
|
||||
this.nextEntry = null;
|
||||
}
|
||||
public boolean hasNext() {
|
||||
try {
|
||||
return this.bookmarkIter.hasNext();
|
||||
} catch (kelondroException e) {
|
||||
//resetDatabase();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public Object next() {
|
||||
try {
|
||||
return getBookmark((String) this.bookmarkIter.next());
|
||||
} catch (kelondroException e) {
|
||||
//resetDatabase();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public void remove() {
|
||||
if (this.nextEntry != null) {
|
||||
try {
|
||||
Object bookmarkName = this.nextEntry.getUrlHash();
|
||||
if (bookmarkName != null) removeBookmark((String) bookmarkName);
|
||||
} catch (kelondroException e) {
|
||||
//resetDatabase();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue