Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Merge remote-tracking branch 'origin/master'
Michael Peter Christen8c099d2106d3
diff --cc htroot/api/ymarks/import_ymark.javaindex d35707581,35310ffa4..772b1e94a--- a/htroot/api/ymarks/import_ymark.java+++ b/htroot/api/ymarks/import_ymark.java@@@ -10,7 -14,7 +14,6 @@@ import java.util.zip.GZIPInputStreamimport net.yacy.cora.document.UTF8;import net.yacy.cora.protocol.RequestHeader;- import net.yacy.cora.services.federated.yacy.CacheStrategy;-import net.yacy.cora.util.SpaceExceededException;import net.yacy.document.Parser.Failure;import net.yacy.document.content.SurrogateReader;import net.yacy.kelondro.blob.Tables;@@@ -166,11 -162,11 +161,9 @@@ public class import_ymark}prop.put("status", "1");} catch (final IOException e) {- // TODO Auto-generated catch block- e.printStackTrace();+ Log.logException(e);} catch (final Failure e) {- // TODO Auto-generated catch block- e.printStackTrace();+ Log.logException(e);- } catch (SpaceExceededException e) {- Log.logException(e);}} else if(post.containsKey("importer") && post.get("importer").equals("bmks")) {if(!isAdmin) {@@@ -197,22 -193,39 +190,37 @@@sb.tables.bookmarks.addBookmark(bmk_user, bmk_entry, merge, true);prop.put("status", "1");} catch (final MalformedURLException e) {- // TODO Auto-generated catch block- e.printStackTrace();+ Log.logException(e);} catch (final IOException e) {- // TODO Auto-generated catch block- e.printStackTrace();+ Log.logException(e);- } catch (SpaceExceededException e) {- Log.logException(e);}}+ } else if(post.containsKey("importer") && post.get("importer").equals("dmoz")) {+ if(!isAdmin) {+ prop.authenticationRequired();+ return prop;+ }- try {++ try {+ final File in = new File(sb.workPath, "content.rdf.u8.gz");+ final InputStream gzip = new FileInputStream(in);+ final InputStream content = new GZIPInputStream(gzip);+ final InputStreamReader reader = new InputStreamReader(content, "UTF-8");+ final BufferedReader breader = new BufferedReader(reader);- final MonitoredReader mreader = new MonitoredReader(breader, 1024*1024, in.length());-++ final MonitoredReader mreader = new MonitoredReader(breader, 1024*1024, in.length());+++ final String source = post.get("source", "");+ final YMarkDMOZImporter DMOZImporter = new YMarkDMOZImporter(mreader, queueSize, root, source);-- mreader.addChangeListener(sb.tables.bookmarks.getProgressListener("DMOZImporter"));++++ mreader.addChangeListener(sb.tables.bookmarks.getProgressListener("DMOZImporter"));+ DMOZImporter.setDepth(6);+ InstantBusyThread.oneTimeJob(DMOZImporter, 0);+ InstantBusyThread.oneTimeJob(DMOZImporter.getConsumer(sb, bmk_user, autoTaggingQueue, autotag, empty, indexing, medialink), 0);-+++ prop.put("status", "1");+ } catch (Exception e) {+ Log.logException(e);+ }}- if(post.containsKey("autotag") && !post.get("autotag", "off").equals("off")) {- try {- autoTaggingQueue.put(YMarkAutoTagger.POISON);- Log.logInfo(YMarkTables.BOOKMARKS_LOG, "Importer inserted poison pill in autoTagging queue");- } catch (final InterruptedException e) {- Log.logException(e);- }- }} else {prop.put(serverObjects.ACTION_AUTHENTICATE, YMarkTables.USER_AUTHENTICATE_MSG);}@@@ -233,61 -246,22 +241,20 @@@} else if(!bmk.containsKey(YMarkEntry.BOOKMARK.TAGS.key()) || bmk.get(YMarkEntry.BOOKMARK.TAGS.key()).equals(YMarkEntry.BOOKMARK.TAGS.deflt())) {autoTaggingQueue.put(url);}- }+ }-// fill crawlerif (indexing.equals("single")) {- crawlStart(sb, new DigestURI(url), CrawlProfile.MATCH_ALL_STRING, CrawlProfile.MATCH_NEVER_STRING, 0, true, medialink);+ bmk.crawl(YMarkCrawlStart.CRAWLSTART.SINGLE, medialink, sb);} else if (indexing.equals("onelink")) {- crawlStart(sb, new DigestURI(url), CrawlProfile.MATCH_ALL_STRING, CrawlProfile.MATCH_NEVER_STRING, 1, true, medialink);+ bmk.crawl(YMarkCrawlStart.CRAWLSTART.ONE_LINK, medialink, sb);} else if (indexing.equals("fulldomain")) {- final DigestURI u = new DigestURI(url);- crawlStart(sb, u, CrawlProfile.mustMatchFilterFullDomain(u), CrawlProfile.MATCH_NEVER_STRING, 99, false, medialink);+ bmk.crawl(YMarkCrawlStart.CRAWLSTART.FULL_DOMAIN, medialink, sb);}}} catch (final IOException e) {Log.logException(e);} catch (final InterruptedException e) {Log.logException(e);- } catch (SpaceExceededException e) {- Log.logException(e);}}-- public static String crawlStart(- final Switchboard sb,- final DigestURI startURL,- final String urlMustMatch,- final String urlMustNotMatch,- final int depth,- final boolean crawlingQ, final boolean medialink) {- final CrawlProfile pe = new CrawlProfile(- (startURL.getHost() == null) ? startURL.toNormalform(true, false) : startURL.getHost(), null,- urlMustMatch,- urlMustNotMatch,- CrawlProfile.MATCH_ALL_STRING,- CrawlProfile.MATCH_NEVER_STRING,- "", depth, medialink,- CrawlProfile.getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_PROXY_RECRAWL_CYCLE), -1, crawlingQ,- true, true, true, false, true, true, true,- CacheStrategy.IFFRESH,- "robot_import");- sb.crawler.putActive(pe.handle().getBytes(), pe);- return sb.crawlStacker.stackCrawl(new Request(- sb.peers.mySeed().hash.getBytes(),- startURL,- null,- "CRAWLING-ROOT",- new Date(),- pe.handle(), 0, 0, 0, 0- ));- }--}+}---------diff --cc source/de/anomic/data/ymark/YMarkCrawlStart.javaindex d0474b3a0,73f314ecf..4efc2ac32--- a/source/de/anomic/data/ymark/YMarkCrawlStart.java+++ b/source/de/anomic/data/ymark/YMarkCrawlStart.java@@@ -47,7 -51,11 +51,11 @@@ public class YMarkCrawlStart extends Haprivate Date date_recording;private String apicall_pk;private String url;-++ public static enum CRAWLSTART {+ SINGLE, ONE_LINK, FULL_DOMAIN+ }-++public YMarkCrawlStart(final WorkTables worktables) {super();this.date_recording = new Date(0);@@@ -80,11 -88,14 +88,14 @@@return new Date(0);return this.date_next_exec;}-- public boolean hasSchedule() {++ public boolean hasSchedule() {- return !this.isEmpty() && this.date_next_exec.after(new Date());+ if(!this.isEmpty() && this.date_next_exec.after(new Date()))+ return true;+ else+ return false;}-+public boolean isRunning(final CrawlSwitchboard crawler) {final Iterator<byte[]> iter = crawler.getActive().iterator();while(iter.hasNext()) {@@@ -158,4 -169,30 +169,37 @@@// TODO Auto-generated catch block}}-+++ public static String crawlStart(+ final Switchboard sb,+ final DigestURI startURL,+ final String urlMustMatch,+ final String urlMustNotMatch,+ final int depth,+ final boolean crawlingQ, final boolean medialink) {+ final CrawlProfile pe = new CrawlProfile(- (startURL.getHost() == null) ? startURL.toNormalform(true, false) : startURL.getHost(), null,- urlMustMatch,- urlMustNotMatch,- CrawlProfile.MATCH_ALL_STRING,- CrawlProfile.MATCH_NEVER_STRING,- "", depth, medialink,- CrawlProfile.getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_PROXY_RECRAWL_CYCLE), -1, crawlingQ, true, true, true, false, true, true, true,CacheStrategy.IFFRESH);++ (startURL.getHost() == null) ? startURL.toNormalform(true, false) : startURL.getHost(), null,++ urlMustMatch,++ urlMustNotMatch,++ CrawlProfile.MATCH_ALL_STRING,++ CrawlProfile.MATCH_NEVER_STRING,++ "",++ depth,++ medialink,++ CrawlProfile.getRecrawlDate(CrawlSwitchboard.CRAWL_PROFILE_PROXY_RECRAWL_CYCLE),++ -1,++ crawlingQ,++ true, true, true, false, true, true, true,++ CacheStrategy.IFFRESH,++ "robot_" + CrawlSwitchboard.CRAWL_PROFILE_SNIPPET_GLOBAL_MEDIA); // TODO: make this a default profile in CrawlSwitchboard+ sb.crawler.putActive(pe.handle().getBytes(), pe);+ return sb.crawlStacker.stackCrawl(new Request(+ sb.peers.mySeed().hash.getBytes(),+ startURL,+ null,+ "CRAWLING-ROOT",+ new Date(),+ pe.handle(), 0, 0, 0, 0+ ));+ }}diff --cc source/de/anomic/data/ymark/YMarkEntry.javaindex f5ee2397a,f44f25032..56e2b8682--- a/source/de/anomic/data/ymark/YMarkEntry.java+++ b/source/de/anomic/data/ymark/YMarkEntry.java@@@ -11,30 -43,25 +43,30 @@@ import de.anomic.crawler.CrawlProfilepublic class YMarkEntry extends TreeMap<String, String> {private static final long serialVersionUID = 2179622977348536148L;--++public static final YMarkEntry POISON = new YMarkEntry();+ public static final YMarkEntry EMPTY = new YMarkEntry();public static final String BOOKMARKS_ID = "id";public static final String BOOKMARKS_REF = "ref";public static final String FOLDERS_IMPORTED = "/imported";-+public static enum BOOKMARK {- // key dc_attrb dflt html_attrb xbel_attrb json_attrb type- URL ("url", "dc:identifier", "", "href", "href", "uri", "link"),- TITLE ("title", "dc:title", "", "", "", "title", "meta"),- DESC ("desc", "dc:description", "", "", "", "", "comment"),- DATE_ADDED ("date_added", "", "", "add_date", "added", "dateAdded", "date"),- DATE_MODIFIED ("date_modified", "", "", "last_modified", "modified", "lastModified", "date"),- DATE_VISITED ("date_visited", "", "", "last_visited", "visited", "", "date"),- PUBLIC ("public", "", "false", "private", "yacy:public", "", "lock"),- TAGS ("tags", "dc:subject", "unsorted", "shortcuturl", "yacy:tags", "keyword", "tag"),- VISITS ("visits", "", "0", "", "yacy:visits", "", "stat"),- FOLDERS ("folders", "", "/unsorted", "", "", "", "folder"),- FILTER ("filter", "", "", "", "yacy:filter", "", "filter"),- OAI ("oai", "", "", "", "yacy:oai", "", "oai"),- URLHASH ("urlhash", "", "", "", "yacy:urlhash", "", "urlhash"),- STARRATING ("starrating", "", "", "", "yacy:starrating", "", "stat");-+ // key dc_attrb dflt html_attrb xbel_attrb json_attrb type index separator+ URL ("url", "dc:identifier", "", "href", "href", "uri", "link", false, YMarkUtil.EMPTY_STRING),+ TITLE ("title", "dc:title", "", "", "", "title", "meta", false, YMarkUtil.EMPTY_STRING),+ DESC ("desc", "dc:description", "", "", "", "", "comment", false, YMarkUtil.EMPTY_STRING),+ DATE_ADDED ("date_added", "", "", "add_date", "added", "dateAdded", "date", false, YMarkUtil.EMPTY_STRING),+ DATE_MODIFIED ("date_modified", "", "", "last_modified", "modified", "lastModified", "date", false, YMarkUtil.EMPTY_STRING),+ DATE_VISITED ("date_visited", "", "", "last_visited", "visited", "", "date", false, YMarkUtil.EMPTY_STRING),+ PUBLIC ("public", "", "false", "private", "yacy:public", "", "lock", false, YMarkUtil.EMPTY_STRING),+ TAGS ("tags", "dc:subject", "unsorted", "shortcuturl", "yacy:tags", "keyword", "tag", true, YMarkUtil.TAGS_SEPARATOR),+ VISITS ("visits", "", "0", "", "yacy:visits", "", "stat", false, YMarkUtil.EMPTY_STRING),- FOLDERS ("folders", "", "/unsorted", "", "", "", "folder", true, YMarkUtil.TAGS_SEPARATOR);-++ FOLDERS ("folders", "", "/unsorted", "", "", "", "folder", true, YMarkUtil.TAGS_SEPARATOR),++ FILTER ("filter", "", "", "", "yacy:filter", "", "filter", false, YMarkUtil.EMPTY_STRING),++ OAI ("oai", "", "", "", "yacy:oai", "", "oai", false, YMarkUtil.EMPTY_STRING),++ URLHASH ("urlhash", "", "", "", "yacy:urlhash", "", "urlhash", false, YMarkUtil.EMPTY_STRING),++ STARRATING ("starrating", "", "", "", "yacy:starrating", "", "stat", false, YMarkUtil.EMPTY_STRING);++private String key;private String dc_attrb;private String dflt;@@@ -42,16 -69,23 +74,23 @@@private String xbel_attrb;private String json_attrb;private String type;-+ private boolean index;+ private String seperator;-++private static final Map<String,BOOKMARK> lookup = new HashMap<String,BOOKMARK>();+ private static final Map<String,String> indexColumns = new HashMap<String,String>();static {- for(BOOKMARK b : EnumSet.allOf(BOOKMARK.class))- lookup.put(b.key(), b);+ for(BOOKMARK b : EnumSet.allOf(BOOKMARK.class)) {+ lookup.put(b.key, b);+ if(b.index) {+ indexColumns.put(b.key, b.seperator);+ }- }++ }}--++private static StringBuilder buffer = new StringBuilder(25);--- private BOOKMARK(final String k, final String d, final String s, final String a, final String x, final String j, final String t) {+++ private BOOKMARK(final String k, final String d, final String s, final String a, final String x, final String j, final String t, final boolean index, final String separator) {this.key = k;this.dc_attrb = d;this.dflt = s;@@@ -59,16 -93,21 +98,21 @@@this.xbel_attrb = x;this.json_attrb = j;this.type = t;+ this.index = index;+ this.seperator = separator;+ }+ public static Map<String,String> indexColumns() {- return Collections.unmodifiableMap(indexColumns);++ return Collections.unmodifiableMap(indexColumns);}-- public static BOOKMARK get(String key) {-- return lookup.get(key);++ public static BOOKMARK get(String key) {++ return lookup.get(key);}public static boolean contains(String key) {return lookup.containsKey(key);}public String key() {return this.key;-- }++ }public String deflt() {return this.dflt;}@@@ -97,23 -136,31 +141,31 @@@public String type() {return this.type;}+ public boolean index() {+ return this.index;+ }+ public String seperator() {+ return this.seperator;+ }-++}-+public YMarkEntry() {this(true);}--++public YMarkEntry(final boolean setDefaults) {- super();+ super();if(setDefaults) {setCurrentTimeMillis(BOOKMARK.DATE_ADDED);setCurrentTimeMillis(BOOKMARK.DATE_MODIFIED);setDefaults();}-- }--++ }++public YMarkEntry(final DCEntry dc) {- for (BOOKMARK b : BOOKMARK.values()) {+ super();+ for (BOOKMARK b : BOOKMARK.values()) {if(dc.containsKey(b.dc_attrb)) {this.put(b.key(), dc.get(b.dc_attrb));}@@@ -122,15 -169,16 +174,16 @@@setCurrentTimeMillis(BOOKMARK.DATE_MODIFIED);setDefaults();}--++public YMarkEntry(final Tables.Row bmk_row) {- for (BOOKMARK b : BOOKMARK.values()) {+ super();+ for (BOOKMARK b : BOOKMARK.values()) {if(bmk_row.containsKey(b.key())) {this.put(b.key(), bmk_row.get(b.key(), b.deflt()));}}}--++private void setCurrentTimeMillis(BOOKMARK b) {switch(b) {case DATE_ADDED:@@@ -140,9 -188,9 +193,9 @@@break;default:break;-- }++ }}--++public void setDefaults() {for (BOOKMARK b : BOOKMARK.values()) {if(!b.deflt().isEmpty() && !this.containsKey(b.key())) {@@@ -150,7 -198,17 +203,17 @@@}}}--+++ public byte[] getUrlHash() {+ if(this.containsKey(YMarkEntry.BOOKMARK.URL.key()))+ try {+ return YMarkUtil.getBookmarkId(this.get(YMarkEntry.BOOKMARK.URL.key()));+ } catch (MalformedURLException e) {+ Log.logWarning(YMarkTables.BOOKMARKS_LOG, "getUrlHash - MalformedURLException for YMarkEntry: "+this.get(YMarkEntry.BOOKMARK.URL.key()));+ }+ return null;+ }-++public DCEntry getDCEntry() {final DCEntry dc = new DCEntry();for (BOOKMARK b : BOOKMARK.values()) {@@@ -160,7 -218,7 +223,7 @@@}return dc;}--++public Tables.Data getData() {final Tables.Data data = new Tables.Data();for (BOOKMARK b : BOOKMARK.values()) {@@@ -172,4 -230,21 +235,21 @@@}return data;}-+++ public void crawl(final YMarkCrawlStart.CRAWLSTART type, final boolean medialink, final Switchboard sb) throws MalformedURLException {+ final DigestURI url = new DigestURI(this.get(BOOKMARK.URL.key()));+ switch(type) {+ case SINGLE:+ YMarkCrawlStart.crawlStart(sb, url, CrawlProfile.MATCH_ALL_STRING, CrawlProfile.MATCH_NEVER_STRING, 0, true, medialink);+ break;+ case ONE_LINK:+ YMarkCrawlStart.crawlStart(sb, url, CrawlProfile.MATCH_ALL_STRING, CrawlProfile.MATCH_NEVER_STRING, 1, true, medialink);+ break;+ case FULL_DOMAIN:+ YMarkCrawlStart.crawlStart(sb, url, CrawlProfile.mustMatchFilterFullDomain(url), CrawlProfile.MATCH_NEVER_STRING, 99, false, medialink);+ break;+ default:- break;++ break;+ }+ }}diff --cc source/de/anomic/data/ymark/YMarkImporter.javaindex 000000000,3f5933b5e..7be319694mode 000000,100644..100644--- a/source/de/anomic/data/ymark/YMarkImporter.java+++ b/source/de/anomic/data/ymark/YMarkImporter.java@@@ -1,0 -1,157 +1,156 @@@+ // YMarkImporter.java+ // (C) 2012 by Stefan Foerster (apfelmaennchen), [email protected], Norderstedt, Germany+ // first published 2012 on http://yacy.net+ //+ // This is a part of YaCy, a peer-to-peer based web search engine+ //+ // LICENSE-//++//+ // 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++ package de.anomic.data.ymark;++ import java.io.IOException;+ import java.util.concurrent.ArrayBlockingQueue;+-import net.yacy.cora.util.SpaceExceededException;+ import net.yacy.kelondro.logging.Log;+ import net.yacy.search.Switchboard;++ public abstract class YMarkImporter implements Runnable {+ // Statics+ public final static String XML_NAMESPACE_PREFIXES = "http://xml.org/sax/features/namespace-prefixes";+ public final static String XML_NAMESPACES = "http://xml.org/sax/features/namespaces";+ public final static String XML_VALIDATION = "http://xml.org/sax/features/validation";-+++ protected String importer;+ protected ArrayBlockingQueue<YMarkEntry> bookmarks;+ protected final MonitoredReader bmk_file;+ protected final String targetFolder;+ protected final String sourceFolder;-+++ public YMarkImporter(final MonitoredReader bmk_file, final int queueSize, final String sourceFolder, final String targetFolder) {+ this.bookmarks = new ArrayBlockingQueue<YMarkEntry>(queueSize);+ this.bmk_file = bmk_file;+ this.sourceFolder = YMarkUtil.cleanFoldersString(sourceFolder);+ this.targetFolder = YMarkUtil.cleanFoldersString(targetFolder);- }-++ }++++ @Override+ public void run() {+ try {+ parse();+ } catch (Exception e) {+ Log.logException(e);+ } finally {+ try {+ Log.logInfo(YMarkTables.BOOKMARKS_LOG, this.importer+" Importer inserted poison pill in queue");+ this.bookmarks.put(YMarkEntry.POISON);+ } catch (InterruptedException e1) {+ Log.logException(e1);+ }+ }+ }-+++ public YMarkEntry take() {+ try {+ return this.bookmarks.take();+ } catch (InterruptedException e) {+ Log.logException(e);+ return null;+ }+ }-+++ public void setImporter(final String importer) {+ this.importer = importer;+ }-+++ public long getProgress() {+ return this.bmk_file.getProgress();+ }-+++ public long maxProgress() {+ return this.bmk_file.maxProgress();+ }-+++ public abstract void parse() throws Exception;+- public Consumer getConsumer(final Switchboard sb, final String bmk_user, final ArrayBlockingQueue<String> autoTaggingQueue,++ public Consumer getConsumer(final Switchboard sb, final String bmk_user, final ArrayBlockingQueue<String> autoTaggingQueue,+ final boolean autotag, final boolean empty, final String indexing, final boolean medialink) {+ return new Consumer(sb, bmk_user, autoTaggingQueue, autotag, empty, indexing, medialink);+ }-- public class Consumer implements Runnable {++++ public class Consumer implements Runnable {+ private final Switchboard sb;+ private final String bmk_user;+ private final ArrayBlockingQueue<String> autoTaggingQueue;+ private final String indexing;-+++ private final boolean autotag;+ private final boolean empty;+ private final boolean medialink;-- public Consumer(final Switchboard sb, final String bmk_user, final ArrayBlockingQueue<String> autoTaggingQueue,++++ public Consumer(final Switchboard sb, final String bmk_user, final ArrayBlockingQueue<String> autoTaggingQueue,+ final boolean autotag, final boolean empty, final String indexing, final boolean medialink) {+ this.sb = sb;+ this.bmk_user = bmk_user;+ this.autoTaggingQueue = autoTaggingQueue;+ this.autotag = autotag;+ this.empty = empty;+ this.indexing = indexing;- this.medialink = medialink;++ this.medialink = medialink;+ }-- public void run() {++++ @Override++ public void run() {+ YMarkEntry bmk;+ while ((bmk = take()) != YMarkEntry.POISON) {+ try {+ final String url = bmk.get(YMarkEntry.BOOKMARK.URL.key());+ // other protocols could cause problems+ if(url != null && url.startsWith("http")) {- sb.tables.bookmarks.addBookmark(bmk_user, bmk, true, true);- if(autotag) {- if(!empty) {- autoTaggingQueue.put(url);++ this.sb.tables.bookmarks.addBookmark(this.bmk_user, bmk, true, true);++ if(this.autotag) {++ if(!this.empty) {++ this.autoTaggingQueue.put(url);+ } else if(!bmk.containsKey(YMarkEntry.BOOKMARK.TAGS.key()) || bmk.get(YMarkEntry.BOOKMARK.TAGS.key()).equals(YMarkEntry.BOOKMARK.TAGS.deflt())) {- autoTaggingQueue.put(url);++ this.autoTaggingQueue.put(url);+ }- }++ }+ // fill crawler- if (indexing.equals("single")) {- bmk.crawl(YMarkCrawlStart.CRAWLSTART.SINGLE, medialink, sb);- } else if (indexing.equals("onelink")) {- bmk.crawl(YMarkCrawlStart.CRAWLSTART.ONE_LINK, medialink, sb);- } else if (indexing.equals("fulldomain")) {- bmk.crawl(YMarkCrawlStart.CRAWLSTART.FULL_DOMAIN, medialink, sb);++ if (this.indexing.equals("single")) {++ bmk.crawl(YMarkCrawlStart.CRAWLSTART.SINGLE, this.medialink, this.sb);++ } else if (this.indexing.equals("onelink")) {++ bmk.crawl(YMarkCrawlStart.CRAWLSTART.ONE_LINK, this.medialink, this.sb);++ } else if (this.indexing.equals("fulldomain")) {++ bmk.crawl(YMarkCrawlStart.CRAWLSTART.FULL_DOMAIN, this.medialink, this.sb);+ }+ }+ } catch (final IOException e) {+ Log.logException(e);+ } catch (final InterruptedException e) {+ Log.logException(e);- } catch (SpaceExceededException e) {- Log.logException(e);+ }+ }- if(autotag) {++ if(this.autotag) {+ try {- autoTaggingQueue.put(YMarkAutoTagger.POISON);- Log.logInfo(YMarkTables.BOOKMARKS_LOG, importer+" inserted poison pill into autoTagging queue");++ this.autoTaggingQueue.put(YMarkAutoTagger.POISON);++ Log.logInfo(YMarkTables.BOOKMARKS_LOG, YMarkImporter.this.importer+" inserted poison pill into autoTagging queue");+ } catch (final InterruptedException e) {+ Log.logException(e);+ }+ }+ }+ }+ }diff --cc source/de/anomic/data/ymark/YMarkTables.javaindex a9610dd20,704995310..bc32df779--- a/source/de/anomic/data/ymark/YMarkTables.java+++ b/source/de/anomic/data/ymark/YMarkTables.java@@@ -94,19 -98,58 +99,61 @@@ public class YMarkTablespublic final static int BUFFER_LENGTH = 256;private final WorkTables worktables;+ private final Map<String, ChangeListener> progressListeners;+ public boolean dirty = false;+public YMarkTables(final Tables wt) {this.worktables = (WorkTables)wt;- this.dirty = true;+ this.progressListeners = new ConcurrentHashMap<String, ChangeListener>();+ this.buildIndex();+ }-+++ public ChangeListener getProgressListener(String thread) {+ final ChangeListener l = new ProgressListener();+ this.progressListeners.put(thread, l);+ return l;+ }-+++ public void removeProgressListener(String thread) {+ this.progressListeners.remove(thread);+ }-+++ public class ProgressListener implements ChangeListener {+ // the progress in %+ private int progress = 0;- public void stateChanged(ChangeEvent e) {++ @Override++ public void stateChanged(ChangeEvent e) {+ final MonitoredReader mreader = (MonitoredReader)e.getSource();+ this.progress = (int)((mreader.getProgress() / mreader.maxProgress())*100);+ }+ public int progress() {+ return this.progress;+ }+ }-- public void buildIndex() {++++ public void buildIndex() {+ final Iterator<String> iter = this.worktables.iterator();+ while(iter.hasNext()) {+ final String bmk_table = iter.next();+ if(bmk_table.endsWith(TABLES.BOOKMARKS.basename())) {- try {++ try {+ final long time = System.currentTimeMillis();- final TablesColumnIndex index = this.worktables.getIndex(bmk_table);++ final TablesColumnIndex index = this.worktables.getIndex(bmk_table);+ if(index.getType() == TablesColumnIndex.INDEXTYPE.RAM || index.size() == 0) {+ Log.logInfo(YMarkTables.BOOKMARKS_LOG, "buildIndex() "+YMarkEntry.BOOKMARK.indexColumns().keySet().toString());+ index.buildIndex(YMarkEntry.BOOKMARK.indexColumns(), this.worktables.iterator(bmk_table));+ Log.logInfo(YMarkTables.BOOKMARKS_LOG, "build "+index.getType().name()+" index for columns "+YMarkEntry.BOOKMARK.indexColumns().keySet().toString()+ +" of table "+bmk_table+" containing "+this.worktables.size(bmk_table)+ " bookmarks"- +" ("+(System.currentTimeMillis()-time)+"ms)");- }++ +" ("+(System.currentTimeMillis()-time)+"ms)");++ }+ } catch (IOException e) {+ Log.logException(e);+ } catch (Exception e) {+ Log.logException(e);+ }+ }- }++ }}public void deleteBookmark(final String bmk_user, final byte[] urlHash) throws IOException, SpaceExceededException {@@@ -147,32 -197,65 +201,65 @@@public TreeMap<String, YMarkTag> getTags(final String bmk_user) throws IOException {final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user);- final TreeMap<String,YMarkTag> tags = getTags(this.worktables.iterator(bmk_table));- return tags;+ final TreeMap<String,YMarkTag> tags = new TreeMap<String,YMarkTag>();+ if(this.worktables.hasIndex(bmk_table, YMarkEntry.BOOKMARK.TAGS.key())) {+ try {+ final TablesColumnIndex index = this.worktables.getIndex(bmk_table);+ final Iterator<String> iter = index.keySet(YMarkEntry.BOOKMARK.TAGS.key()).iterator();+ while(iter.hasNext()) {+ final String tag = iter.next();+ tags.put(tag, new YMarkTag(tag, index.get(YMarkEntry.BOOKMARK.TAGS.key(), tag).size()));+ }+ return tags;+ } catch (Exception e) {+ // nothing to do+ }+ }+ return getTags(this.worktables.iterator(bmk_table));}-- public TreeSet<String> getFolders(final String bmk_user, final String root) throws IOException {- final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user);+ public TreeSet<String> getFolders(final String bmk_user, String root) throws IOException {final TreeSet<String> folders = new TreeSet<String>();- final StringBuilder path = new StringBuilder(200);- final StringBuffer patternBuilder = new StringBuffer(BUFFER_LENGTH);- patternBuilder.setLength(0);- patternBuilder.append(p1);- patternBuilder.append('(');- patternBuilder.append(root);- patternBuilder.append(p7);- patternBuilder.append(p8);- final Pattern r = Pattern.compile(patternBuilder.toString());- final Iterator<Tables.Row> bit = this.worktables.iterator(bmk_table, YMarkEntry.BOOKMARK.FOLDERS.key(), r);- Tables.Row bmk_row = null;+ final StringBuilder path = new StringBuilder(BUFFER_LENGTH);+ final String r = root + YMarkUtil.FOLDERS_SEPARATOR;- final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user);++ final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user);+ // if exists, try the index first- if(this.worktables.hasIndex(bmk_table, YMarkEntry.BOOKMARK.FOLDERS.key())) {++ if(this.worktables.hasIndex(bmk_table, YMarkEntry.BOOKMARK.FOLDERS.key())) {+ TablesColumnIndex index;+ try {+ index = this.worktables.getIndex(bmk_table);+ final Iterator<String> fiter = index.keySet(YMarkEntry.BOOKMARK.FOLDERS.key()).iterator();+ while(fiter.hasNext()) {+ final String folder = fiter.next();+ if(folder.startsWith(r)) {+ path.setLength(0);+ path.append(folder);+ while(path.length() > 0 && !path.toString().equals(root)){+ final String p = path.toString();+ if(folders.isEmpty() || !p.equals(folders.floor(p))) {+ folders.add(p);- }++ }+ path.setLength(path.lastIndexOf(YMarkUtil.FOLDERS_SEPARATOR));+ }+ }+ }+ if (!root.equals(YMarkTables.FOLDERS_ROOT)) { folders.add(root); }- return folders;++ return folders;+ } catch (Exception e) {+ Log.logException(e);+ }+ }-+++ // by default iterate all bookmarks and extract folder information- final Iterator<Tables.Row> bit = this.worktables.iterator(bmk_table);- Tables.Row bmk_row = null;++ final Iterator<Tables.Row> bit = this.worktables.iterator(bmk_table);++ Tables.Row bmk_row = null;while(bit.hasNext()) {bmk_row = bit.next();- if(bmk_row.containsKey(YMarkEntry.BOOKMARK.FOLDERS.key())) {+ if(bmk_row.containsKey(YMarkEntry.BOOKMARK.FOLDERS.key())) {final String[] folderArray = (new String(bmk_row.get(YMarkEntry.BOOKMARK.FOLDERS.key()),"UTF8")).split(YMarkUtil.TAGS_SEPARATOR);for (final String folder : folderArray) {- if(folder.length() > root.length() && folder.substring(0, root.length()+1).equals(root+'/')) {+ if(folder.length() > root.length() && folder.substring(0, root.length()+1).equals(r)) {if(!folders.contains(folder)) {path.setLength(0);path.append(folder);@@@ -184,52 -267,25 +271,25 @@@}}}- }+ }}- if (!root.equals(YMarkTables.FOLDERS_ROOT)) { folders.add(root); }- return folders;+ if (!root.equals(YMarkTables.FOLDERS_ROOT)) { folders.add(root); }- return folders;++ return folders;}-+- public Iterator<Tables.Row> getBookmarksByFolder(final String bmk_user, final String folder) throws IOException {+ public int getSize(final String bmk_user) throws IOException {final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user);- final StringBuilder patternBuilder = new StringBuilder(BUFFER_LENGTH);- patternBuilder.setLength(0);- patternBuilder.append(p1);- patternBuilder.append('(');- patternBuilder.append(Pattern.quote(folder));- patternBuilder.append(')');- patternBuilder.append(p4);- final Pattern p = Pattern.compile(patternBuilder.toString());- return this.worktables.iterator(bmk_table, YMarkEntry.BOOKMARK.FOLDERS.key(), p);+ return this.worktables.size(bmk_table);}- public Iterator<Tables.Row> getBookmarksByTag(final String bmk_user, final String[] tagArray) throws IOException {- final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user);- final StringBuilder patternBuilder = new StringBuilder(BUFFER_LENGTH);- patternBuilder.setLength(0);- patternBuilder.append(p1);- patternBuilder.append(p5);- for (final String tag : tagArray) {- patternBuilder.append(Pattern.quote(tag));- patternBuilder.append('|');- }- patternBuilder.deleteCharAt(patternBuilder.length()-1);- patternBuilder.append(p6);-- patternBuilder.append(tagArray.length);- patternBuilder.append('}');- final Pattern p = Pattern.compile(patternBuilder.toString(), Pattern.CASE_INSENSITIVE);- return this.worktables.iterator(bmk_table, YMarkEntry.BOOKMARK.TAGS.key(), p);+ public Iterator<Tables.Row> getBookmarksByFolder(final String bmk_user, final String foldersString) {- final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user);- return this.worktables.getByIndex(bmk_table, YMarkEntry.BOOKMARK.FOLDERS.key(), YMarkEntry.BOOKMARK.FOLDERS.seperator(), foldersString);++ final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user);++ return this.worktables.getByIndex(bmk_table, YMarkEntry.BOOKMARK.FOLDERS.key(), YMarkEntry.BOOKMARK.FOLDERS.seperator(), foldersString);}- public Iterator<Tables.Row> getBookmarksByTag(final String bmk_user, String regex) throws IOException {- final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user);- final StringBuilder patternBuilder = new StringBuilder(BUFFER_LENGTH);- patternBuilder.setLength(0);- patternBuilder.append(regex);-- final Pattern p = Pattern.compile(patternBuilder.toString(), Pattern.CASE_INSENSITIVE);- return this.worktables.iterator(bmk_table, YMarkEntry.BOOKMARK.TAGS.key(), p);+ public Iterator<Tables.Row> getBookmarksByTag(final String bmk_user, final String tagsString) {- final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user);- return this.worktables.getByIndex(bmk_table, YMarkEntry.BOOKMARK.TAGS.key(), YMarkEntry.BOOKMARK.TAGS.seperator(), tagsString);++ final String bmk_table = TABLES.BOOKMARKS.tablename(bmk_user);++ return this.worktables.getByIndex(bmk_table, YMarkEntry.BOOKMARK.TAGS.key(), YMarkEntry.BOOKMARK.TAGS.seperator(), tagsString);}public List<Row> orderBookmarksBy(final Iterator<Row> rowIterator, final String sortname, final String sortorder) {@@@ -270,12 -326,18 +331,19 @@@t.append(YMarkUtil.TAGS_SEPARATOR);t.append(replaceString);row.put(YMarkEntry.BOOKMARK.TAGS.key(), YMarkUtil.cleanTagsString(t.toString()));- this.worktables.update(TABLES.BOOKMARKS.tablename(bmk_user), row);+ this.worktables.update(bmk_table, row);+ if(this.worktables.hasIndex(bmk_table)) {+ try {+ this.worktables.getIndex(bmk_table).update(YMarkEntry.BOOKMARK.TAGS.key(), YMarkEntry.BOOKMARK.TAGS.seperator(), row);+ } catch (Exception e) {+ // nothing to do+ }+ }}+ this.dirty = true;}- public void addFolder(final String bmk_user, final String url, final String folder) throws IOException, SpaceExceededException {+ public void addFolder(final String bmk_user, final String url, final String folder) throws IOException {if(!folder.isEmpty()) {// do not set defaults as we only want to add a folderfinal YMarkEntry bmk = new YMarkEntry(false);@@@ -417,9 -476,13 +491,15 @@@}// update bmk_tablethis.worktables.update(bmk_table, bmk_row);+ try {+ if(this.worktables.hasIndex(bmk_table))+ this.worktables.getIndex(bmk_table).update(YMarkEntry.BOOKMARK.indexColumns(), bmk_row);+ } catch (Exception e) {+ // nothing to do+ }}++ this.dirty = true;}}}diff --cc source/net/yacy/interaction/contentcontrol/ContentControlFilterUpdateThread.javaindex 8509cb881,000000000..ee1fcd136mode 100644,000000..100644--- a/source/net/yacy/interaction/contentcontrol/ContentControlFilterUpdateThread.java+++ b/source/net/yacy/interaction/contentcontrol/ContentControlFilterUpdateThread.java@@@ -1,108 -1,0 +1,101 @@@+package net.yacy.interaction.contentcontrol;+- import java.io.IOException;+import java.util.Iterator;++import net.yacy.kelondro.blob.Tables;+import net.yacy.kelondro.blob.Tables.Row;+import net.yacy.repository.FilterEngine;+import net.yacy.search.Switchboard;++public class ContentControlFilterUpdateThread {++ private final Switchboard sb;++ private Boolean locked = false;++ private static FilterEngine networkfilter;++ public ContentControlFilterUpdateThread(final Switchboard sb) {+ //final long time = System.currentTimeMillis();+ this.sb = sb;++ if (this.sb.getConfigBool("contentcontrol.smwimport.purgelistoninit",+ false)) {+ this.sb.tables.clear(this.sb.getConfig(+ "contentcontrol.smwimport.targetlist", "contentcontrol"));++ }+ }++ public final void run() {++ if (!this.locked) {++ this.locked = true;++ if (this.sb.getConfigBool("contentcontrol.enabled", false) == true) {++ if (!this.sb+ .getConfig("contentcontrol.mandatoryfilterlist", "")+ .equals("")) {++ if (this.sb.tables.bookmarks.dirty) {++ networkfilter = updateFilter();++ this.sb.tables.bookmarks.dirty = false;++ }++ }++ }++ this.locked = false;++ }+++ return;+ }++ private static FilterEngine updateFilter () {++ FilterEngine newfilter = new FilterEngine();++ Switchboard sb = Switchboard.getSwitchboard();++ Iterator<Tables.Row> it;- try {- it = sb.tables.bookmarks.getBookmarksByTag(- sb.getConfig(- "contentcontrol.bookmarklist",- "contentcontrol"),- "^((?!sc:"- + sb- .getConfig(- "contentcontrol.mandatoryfilterlist",- "") + ").*)$");- while (it.hasNext()) {- Row b = it.next();-- if (!b.get("filter", "").equals("")) {-- newfilter.add(b.get("filter", ""), null);- }- }-- } catch (IOException e) {- // TODO Auto-generated catch block- e.printStackTrace();- }++ it = sb.tables.bookmarks.getBookmarksByTag(++ sb.getConfig(++ "contentcontrol.bookmarklist",++ "contentcontrol"),++ "^((?!sc:"++ + sb++ .getConfig(++ "contentcontrol.mandatoryfilterlist",++ "") + ").*)$");++ while (it.hasNext()) {++ Row b = it.next();++++ if (!b.get("filter", "").equals("")) {++++ newfilter.add(b.get("filter", ""), null);++ }++ }++ return newfilter;+ }+++ public static FilterEngine getNetworkFilter() {+ FilterEngine f = networkfilter;++ if (f != null && f.size() > 0)+ return f;++ return null;++ }++}