From e0decf4653d02391728284c85b834f8ef0cb67a5 Mon Sep 17 00:00:00 2001 From: karlchenofhell Date: Sun, 25 Feb 2007 19:36:05 +0000 Subject: [PATCH] - added support for changing invalid entries in blacklist cleaner git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3397 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/BlacklistCleaner_p.html | 9 ++-- htroot/BlacklistCleaner_p.java | 76 +++++++++++++++++++++++++++++----- 2 files changed, 70 insertions(+), 15 deletions(-) diff --git a/htroot/BlacklistCleaner_p.html b/htroot/BlacklistCleaner_p.html index df8d933ca..961693fac 100644 --- a/htroot/BlacklistCleaner_p.html +++ b/htroot/BlacklistCleaner_p.html @@ -46,10 +46,11 @@ -
- #{/entries}# -
- +
#{/entries}# +
 
+
+ +
::#(/disabled)# :: diff --git a/htroot/BlacklistCleaner_p.java b/htroot/BlacklistCleaner_p.java index f7f4a7b52..c55513c34 100644 --- a/htroot/BlacklistCleaner_p.java +++ b/htroot/BlacklistCleaner_p.java @@ -49,10 +49,14 @@ // if the shell's current path is HTROOT import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.Map.Entry; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -63,6 +67,7 @@ import de.anomic.plasma.urlPattern.defaultURLPattern; import de.anomic.plasma.urlPattern.plasmaURLPattern; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; +import de.anomic.server.logging.serverLog; public class BlacklistCleaner_p { @@ -109,10 +114,10 @@ public class BlacklistCleaner_p { if (post.containsKey("delete")) { prop.put(RESULTS + "modified", 1); - prop.put(RESULTS + "modified_delCount", removeEntries(blacklistToUse, supportedBlacklistTypes, getByPrefix(post, "select"))); + prop.put(RESULTS + "modified_delCount", removeEntries(blacklistToUse, supportedBlacklistTypes, getByPrefix(post, "select", true))); } else if (post.containsKey("alter")) { prop.put(RESULTS + "modified", 2); - prop.put(RESULTS + "modified_alterCount", alterEntries(blacklistToUse, supportedBlacklistTypes, getByPrefix(post, "select"), getByPrefix(post, "entry"))); + prop.put(RESULTS + "modified_alterCount", alterEntries(blacklistToUse, supportedBlacklistTypes, getByPrefix(post, "select", true), getByPrefix(post, "entry", false))); } // list illegal entries @@ -150,14 +155,25 @@ public class BlacklistCleaner_p { } } - private static String[] getByPrefix(serverObjects post, String prefix) { + private static String[] getByPrefix(serverObjects post, String prefix, boolean useKeys) { ArrayList r = new ArrayList(); - Iterator it = post.keySet().iterator(); - Object o; - while (it.hasNext()) - if (((String)(o = it.next())).indexOf(prefix) == 0) - r.add(((String)o).substring(prefix.length())); - + Iterator it; + String s; + if (useKeys) { + it = post.keySet().iterator(); + while (it.hasNext()) + if ((s = (String)it.next()).indexOf(prefix) == 0) + r.add(s.substring(prefix.length())); + } else { + it = post.entrySet().iterator(); + Entry entry; + while (it.hasNext()) { + entry = (Entry)it.next(); + if (((String)entry.getKey()).indexOf(prefix) == 0) + r.add(entry.getValue()); + } + } + System.err.println("for " + prefix + "(" + useKeys + "): " + r.size()); return (String[])r.toArray(new String[r.size()]); } @@ -255,10 +271,46 @@ public class BlacklistCleaner_p { } } if (list != null) listManager.writeList(new File(listManager.listsPath, blacklistToUse), (String[])list.toArray(new String[list.size()])); - return entries.length; } + private static int alterEntries( + String blacklistToUse, + String[] supportedBlacklistTypes, + String[] oldE, + String[] newE) { + removeEntries(blacklistToUse, supportedBlacklistTypes, oldE); + PrintWriter pw = null; + try { + pw = new PrintWriter(new FileWriter(new File(listManager.listsPath, blacklistToUse), true)); + String host, path; + for (int i=0, pos; i