|
|
|
@ -2,15 +2,22 @@ import java.io.ByteArrayInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
|
|
|
|
|
|
import net.yacy.cora.protocol.RequestHeader;
|
|
|
|
|
import net.yacy.document.Document;
|
|
|
|
|
import net.yacy.document.Parser.Failure;
|
|
|
|
|
import net.yacy.kelondro.data.meta.DigestURI;
|
|
|
|
|
import net.yacy.kelondro.index.RowSpaceExceededException;
|
|
|
|
|
import net.yacy.kelondro.logging.Log;
|
|
|
|
|
|
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
|
|
|
|
|
|
import de.anomic.crawler.CrawlProfile;
|
|
|
|
|
import de.anomic.crawler.retrieval.Response;
|
|
|
|
|
import de.anomic.data.UserDB;
|
|
|
|
|
import de.anomic.data.YMarkTables;
|
|
|
|
|
import de.anomic.data.YMarksHTMLImporter;
|
|
|
|
|
import de.anomic.data.YMarksXBELImporter;
|
|
|
|
|
import de.anomic.data.UserDB;
|
|
|
|
|
import de.anomic.search.Switchboard;
|
|
|
|
|
import de.anomic.server.serverObjects;
|
|
|
|
|
import de.anomic.server.serverSwitch;
|
|
|
|
@ -48,17 +55,7 @@ public class import_ymark {
|
|
|
|
|
t = new Thread(htmlImporter, "YMarks - HTML Importer");
|
|
|
|
|
t.start();
|
|
|
|
|
while ((bmk = htmlImporter.take()) != YMarkTables.POISON) {
|
|
|
|
|
try {
|
|
|
|
|
sb.tables.bookmarks.addBookmark(bmk_user, bmk, true);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
Log.logWarning(YMarkTables.BOOKMARKS_LOG.toString(), "HTML Importer - IOException for URL: "+bmk.get(YMarkTables.BOOKMARK.URL.key()));
|
|
|
|
|
continue;
|
|
|
|
|
} catch (RowSpaceExceededException e) {
|
|
|
|
|
//TODO: display an error message
|
|
|
|
|
Log.logException(e);
|
|
|
|
|
prop.put("result", "0");
|
|
|
|
|
return prop;
|
|
|
|
|
}
|
|
|
|
|
putBookmark(sb, bmk_user, bmk);
|
|
|
|
|
}
|
|
|
|
|
prop.put("result", "1");
|
|
|
|
|
} else if(post.get("importer").equals("xbel") && byteIn != null) {
|
|
|
|
@ -75,17 +72,7 @@ public class import_ymark {
|
|
|
|
|
t = new Thread(xbelImporter, "YMarks - XBEL Importer");
|
|
|
|
|
t.start();
|
|
|
|
|
while ((bmk = xbelImporter.take()) != YMarkTables.POISON) {
|
|
|
|
|
try {
|
|
|
|
|
sb.tables.bookmarks.addBookmark(bmk_user, bmk, true);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
Log.logWarning(YMarkTables.BOOKMARKS_LOG.toString(), "XBEL Importer - IOException for URL: "+bmk.get(YMarkTables.BOOKMARK.URL.key()));
|
|
|
|
|
continue;
|
|
|
|
|
} catch (RowSpaceExceededException e) {
|
|
|
|
|
//TODO: display an error message
|
|
|
|
|
Log.logException(e);
|
|
|
|
|
prop.put("result", "0");
|
|
|
|
|
return prop;
|
|
|
|
|
}
|
|
|
|
|
putBookmark(sb, bmk_user, bmk);
|
|
|
|
|
}
|
|
|
|
|
prop.put("result", "1");
|
|
|
|
|
}
|
|
|
|
@ -100,6 +87,26 @@ public class import_ymark {
|
|
|
|
|
// return rewrite properties
|
|
|
|
|
return prop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void putBookmark(final Switchboard sb, final String bmk_user, final HashMap<String, String> bmk) {
|
|
|
|
|
try {
|
|
|
|
|
if(!bmk.containsKey(YMarkTables.BOOKMARK.TAGS.key()) || bmk.get(YMarkTables.BOOKMARK.TAGS.key()).equals(YMarkTables.BOOKMARK.TAGS.deflt())) {
|
|
|
|
|
final DigestURI u = new DigestURI(bmk.get(YMarkTables.BOOKMARK.URL.key()));
|
|
|
|
|
Response response = sb.loader.load(sb.loader.request(u, true, false), CrawlProfile.CacheStrategy.IFEXIST, Long.MAX_VALUE);
|
|
|
|
|
final Document document = Document.mergeDocuments(response.url(), response.getMimeType(), response.parse());
|
|
|
|
|
if(document != null) {
|
|
|
|
|
bmk.put(YMarkTables.BOOKMARK.TAGS.key(), sb.tables.bookmarks.autoTag(document, bmk_user, 3));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sb.tables.bookmarks.addBookmark(bmk_user, bmk, true);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
Log.logWarning(YMarkTables.BOOKMARKS_LOG.toString(), "Importer - IOException for URL: "+bmk.get(YMarkTables.BOOKMARK.URL.key()));
|
|
|
|
|
} catch (RowSpaceExceededException e) {
|
|
|
|
|
Log.logException(e);
|
|
|
|
|
} catch (Failure e) {
|
|
|
|
|
Log.logWarning(YMarkTables.BOOKMARKS_LOG.toString(), "Importer - Failure for URL: "+bmk.get(YMarkTables.BOOKMARK.URL.key()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|