Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
dates Table for bookmarksdb(needed for del.icio.us api) Files in DATA/DATA Migration: move bookmarks.db from SETTINGS in DATA
allo9cce3c5709d9
diff --git a/source/de/anomic/data/bookmarksDB.java b/source/de/anomic/data/bookmarksDB.javaindex c368a5abf..48620686e 100644--- a/source/de/anomic/data/bookmarksDB.java+++ b/source/de/anomic/data/bookmarksDB.java@@ -44,7 +44,9 @@ package de.anomic.data;import java.io.File;import java.io.IOException;import java.net.URL;+import java.text.SimpleDateFormat;import java.util.Comparator;+import java.util.Date;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;@@ -61,8 +63,10 @@ import de.anomic.server.logging.serverLog;public class bookmarksDB {kelondroMap tagsTable;kelondroMap bookmarksTable;+ kelondroMap datesTable;- public bookmarksDB(File bookmarksFile, File tagsFile, int bufferkb){+ public bookmarksDB(File bookmarksFile, File tagsFile, File datesFile, int bufferkb){+ //bookmarks//check if database existsif(bookmarksFile.exists()){try {@@ -72,13 +76,15 @@ public class bookmarksDB {//database reset :-((bookmarksFile.delete();bookmarksFile.getParentFile().mkdirs();- this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true));+ //urlHash is 12 bytes long+ this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 12, 256, true));}}else{//new databasebookmarksFile.getParentFile().mkdirs();- this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true));+ this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 12, 256, true));}+ //tags//check if database existsif(tagsFile.exists()){try {@@ -88,16 +94,36 @@ public class bookmarksDB {//reset databasetagsFile.delete();tagsFile.getParentFile().mkdirs();+ // max. 128 byte long tagsthis.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true));rebuildTags();}-}else{//new databasetagsFile.getParentFile().mkdirs();this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true));rebuildTags();}+ // dates+ //check if database exists+ if(datesFile.exists()){+ try {+ //open it+ this.datesTable=new kelondroMap(new kelondroDyn(datesFile, 1024*bufferkb));+ } catch (IOException e) {+ //reset database+ datesFile.delete();+ datesFile.getParentFile().mkdirs();+ //YYYY-MM-DDTHH:mm:ssZ = 20 byte. currently used: YYYY-MM-DD = 10 bytes+ this.datesTable = new kelondroMap(new kelondroDyn(datesFile, bufferkb * 1024, 20, 256, true));+ rebuildDates();+ }+ }else{+ //new database+ datesFile.getParentFile().mkdirs();+ this.datesTable = new kelondroMap(new kelondroDyn(datesFile, bufferkb * 1024, 20, 256, true));+ rebuildDates();+ }}public void close(){try {@@ -106,6 +132,9 @@ public class bookmarksDB {try {tagsTable.close();} catch (IOException e) {}+ try {+ datesTable.close();+ } catch (IOException e) {}}public int bookmarksSize(){return bookmarksTable.size();@@ -167,6 +196,24 @@ public class bookmarksDB {}serverLog.logInfo("BOOKMARKS", "Rebuilt "+tagsTable.size()+" tags using your "+bookmarksTable.size()+" bookmarks.");}+ public void rebuildDates(){+ serverLog.logInfo("BOOKMARKS", "rebuilding dates.db from bookmarks.db...");+ Iterator it=bookmarkIterator(true);+ Bookmark bookmark;+ String date;+ bookmarksDate bmDate;+ while(it.hasNext()){+ bookmark=(Bookmark) it.next();+ date = (new SimpleDateFormat("yyyy-MM-dd")).format(new Date(bookmark.getTimeStamp()));+ bmDate=getDate(date);+ if(bmDate==null){+ bmDate=new bookmarksDate(date);+ }+ bmDate.add(bookmark.getUrlHash());+ bmDate.setDatesTable();+ }+ serverLog.logInfo("BOOKMARKS", "Rebuilt "+datesTable.size()+" dates using your "+bookmarksTable.size()+" bookmarks.");+ }public Tag getTag(String tagName){Map map;try {@@ -177,6 +224,17 @@ public class bookmarksDB {return null;}}+ public bookmarksDate getDate(String date){+ Map map;+ try {+ map=datesTable.get(date);+ if(map==null) return null;+ return new bookmarksDate(date, map);+ } catch (IOException e) {+ return null;+ }++ }public boolean renameTag(String oldName, String newName){Tag tag=getTag(oldName);if (tag != null) {@@ -346,6 +404,67 @@ public class bookmarksDB {return string2vector(((String)this.mem.get(URL_HASHES))).size();}}+ class bookmarksDate{+ public static final String URL_HASHES="urlHashes";+ private Map mem;+ String date;+ public bookmarksDate(String mydate){+ date=mydate;+ mem=new HashMap();+ mem.put(URL_HASHES, "");+ }+ public bookmarksDate(String mydate, Map map){+ date=mydate;+ mem=map;+ }+ public bookmarksDate(String mydate, Vector entries){+ date=mydate;+ mem=new HashMap();+ mem.put(URL_HASHES, vector2string(entries));+ }+ public void add(String urlHash){+ String urlHashes = (String)mem.get(URL_HASHES);+ Vector list;+ if(urlHashes != null && !urlHashes.equals("")){+ list=string2vector(urlHashes);+ }else{+ list=new Vector();+ }+ if(!list.contains(urlHash) && !urlHash.equals("")){+ list.add(urlHash);+ }+ this.mem.put(URL_HASHES, vector2string(list));+ /*if(urlHashes!=null && !urlHashes.equals("") ){+ if(urlHashes.indexOf(urlHash) <0){+ this.mem.put(URL_HASHES, urlHashes+","+urlHash);+ }+ }else{+ this.mem.put(URL_HASHES, urlHash);+ }*/+ }+ 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, vector2string(list));+ }+ public void setDatesTable(){+ try {+ if(this.size() >0){+ bookmarksDB.this.datesTable.set(getDateString(), mem);+ }else{+ bookmarksDB.this.datesTable.remove(getDateString());+ }+ } catch (IOException e) {}+ }+ public String getDateString(){+ return date;+ }+ public int size(){+ return string2vector(((String)this.mem.get(URL_HASHES))).size();+ }+ }/*** Subclass, which stores the bookmark*diff --git a/source/de/anomic/plasma/plasmaSwitchboard.java b/source/de/anomic/plasma/plasmaSwitchboard.javaindex bacc8ea19..b97ef584d 100644--- a/source/de/anomic/plasma/plasmaSwitchboard.java+++ b/source/de/anomic/plasma/plasmaSwitchboard.java@@ -434,9 +434,10 @@ public final class plasmaSwitchboard extends serverAbstractSwitch implements ser//Init bookmarks DBthis.log.logConfig("Loading Bookmarks DB");- File bookmarksFile = new File(getRootPath(), "DATA/SETTINGS/bookmarks.db");- File tagsFile = new File(getRootPath(), "DATA/SETTINGS/tags.db");- this.bookmarksDB = new bookmarksDB(bookmarksFile, tagsFile, 512);+ File bookmarksFile = new File(getRootPath(), "DATA/DATA/bookmarks.db");+ File tagsFile = new File(getRootPath(), "DATA/DATA/bookmarkTags.db");+ File datesFile = new File(getRootPath(), "DATA/DATA/bookmarkDates.db");+ this.bookmarksDB = new bookmarksDB(bookmarksFile, tagsFile, datesFile, 512);this.log.logConfig("Loaded Bookmarks DB from files "+ bookmarksFile.getName()+ ", "+tagsFile.getName());this.log.logConfig(this.bookmarksDB.tagsSize()+" Tag, "+this.bookmarksDB.bookmarksSize()+" Bookmarks");