Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
better error handling for bookmarks
Michael Peter Christendee8b24d3c9a
diff --git a/htroot/Bookmarks.java b/htroot/Bookmarks.javaindex fc4bedcb6..881e14dd6 100644--- a/htroot/Bookmarks.java+++ b/htroot/Bookmarks.java@@ -192,7 +192,11 @@ public class Bookmarks {prop.put("mode_public", "0");prop.put("mode_feed", "0");} else {- final BookmarksDB.Bookmark bookmark = sb.bookmarksDB.getBookmark(urlHash);+ BookmarksDB.Bookmark bookmark = null;+ try {+ bookmark = sb.bookmarksDB.getBookmark(urlHash);+ } catch (IOException e1) {+ }if (bookmark == null) {// try to get the bookmark from the LURL databasefinal URIMetadataNode urlentry = sb.index.fulltext().getMetadata(ASCII.getBytes(urlHash));@@ -305,7 +309,11 @@ public class Bookmarks {count = 0;while(count < max_count && it.hasNext()) {- final Bookmark bookmark = sb.bookmarksDB.getBookmark(it.next());+ Bookmark bookmark = null;+ try {+ bookmark = sb.bookmarksDB.getBookmark(it.next());+ } catch (IOException e) {+ }if (bookmark != null){if (bookmark.getFeed() && isAdmin) {@@ -425,10 +433,12 @@ public class Bookmarks {final Iterator<String> bit = sb.bookmarksDB.getBookmarksIterator(fn, isAdmin);while (bit.hasNext()) {- final Bookmark bookmark=sb.bookmarksDB.getBookmark(bit.next());- if(bookmark == null) {- break;+ Bookmark bookmark = null;+ try {+ bookmark = sb.bookmarksDB.getBookmark(bit.next());+ } catch (IOException e) {}+ if (bookmark == null) break;prop.put("display_folderlist_" + count + "_folder", "<li><a href=\"" + bookmark.getUrl() + "\" title=\"" + bookmark.getDescription() + "\">" + bookmark.getTitle() + "</a></li>");count++;}diff --git a/htroot/api/bookmarks/get_bookmarks.java b/htroot/api/bookmarks/get_bookmarks.javaindex a72f8e1aa..21059dd2a 100644--- a/htroot/api/bookmarks/get_bookmarks.java+++ b/htroot/api/bookmarks/get_bookmarks.java@@ -1,5 +1,6 @@+import java.io.IOException;import java.util.Date;import java.util.Iterator;@@ -155,35 +156,38 @@ public class get_bookmarks {count = 0;BookmarksDB.Bookmark bookmark = null;while (count < itemsPerPage && it.hasNext()) {- bookmark = sb.bookmarksDB.getBookmark(it.next());- if (bookmark != null) {- prop.put("display_bookmarks_"+count+"_id",count);- prop.put("display_bookmarks_"+count+"_link",bookmark.getUrl());- prop.put("display_bookmarks_"+count+"_date", ISO8601Formatter.FORMATTER.format(new Date(bookmark.getTimeStamp())));- prop.put("display_bookmarks_"+count+"_rfc822date", HeaderFramework.formatRFC1123(new Date(bookmark.getTimeStamp())));- prop.put("display_bookmarks_"+count+"_public", (bookmark.getPublic() ? "0" : "1"));- prop.put("display_bookmarks_"+count+"_hash", bookmark.getUrlHash());- prop.put("display_bookmarks_"+count+"_comma", ",");-- // offer HTML encoded- prop.putHTML("display_bookmarks_"+count+"_title-html", bookmark.getTitle());- prop.putHTML("display_bookmarks_"+count+"_desc-html", bookmark.getDescription());- prop.putHTML("display_bookmarks_"+count+"_tags-html", bookmark.getTagsString().replaceAll(",", ", "));- prop.putHTML("display_bookmarks_"+count+"_folders-html", (bookmark.getFoldersString()));-- // XML encoded- prop.putXML("display_bookmarks_"+count+"_title-xml", bookmark.getTitle());- prop.putXML("display_bookmarks_"+count+"_desc-xml", bookmark.getDescription());- prop.putXML("display_bookmarks_"+count+"_tags-xml", bookmark.getTagsString());- prop.putXML("display_bookmarks_"+count+"_folders-xml", (bookmark.getFoldersString()));-- // and plain text (potentially unsecure)- prop.put("display_bookmarks_"+count+"_title", bookmark.getTitle());- prop.put("display_bookmarks_"+count+"_desc", bookmark.getDescription());- prop.put("display_bookmarks_"+count+"_tags", bookmark.getTagsString());- prop.put("display_bookmarks_"+count+"_folders", (bookmark.getFoldersString()));-- count++;+ try {+ bookmark = sb.bookmarksDB.getBookmark(it.next());+ if (bookmark != null) {+ prop.put("display_bookmarks_"+count+"_id",count);+ prop.put("display_bookmarks_"+count+"_link",bookmark.getUrl());+ prop.put("display_bookmarks_"+count+"_date", ISO8601Formatter.FORMATTER.format(new Date(bookmark.getTimeStamp())));+ prop.put("display_bookmarks_"+count+"_rfc822date", HeaderFramework.formatRFC1123(new Date(bookmark.getTimeStamp())));+ prop.put("display_bookmarks_"+count+"_public", (bookmark.getPublic() ? "0" : "1"));+ prop.put("display_bookmarks_"+count+"_hash", bookmark.getUrlHash());+ prop.put("display_bookmarks_"+count+"_comma", ",");++ // offer HTML encoded+ prop.putHTML("display_bookmarks_"+count+"_title-html", bookmark.getTitle());+ prop.putHTML("display_bookmarks_"+count+"_desc-html", bookmark.getDescription());+ prop.putHTML("display_bookmarks_"+count+"_tags-html", bookmark.getTagsString().replaceAll(",", ", "));+ prop.putHTML("display_bookmarks_"+count+"_folders-html", (bookmark.getFoldersString()));++ // XML encoded+ prop.putXML("display_bookmarks_"+count+"_title-xml", bookmark.getTitle());+ prop.putXML("display_bookmarks_"+count+"_desc-xml", bookmark.getDescription());+ prop.putXML("display_bookmarks_"+count+"_tags-xml", bookmark.getTagsString());+ prop.putXML("display_bookmarks_"+count+"_folders-xml", (bookmark.getFoldersString()));++ // and plain text (potentially unsecure)+ prop.put("display_bookmarks_"+count+"_title", bookmark.getTitle());+ prop.put("display_bookmarks_"+count+"_desc", bookmark.getDescription());+ prop.put("display_bookmarks_"+count+"_tags", bookmark.getTagsString());+ prop.put("display_bookmarks_"+count+"_folders", (bookmark.getFoldersString()));++ count++;+ }+ } catch (IOException e) {}}// eliminate the trailing comma for Json output@@ -250,36 +254,39 @@ public class get_bookmarks {BookmarksDB.Bookmark bookmark = null;Date date;while(bit.hasNext()){- bookmark = sb.bookmarksDB.getBookmark(bit.next());- date = new Date(bookmark.getTimeStamp());- prop.put("display_xbel_"+count+"_elements", "<bookmark id=\"" + bookmark.getUrlHash()- + "\" href=\"" + CharacterCoding.unicode2xml(bookmark.getUrl(), true)- + "\" added=\"" + CharacterCoding.unicode2xml(ISO8601Formatter.FORMATTER.format(date), true)+"\">");- count++;- prop.put("display_xbel_"+count+"_elements", "<title>");- count++;- prop.putXML("display_xbel_"+count+"_elements", bookmark.getTitle());- count++;- prop.put("display_xbel_"+count+"_elements", "</title>");- count++;- prop.put("display_xbel_"+count+"_elements", "<info>");- count++;- prop.put("display_xbel_"+count+"_elements", "<metadata owner=\"Mozilla\" ShortcutURL=\""- + CharacterCoding.unicode2xml(bookmark.getTagsString().replaceAll("/.*,", "").toLowerCase(), true)- + "\"/>");- count++;- prop.put("display_xbel_"+count+"_elements", "<metadata owner=\"YaCy\" public=\""+Boolean.toString(bookmark.getPublic())+"\"/>");- count++;- prop.put("display_xbel_"+count+"_elements", "</info>");- count++;- prop.put("display_xbel_"+count+"_elements", "<desc>");- count++;- prop.putXML("display_xbel_"+count+"_elements", bookmark.getDescription());- count++;- prop.put("display_xbel_"+count+"_elements", "</desc>");- count++;- prop.put("display_xbel_"+count+"_elements", "</bookmark>");- count++;+ try {+ bookmark = sb.bookmarksDB.getBookmark(bit.next());+ date = new Date(bookmark.getTimeStamp());+ prop.put("display_xbel_"+count+"_elements", "<bookmark id=\"" + bookmark.getUrlHash()+ + "\" href=\"" + CharacterCoding.unicode2xml(bookmark.getUrl(), true)+ + "\" added=\"" + CharacterCoding.unicode2xml(ISO8601Formatter.FORMATTER.format(date), true)+"\">");+ count++;+ prop.put("display_xbel_"+count+"_elements", "<title>");+ count++;+ prop.putXML("display_xbel_"+count+"_elements", bookmark.getTitle());+ count++;+ prop.put("display_xbel_"+count+"_elements", "</title>");+ count++;+ prop.put("display_xbel_"+count+"_elements", "<info>");+ count++;+ prop.put("display_xbel_"+count+"_elements", "<metadata owner=\"Mozilla\" ShortcutURL=\""+ + CharacterCoding.unicode2xml(bookmark.getTagsString().replaceAll("/.*,", "").toLowerCase(), true)+ + "\"/>");+ count++;+ prop.put("display_xbel_"+count+"_elements", "<metadata owner=\"YaCy\" public=\""+Boolean.toString(bookmark.getPublic())+"\"/>");+ count++;+ prop.put("display_xbel_"+count+"_elements", "</info>");+ count++;+ prop.put("display_xbel_"+count+"_elements", "<desc>");+ count++;+ prop.putXML("display_xbel_"+count+"_elements", bookmark.getDescription());+ count++;+ prop.put("display_xbel_"+count+"_elements", "</desc>");+ count++;+ prop.put("display_xbel_"+count+"_elements", "</bookmark>");+ count++;+ } catch (IOException e) {+ }}return count;}diff --git a/htroot/api/bookmarks/get_folders.java b/htroot/api/bookmarks/get_folders.javaindex fb8f207b9..5f8eb0e26 100644--- a/htroot/api/bookmarks/get_folders.java+++ b/htroot/api/bookmarks/get_folders.java@@ -1,5 +1,6 @@+import java.io.IOException;import java.util.Iterator;import net.yacy.cora.protocol.RequestHeader;import net.yacy.cora.util.CommonPattern;@@ -73,24 +74,27 @@ public class get_folders {it = sb.bookmarksDB.getBookmarksIterator(root, isAdmin);BookmarksDB.Bookmark bm;while (it.hasNext()) {- bm = sb.bookmarksDB.getBookmark(it.next());- // TODO: get rid of bmtype- if (post.containsKey("bmtype")) {- if (post.get("bmtype").equals("title")) {- prop.put("folders_"+count+"_foldername", bm.getTitle());- } else if (post.get("bmtype").equals("href")) {- prop.put("folders_"+count+"_foldername", "<a href='"+bm.getUrl()+" 'target='_blank'>"+bm.getTitle()+"</a>");- } else {- prop.put("folders_"+count+"_foldername", bm.getUrl());- }- }- prop.put("folders_"+count+"_expanded", "false");- prop.put("folders_"+count+"_url", bm.getUrl());- prop.put("folders_"+count+"_type", "file");- prop.put("folders_"+count+"_hash", bm.getUrlHash());- prop.put("folders_"+count+"_hasChildren", "false");- prop.put("folders_"+count+"_comma", ",");- count++;+ try {+ bm = sb.bookmarksDB.getBookmark(it.next());+ // TODO: get rid of bmtype+ if (post.containsKey("bmtype")) {+ if (post.get("bmtype").equals("title")) {+ prop.put("folders_"+count+"_foldername", bm.getTitle());+ } else if (post.get("bmtype").equals("href")) {+ prop.put("folders_"+count+"_foldername", "<a href='"+bm.getUrl()+" 'target='_blank'>"+bm.getTitle()+"</a>");+ } else {+ prop.put("folders_"+count+"_foldername", bm.getUrl());+ }+ }+ prop.put("folders_"+count+"_expanded", "false");+ prop.put("folders_"+count+"_url", bm.getUrl());+ prop.put("folders_"+count+"_type", "file");+ prop.put("folders_"+count+"_hash", bm.getUrlHash());+ prop.put("folders_"+count+"_hasChildren", "false");+ prop.put("folders_"+count+"_comma", ",");+ count++;+ } catch (IOException e) {+ }}count--;diff --git a/htroot/api/bookmarks/posts/all.java b/htroot/api/bookmarks/posts/all.javaindex 513107718..4ae815c19 100644--- a/htroot/api/bookmarks/posts/all.java+++ b/htroot/api/bookmarks/posts/all.java@@ -1,4 +1,5 @@+import java.io.IOException;import java.util.Date;import java.util.Iterator;@@ -31,21 +32,24 @@ public class all {BookmarksDB.Bookmark bookmark;Date date;while(it.hasNext()){- bookmark=switchboard.bookmarksDB.getBookmark(it.next());- prop.putXML("posts_"+count+"_url", bookmark.getUrl());- prop.putXML("posts_"+count+"_title", bookmark.getTitle());- prop.putXML("posts_"+count+"_description", bookmark.getDescription());- prop.putXML("posts_"+count+"_md5", Digest.encodeMD5Hex(bookmark.getUrl()));- date = new Date(bookmark.getTimeStamp());- prop.putXML("posts_"+count+"_time", ISO8601Formatter.FORMATTER.format(date));- prop.putXML("posts_"+count+"_tags", bookmark.getTagsString().replaceAll(","," "));-- // additional XML tags- prop.put("posts_"+count+"_isExtended",extendedXML ? "1" : "0");- if (extendedXML) {- prop.put("posts_"+count+"_isExtended_private", Boolean.toString(!bookmark.getPublic()));+ try {+ bookmark=switchboard.bookmarksDB.getBookmark(it.next());+ prop.putXML("posts_"+count+"_url", bookmark.getUrl());+ prop.putXML("posts_"+count+"_title", bookmark.getTitle());+ prop.putXML("posts_"+count+"_description", bookmark.getDescription());+ prop.putXML("posts_"+count+"_md5", Digest.encodeMD5Hex(bookmark.getUrl()));+ date = new Date(bookmark.getTimeStamp());+ prop.putXML("posts_"+count+"_time", ISO8601Formatter.FORMATTER.format(date));+ prop.putXML("posts_"+count+"_tags", bookmark.getTagsString().replaceAll(","," "));++ // additional XML tags+ prop.put("posts_"+count+"_isExtended",extendedXML ? "1" : "0");+ if (extendedXML) {+ prop.put("posts_"+count+"_isExtended_private", Boolean.toString(!bookmark.getPublic()));+ }+ count++;+ } catch (IOException e) {}- count++;}prop.put("posts", count);diff --git a/htroot/api/bookmarks/posts/get.java b/htroot/api/bookmarks/posts/get.javaindex 538768f60..9ec1dace7 100644--- a/htroot/api/bookmarks/posts/get.java+++ b/htroot/api/bookmarks/posts/get.java@@ -1,5 +1,6 @@+import java.io.IOException;import java.text.ParseException;import java.util.Date;import java.util.List;@@ -46,23 +47,26 @@ public class get {final List<String> bookmark_hashes = switchboard.bookmarksDB.getDate(Long.toString(parsedDate.getTime())).getBookmarkList();BookmarksDB.Bookmark bookmark = null;for (final String bookmark_hash : bookmark_hashes){- bookmark=switchboard.bookmarksDB.getBookmark(bookmark_hash);- if (ISO8601Formatter.FORMATTER.format(new Date(bookmark.getTimeStamp())).equals(date) &&- tag==null || bookmark.getTags().contains(tag) &&- isAdmin || bookmark.getPublic()){- prop.putHTML("posts_"+count+"_url", bookmark.getUrl());- prop.putHTML("posts_"+count+"_title", bookmark.getTitle());- prop.putHTML("posts_"+count+"_description", bookmark.getDescription());- prop.put("posts_"+count+"_md5", Digest.encodeMD5Hex(bookmark.getUrl()));- prop.put("posts_"+count+"_time", date);- prop.putHTML("posts_"+count+"_tags", bookmark.getTagsString().replaceAll(","," "));+ try {+ bookmark=switchboard.bookmarksDB.getBookmark(bookmark_hash);+ if (ISO8601Formatter.FORMATTER.format(new Date(bookmark.getTimeStamp())).equals(date) &&+ tag==null || bookmark.getTags().contains(tag) &&+ isAdmin || bookmark.getPublic()){+ prop.putHTML("posts_"+count+"_url", bookmark.getUrl());+ prop.putHTML("posts_"+count+"_title", bookmark.getTitle());+ prop.putHTML("posts_"+count+"_description", bookmark.getDescription());+ prop.put("posts_"+count+"_md5", Digest.encodeMD5Hex(bookmark.getUrl()));+ prop.put("posts_"+count+"_time", date);+ prop.putHTML("posts_"+count+"_tags", bookmark.getTagsString().replaceAll(","," "));- // additional XML tags- prop.put("posts_"+count+"_isExtended",extendedXML ? "1" : "0");- if (extendedXML) {- prop.put("posts_"+count+"_isExtended_private", Boolean.toString(!bookmark.getPublic()));+ // additional XML tags+ prop.put("posts_"+count+"_isExtended",extendedXML ? "1" : "0");+ if (extendedXML) {+ prop.put("posts_"+count+"_isExtended_private", Boolean.toString(!bookmark.getPublic()));+ }+ count++;}- count++;+ } catch (IOException e) {}}prop.put("posts", count);diff --git a/htroot/api/bookmarks/tags/addTag_p.java b/htroot/api/bookmarks/tags/addTag_p.javaindex 9deed8f7d..5b966abe1 100644--- a/htroot/api/bookmarks/tags/addTag_p.java+++ b/htroot/api/bookmarks/tags/addTag_p.java@@ -1,4 +1,6 @@+import java.io.IOException;+import net.yacy.cora.protocol.RequestHeader;import net.yacy.data.BookmarksDB.Bookmark;import net.yacy.search.Switchboard;@@ -21,9 +23,14 @@ public class addTag_p {switchboard.bookmarksDB.addTag(post.get("selectTag"), post.get("addTag"));prop.put("result", "1");//success} else if (post.containsKey("urlhash") && post.containsKey("addTag")) {- final Bookmark bm = switchboard.bookmarksDB.getBookmark(post.get("urlhash"));- bm.addTag(post.get("addTag"));- prop.put("result", "1");//success+ Bookmark bm;+ try {+ bm = switchboard.bookmarksDB.getBookmark(post.get("urlhash"));+ bm.addTag(post.get("addTag"));+ prop.put("result", "1");//success+ } catch (IOException e) {+ prop.put("result", "0");//success+ }}}// return rewrite propertiesdiff --git a/htroot/api/bookmarks/xbel/xbel.java b/htroot/api/bookmarks/xbel/xbel.javaindex 289ff6ee9..c66986d1d 100644--- a/htroot/api/bookmarks/xbel/xbel.java+++ b/htroot/api/bookmarks/xbel/xbel.java@@ -1,5 +1,6 @@+import java.io.IOException;import java.util.Date;import java.util.Iterator;@@ -106,36 +107,39 @@ public class xbel {BookmarksDB.Bookmark bookmark;Date date;while(bit.hasNext()){- bookmark=switchboard.bookmarksDB.getBookmark(bit.next());- date=new Date(bookmark.getTimeStamp());- prop.put("xbel_"+count+"_elements", "<bookmark id=\"" + bookmark.getUrlHash()- + "\" href=\"" + CharacterCoding.unicode2xml(bookmark.getUrl(), true)- + "\" added=\"" + CharacterCoding.unicode2xml(ISO8601Formatter.FORMATTER.format(date), true)+"\">");- count++;- prop.put("xbel_"+count+"_elements", "<title>");- count++;- prop.putXML("xbel_"+count+"_elements", bookmark.getTitle());- count++;- prop.put("xbel_"+count+"_elements", "</title>");- count++;- prop.put("xbel_"+count+"_elements", "<info>");- count++;- prop.put("xbel_"+count+"_elements", "<metadata owner=\"Mozilla\" ShortcutURL=\""- + CharacterCoding.unicode2xml(bookmark.getTagsString().replaceAll("/.*,", "").toLowerCase(), true)- + "\"/>");- count++;- prop.put("xbel_"+count+"_elements", "<metadata owner=\"YaCy\" public=\""+Boolean.toString(bookmark.getPublic())+"\"/>");- count++;- prop.put("xbel_"+count+"_elements", "</info>");- count++;- prop.put("xbel_"+count+"_elements", "<desc>");- count++;- prop.putXML("xbel_"+count+"_elements", bookmark.getDescription());- count++;- prop.put("xbel_"+count+"_elements", "</desc>");- count++;- prop.put("xbel_"+count+"_elements", "</bookmark>");- count++;+ try {+ bookmark=switchboard.bookmarksDB.getBookmark(bit.next());+ date=new Date(bookmark.getTimeStamp());+ prop.put("xbel_"+count+"_elements", "<bookmark id=\"" + bookmark.getUrlHash()+ + "\" href=\"" + CharacterCoding.unicode2xml(bookmark.getUrl(), true)+ + "\" added=\"" + CharacterCoding.unicode2xml(ISO8601Formatter.FORMATTER.format(date), true)+"\">");+ count++;+ prop.put("xbel_"+count+"_elements", "<title>");+ count++;+ prop.putXML("xbel_"+count+"_elements", bookmark.getTitle());+ count++;+ prop.put("xbel_"+count+"_elements", "</title>");+ count++;+ prop.put("xbel_"+count+"_elements", "<info>");+ count++;+ prop.put("xbel_"+count+"_elements", "<metadata owner=\"Mozilla\" ShortcutURL=\""+ + CharacterCoding.unicode2xml(bookmark.getTagsString().replaceAll("/.*,", "").toLowerCase(), true)+ + "\"/>");+ count++;+ prop.put("xbel_"+count+"_elements", "<metadata owner=\"YaCy\" public=\""+Boolean.toString(bookmark.getPublic())+"\"/>");+ count++;+ prop.put("xbel_"+count+"_elements", "</info>");+ count++;+ prop.put("xbel_"+count+"_elements", "<desc>");+ count++;+ prop.putXML("xbel_"+count+"_elements", bookmark.getDescription());+ count++;+ prop.put("xbel_"+count+"_elements", "</desc>");+ count++;+ prop.put("xbel_"+count+"_elements", "</bookmark>");+ count++;+ } catch (IOException e) {+ }}return count;}diff --git a/htroot/api/ymarks/import_ymark.java b/htroot/api/ymarks/import_ymark.javaindex eec1a98f1..968ffcdcc 100644--- a/htroot/api/ymarks/import_ymark.java+++ b/htroot/api/ymarks/import_ymark.java@@ -173,27 +173,30 @@ public class import_ymark {final Iterator<String> bit=sb.bookmarksDB.getBookmarksIterator(isAdmin);BookmarksDB.Bookmark bookmark;while(bit.hasNext()){- bookmark=sb.bookmarksDB.getBookmark(bit.next());- final YMarkEntry bmk_entry = new YMarkEntry(false);- bmk_entry.put(YMarkEntry.BOOKMARK.URL.key(), bookmark.getUrl());try {- if(!sb.tables.has(YMarkTables.TABLES.BOOKMARKS.tablename(bmk_user), YMarkUtil.getBookmarkId(bookmark.getUrl()))) {- bmk_entry.put(YMarkEntry.BOOKMARK.PUBLIC.key(), bookmark.getPublic() ? "true" : "false");- bmk_entry.put(YMarkEntry.BOOKMARK.TITLE.key(), bookmark.getTitle());- bmk_entry.put(YMarkEntry.BOOKMARK.DESC.key(), bookmark.getDescription());- bmk_entry.put(YMarkEntry.BOOKMARK.TAGS.key(), bookmark.getTagsString());- bmk_entry.put(YMarkEntry.BOOKMARK.FOLDERS.key(), root+bookmark.getFoldersString().replaceAll(".*"+YMarkUtil.TAGS_SEPARATOR+YMarkUtil.FOLDERS_SEPARATOR, root+YMarkUtil.FOLDERS_SEPARATOR));- }- if(autotag) {- bmk_entry.put(YMarkEntry.BOOKMARK.TAGS.key(), YMarkAutoTagger.autoTag(bookmark.getUrl(), sb.loader, 3, sb.tables.bookmarks.getTags(bmk_user)));- }- sb.tables.bookmarks.addBookmark(bmk_user, bmk_entry, merge, true);- prop.put("status", "1");- } catch (final MalformedURLException e) {- Log.logException(e);- } catch (final IOException e) {- Log.logException(e);- }+ bookmark=sb.bookmarksDB.getBookmark(bit.next());+ final YMarkEntry bmk_entry = new YMarkEntry(false);+ bmk_entry.put(YMarkEntry.BOOKMARK.URL.key(), bookmark.getUrl());+ try {+ if(!sb.tables.has(YMarkTables.TABLES.BOOKMARKS.tablename(bmk_user), YMarkUtil.getBookmarkId(bookmark.getUrl()))) {+ bmk_entry.put(YMarkEntry.BOOKMARK.PUBLIC.key(), bookmark.getPublic() ? "true" : "false");+ bmk_entry.put(YMarkEntry.BOOKMARK.TITLE.key(), bookmark.getTitle());+ bmk_entry.put(YMarkEntry.BOOKMARK.DESC.key(), bookmark.getDescription());+ bmk_entry.put(YMarkEntry.BOOKMARK.TAGS.key(), bookmark.getTagsString());+ bmk_entry.put(YMarkEntry.BOOKMARK.FOLDERS.key(), root+bookmark.getFoldersString().replaceAll(".*"+YMarkUtil.TAGS_SEPARATOR+YMarkUtil.FOLDERS_SEPARATOR, root+YMarkUtil.FOLDERS_SEPARATOR));+ }+ if(autotag) {+ bmk_entry.put(YMarkEntry.BOOKMARK.TAGS.key(), YMarkAutoTagger.autoTag(bookmark.getUrl(), sb.loader, 3, sb.tables.bookmarks.getTags(bmk_user)));+ }+ sb.tables.bookmarks.addBookmark(bmk_user, bmk_entry, merge, true);+ prop.put("status", "1");+ } catch (final MalformedURLException e) {+ Log.logException(e);+ } catch (final IOException e) {+ Log.logException(e);+ }+ } catch (IOException e1) {+ }}} else if(post.containsKey("importer") && post.get("importer").equals("dmoz")) {if(!isAdmin) {diff --git a/source/net/yacy/data/BookmarksDB.java b/source/net/yacy/data/BookmarksDB.javaindex c9526697b..9f98c9b4f 100644--- a/source/net/yacy/data/BookmarksDB.java+++ b/source/net/yacy/data/BookmarksDB.java@@ -39,7 +39,6 @@ import java.util.concurrent.ConcurrentHashMap;import net.yacy.cora.document.ASCII;import net.yacy.cora.document.UTF8;import net.yacy.cora.order.NaturalOrder;-import net.yacy.cora.util.SpaceExceededException;import net.yacy.kelondro.blob.MapHeap;import net.yacy.kelondro.data.meta.DigestURI;import net.yacy.kelondro.logging.Log;@@ -154,25 +153,23 @@ public class BookmarksDB {}- public Bookmark getBookmark(final String urlHash){+ public Bookmark getBookmark(final String urlHash) throws IOException {try {final Map<String, String> map = this.bookmarks.get(ASCII.getBytes(urlHash));- return (map == null) ? null : new Bookmark(map);- } catch (MalformedURLException e) {- Log.logException(e);- return null;- } catch (final IOException e) {- Log.logException(e);- return null;- } catch (final SpaceExceededException e) {- Log.logException(e);- return null;+ if (map == null) throw new IOException("cannot get bookmark for url hash " + urlHash);+ return new Bookmark(map);+ } catch (Throwable e) {+ throw new IOException(e.getMessage());}}public boolean removeBookmark(final String urlHash){- final Bookmark bookmark = getBookmark(urlHash);- if (bookmark == null) return false; //does not exist+ Bookmark bookmark;+ try {+ bookmark = getBookmark(urlHash);+ } catch (IOException e1) {+ return false;+ }final Set<String> tagSet = bookmark.getTags();BookmarksDB.Tag tag=null;final Iterator<String> it=tagSet.iterator();@@ -218,18 +215,21 @@ public class BookmarksDB {final String tagHash=BookmarkHelper.tagHash(tagName);final Tag tag=getTag(tagHash);Set<String> hashes=new HashSet<String>();- if(tag != null){+ if (tag != null) {hashes=getTag(tagHash).getUrlHashes();}- if(priv){+ if (priv) {set.addAll(hashes);- }else{+ } else {final Iterator<String> it=hashes.iterator();Bookmark bm;while(it.hasNext()){- bm = getBookmark(it.next());- if (bm != null && bm.getPublic()) {- set.add(bm.getUrlHash());+ try {+ bm = getBookmark(it.next());+ if (bm != null && bm.getPublic()) {+ set.add(bm.getUrlHash());+ }+ } catch (IOException e) {}}}@@ -308,16 +308,19 @@ public class BookmarksDB {Bookmark bm;Tag tag;Set<String> tagSet;- while(bit.hasNext()){- bm=getBookmark(bit.next());- if (bm == null) continue;- tagSet = bm.getTags();- it = tagSet.iterator();- while (it.hasNext()) {- tag=getTag(BookmarkHelper.tagHash(it.next()) );- if((priv ||tag.hasPublicItems()) && tag != null){- set.add(tag);+ while (bit.hasNext()) {+ try {+ bm = getBookmark(bit.next());+ if (bm == null) continue;+ tagSet = bm.getTags();+ it = tagSet.iterator();+ while (it.hasNext()) {+ tag=getTag(BookmarkHelper.tagHash(it.next()) );+ if((priv ||tag.hasPublicItems()) && tag != null){+ set.add(tag);+ }}+ } catch (IOException e) {}}return set.iterator();@@ -350,12 +353,15 @@ public class BookmarksDB {Bookmark bookmark;Set<String> tagSet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);for (final String urlHash : urlHashes) { // looping through all bookmarks which were tagged with oldName- bookmark = getBookmark(urlHash);- tagSet = bookmark.getTags();- tagSet.remove(oldName);- bookmark.setTags(tagSet, true); // might not be needed, but doesn't hurt- if(!"".equals(newName)) bookmark.addTag(newName);- saveBookmark(bookmark);+ try {+ bookmark = getBookmark(urlHash);+ tagSet = bookmark.getTags();+ tagSet.remove(oldName);+ bookmark.setTags(tagSet, true); // might not be needed, but doesn't hurt+ if(!"".equals(newName)) bookmark.addTag(newName);+ saveBookmark(bookmark);+ } catch (IOException e) {+ }}return true;}@@ -366,9 +372,12 @@ public class BookmarksDB {Bookmark bookmark;for (final String urlHash : getTag(BookmarkHelper.tagHash(selectTag)).getUrlHashes()) { // looping through all bookmarks which were tagged with selectTag- bookmark = getBookmark(urlHash);- bookmark.addTag(newTag);- saveBookmark(bookmark);+ try {+ bookmark = getBookmark(urlHash);+ bookmark.addTag(newTag);+ saveBookmark(bookmark);+ } catch (IOException e) {+ }}}@@ -499,11 +508,15 @@ public class BookmarksDB {this.entry.put(BOOKMARK_URL, url.toNormalform(false));this.tagNames = new HashSet<String>();this.timestamp = System.currentTimeMillis();- final Bookmark oldBm=getBookmark(this.urlHash);- if(oldBm!=null && oldBm.entry.containsKey(BOOKMARK_TIMESTAMP)){- this.entry.put(BOOKMARK_TIMESTAMP, oldBm.entry.get(BOOKMARK_TIMESTAMP)); //preserve timestamp on edit- }else{- this.entry.put(BOOKMARK_TIMESTAMP, String.valueOf(System.currentTimeMillis()));+ Bookmark oldBm;+ try {+ oldBm = getBookmark(this.urlHash);+ if(oldBm!=null && oldBm.entry.containsKey(BOOKMARK_TIMESTAMP)){+ this.entry.put(BOOKMARK_TIMESTAMP, oldBm.entry.get(BOOKMARK_TIMESTAMP)); //preserve timestamp on edit+ }else{+ this.entry.put(BOOKMARK_TIMESTAMP, String.valueOf(System.currentTimeMillis()));+ }+ } catch (IOException e) {}final BookmarkDate.Entry bmDate=BookmarksDB.this.dates.getDate(this.entry.get(BOOKMARK_TIMESTAMP));bmDate.add(this.urlHash);@@ -692,7 +705,12 @@ public class BookmarksDB {@Overridepublic Bookmark next() {- return getBookmark(UTF8.String(this.bookmarkIter.next()));+ try {+ return getBookmark(UTF8.String(this.bookmarkIter.next()));+ } catch (IOException e) {+ this.bookmarkIter.remove();+ return null;+ }}@Override@@ -717,16 +735,19 @@ public class BookmarksDB {@Overridepublic int compare(final String obj1, final String obj2) {- final Bookmark bm1 = getBookmark(obj1);- final Bookmark bm2 = getBookmark(obj2);- if (bm1 == null || bm2 == null) {- return 0; //XXX: i think this should not happen? maybe this needs further tracing of the bug- }- if (this.newestFirst){- if (bm2.getTimeStamp() - bm1.getTimeStamp() >0) return 1;- return -1;+ try {+ Bookmark bm1 = getBookmark(obj1);+ Bookmark bm2 = getBookmark(obj2);+ if (bm1 == null || bm2 == null) {+ return 0; //XXX: i think this should not happen? maybe this needs further tracing of the bug+ }+ if (this.newestFirst){+ if (bm2.getTimeStamp() - bm1.getTimeStamp() >0) return 1;+ return -1;+ }+ if (bm1.getTimeStamp() - bm2.getTimeStamp() > 0) return 1;+ } catch (IOException e) {}- if (bm1.getTimeStamp() - bm2.getTimeStamp() > 0) return 1;return -1;}}