* fix StringIndexOutOfBoundException in WebStructureGraph

* add better escaping to saveMap and loadMap

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7458 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
f1ori 14 years ago
parent 77715c2b16
commit 982aa689ef

@ -480,7 +480,7 @@ public final class Switchboard extends serverSwitch {
// define a realtime parsable mimetype list
log.logConfig("Parser: Initializing Mime Type deny list");
TextParser.setDenyMime(getConfig(SwitchboardConstants.PARSER_MIME_DENY, null));
TextParser.setDenyMime(getConfig(SwitchboardConstants.PARSER_MIME_DENY, ""));
// start a loader
log.logConfig("Starting Crawl Loader");

@ -77,7 +77,7 @@ public class WebStructureGraph {
for (final Map.Entry<String, String> entry : this.structure_old.entrySet()) {
key = entry.getKey();
value = entry.getValue();
delset.add(value.substring(0, 8) + key);
if (value.length() >= 8) delset.add(value.substring(0, 8) + key);
}
int delcount = this.structure_old.size() - (maxhosts * 9 / 10);
final Iterator<String> j = delset.iterator();

@ -412,10 +412,12 @@ public final class FileUtils {
String key, value;
for (final Map.Entry<String, String> entry: props.entrySet()) {
key = entry.getKey();
if (key != null)
key = key.replace("\\", "\\\\").replace("\n", "\\n").replace("=", "\\=");
if (entry.getValue() == null) {
value = "";
} else {
value = entry.getValue().replaceAll("\n", "\\\\n");
value = entry.getValue().replace("\\", "\\\\").replace("\n", "\\n");
}
pw.println(key + "=" + value);
}
@ -505,13 +507,21 @@ public final class FileUtils {
}
public static Map<String, String> table(Iterator<String> li) {
int pos;
String line;
final HashMap<String, String> props = new HashMap<String, String>();
while (li.hasNext()) {
line = li.next();
pos = line.indexOf('=');
if (pos > 0) props.put(line.substring(0, pos).trim(), line.substring(pos + 1).trim());
int pos = 0;
line = li.next().trim();
if (line.length() > 0 && line.charAt(0) == '#') continue; // exclude comments
do {
// search for unescaped =
pos = line.indexOf('=', pos+1);
} while ( pos > 0 && line.charAt(pos-1) == '\\');
if (pos > 0) {
String key = line.substring(0, pos).trim().replace("\\=", "=").replace("\\n", "\n").replace("\\", "\\");
String value = line.substring(pos + 1).trim().replace("\\n", "\n").replace("\\\\", "\\");
props.put(key, value);
}
}
return props;
}
@ -519,34 +529,6 @@ public final class FileUtils {
public static Map<String, String> table(final byte[] a) {
return table(strings(a));
}
/**
* parse config files
*
* splits the lines in list into pairs sperarated by =, lines beginning with # are ignored
* ie:
* abc=123
* # comment
* fg=dcf
* => Map{abc => 123, fg => dcf}
* @param list
* @return
*/
public static Map<String, String> table(final ArrayList<String> list) {
if (list == null) return new HashMap<String, String>();
final Iterator<String> i = list.iterator();
int pos;
String line;
final HashMap<String, String> props = new HashMap<String, String>(list.size());
while (i.hasNext()) {
line = i.next().trim();
if (line.length() > 0 && line.charAt(0) == '#') continue; // exclude comments
//System.out.println("NXTOOLS_PROPS - LINE:" + line);
pos = line.indexOf('=');
if (pos > 0) props.put(line.substring(0, pos).trim(), line.substring(pos + 1).trim());
}
return props;
}
public static Iterator<String> strings(byte[] a) {
if (a == null) return new ArrayList<String>().iterator();

Loading…
Cancel
Save