Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

*) first and very limited version of XML import, does not use benefits provided by XML yet

low0120c8fd811dc39
diff --git a/htroot/BlacklistImpExp_p.html b/htroot/BlacklistImpExp_p.html
index 97f3058cd..7b45468ea 100644
--- a/htroot/BlacklistImpExp_p.html
+++ b/htroot/BlacklistImpExp_p.html
@@ -48,6 +48,18 @@
<input type="submit" value="Load new blacklist items" />
</fieldset>
</form>
+
+ <!-- blacklist import from xml file -->
+ <form action="sharedBlacklist_p.html" method="post" enctype="multipart/form-data">
+ <fieldset>
+ <legend>XML file:</legend>
+ Upload an XML file which contains one or more blacklists.<br /><br />
+ <input type="hidden" name="currentBlacklist" value="#[currentBlacklist]#" />
+ <input type="hidden" name="type" value="xml" />
+ <input type="file" name="file" />
+ <input type="submit" value="Load new blacklist items" />
+ </fieldset>
+ </form>
</fieldset>::#(/disabled)#
<fieldset class="exportListItems">
diff --git a/htroot/sharedBlacklist_p.html b/htroot/sharedBlacklist_p.html
index f56f6caa8..c01984116 100644
--- a/htroot/sharedBlacklist_p.html
+++ b/htroot/sharedBlacklist_p.html
@@ -46,9 +46,11 @@
::
<!-- [5] -->
Wrong Invocation! Please invoke with sharedBlacklist.html?name=PeerName
+::
+ <!-- [6] -->
+ Parse Error! An error occured while parsing XML data. Please check if the XML is valid.
#(/status)#
</p>
-
<form action="sharedBlacklist_p.html" method="post" enctype="multipart/form-data">
<input type="hidden" name="num" value="#[num]#" />
#(page)#<!-- [0] -->
diff --git a/htroot/sharedBlacklist_p.java b/htroot/sharedBlacklist_p.java
index 7e474b4ec..5664290b3 100644
--- a/htroot/sharedBlacklist_p.java
+++ b/htroot/sharedBlacklist_p.java
@@ -33,6 +33,7 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
+import java.io.StringReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -40,6 +41,8 @@ import java.util.List;
import de.anomic.crawler.HTTPLoader;
import de.anomic.data.AbstractBlacklist;
import de.anomic.data.listManager;
+import de.anomic.data.list.ListAccumulator;
+import de.anomic.data.list.XMLBlacklistImporter;
import de.anomic.htmlFilter.htmlFilterCharacterCoding;
import de.anomic.http.httpClient;
import de.anomic.http.httpRequestHeader;
@@ -49,6 +52,8 @@ import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
import de.anomic.yacy.yacySeed;
import de.anomic.yacy.yacyURL;
+import java.util.Map;
+import org.xml.sax.SAXException;
public class sharedBlacklist_p {
@@ -58,6 +63,7 @@ public class sharedBlacklist_p {
public static final int STATUS_PEER_UNKNOWN = 3;
public static final int STATUS_URL_PROBLEM = 4;
public static final int STATUS_WRONG_INVOCATION = 5;
+ public static final int STATUS_PARSE_ERROR = 6;
private final static String BLACKLIST_FILENAME_FILTER = "^.*\\.black$";
@@ -99,6 +105,8 @@ public class sharedBlacklist_p {
prop.put("page_blackLists", blacklistCount);
List<String> otherBlacklist = null;
+ ListAccumulator otherBlacklists = null;
+
if (post.containsKey("hash")) {
/* ======================================================
* Import blacklist from other peer
@@ -165,22 +173,42 @@ public class sharedBlacklist_p {
prop.put("page", "1");
}
} else if (post.containsKey("file")) {
- /* ======================================================
- * Import the blacklist from file
- * ====================================================== */
- final String sourceFileName = post.get("file");
- prop.putHTML("page_source", sourceFileName);
-
- final String fileString = post.get("file$file");
- if (fileString != null) {
- try {
- otherBlacklist = FileUtils.strings(fileString.getBytes("UTF-8"), "UTF-8");
- } catch (IOException ex) {
- prop.put("status", STATUS_FILE_ERROR);
+ if (post.containsKey("type") && post.get("type").equalsIgnoreCase("xml")) {
+ /* ======================================================
+ * Import the blacklist from XML file
+ * ====================================================== */
+ final String sourceFileName = post.get("file");
+ prop.putHTML("page_source", sourceFileName);
+
+ final String fileString = post.get("file$file");
+
+ if (fileString != null) {
+ try {
+ otherBlacklists = new XMLBlacklistImporter().parse(new StringReader(fileString));
+ } catch (IOException ex) {
+ prop.put("status", STATUS_FILE_ERROR);
+ } catch (SAXException ex) {
+ prop.put("status", STATUS_PARSE_ERROR);
+ }
+ }
+ } else {
+ /* ======================================================
+ * Import the blacklist from text file
+ * ====================================================== */
+ final String sourceFileName = post.get("file");
+ prop.putHTML("page_source", sourceFileName);
+
+ final String fileString = post.get("file$file");
+
+ if (fileString != null) {
+ try {
+ otherBlacklist = FileUtils.strings(fileString.getBytes("UTF-8"), "UTF-8");
+ } catch (IOException ex) {
+ prop.put("status", STATUS_FILE_ERROR);
+ }
}
}
-
} else if (post.containsKey("add")) {
/* ======================================================
* Add loaded items into blacklist file
@@ -268,12 +296,40 @@ public class sharedBlacklist_p {
prop.put("page_urllist", (count));
prop.put("num", count);
prop.put("page", "0");
+
+ } else if (otherBlacklists != null) {
+ List<List<String>> entries = otherBlacklists.getEntryLists();
+ //List<Map<String,String>> properties = otherBlacklists.getPropertyMaps();
+ int count = 0;
+
+ for(List<String> list : entries) {
+
+ // sort the loaded blacklist
+ final String[] sortedlist = list.toArray(new String[list.size()]);
+ Arrays.sort(sortedlist);
+
+ for(int i = 0; i < sortedlist.length; i++){
+ final String tmp = sortedlist[i];
+ if(!tmp.equals("")){
+ //newBlacklist.add(tmp);
+ prop.put("page_urllist_" + count + "_dark", count % 2 == 0 ? "0" : "1");
+ prop.putHTML("page_urllist_" + count + "_url", tmp);
+ prop.put("page_urllist_" + count + "_count", count);
+ count++;
+ }
+ }
+
+ }
+
+ prop.put("page_urllist", (count));
+ prop.put("num", count);
+ prop.put("page", "0");
+
}
-
} else {
prop.put("page", "1");
- prop.put("status", "5");//Wrong Invokation
+ prop.put("status", "5");//Wrong Invocation
}
return prop;
}