added default configuration in ConfigurationSet in case of new values

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7814 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
orbiter 2011-07-02 00:09:49 +00:00
parent 7bf39c8bcf
commit 892caccdca
2 changed files with 59 additions and 1 deletions

View File

@ -569,7 +569,7 @@ public final class Switchboard extends serverSwitch {
// update the working scheme with the backup scheme. This is necessary to include new features.
// new features are always activated by default
workingScheme.fill(backupScheme);
// set up the solr interface
final String solrurls = getConfig("federated.service.solr.indexing.url", "http://127.0.0.1:8983/solr");

View File

@ -72,6 +72,64 @@ public class ConfigurationSet extends AbstractSet<String> implements Set<String>
}
}
public boolean containsDisabled(final String o) {
if (o == null) return false;
final Iterator<Entry> i = new EntryIterator();
Entry e;
while (i.hasNext()) {
e = i.next();
if (!e.enabled() && o.equals(e.key)) return true;
}
return false;
}
@Override
public boolean add(final String key) {
return add(key, null);
}
public boolean add(final String key, final String comment) {
return add(key, comment, true);
}
public boolean add(final String key, final String comment, final boolean enabled) {
if (contains(key)) {
try {
if (!enabled) disable(key);
} catch (final IOException e) {
}
return true;
}
if (containsDisabled(key)) {
try {
if (enabled) enable(key);
} catch (final IOException e) {
}
return false;
}
// extend the lines
final String[] l = new String[this.lines.length + (comment == null ? 2 : 3)];
System.arraycopy(this.lines, 0, l, 0, this.lines.length);
l[this.lines.length] = "";
if (comment != null) l[this.lines.length + 1] = "## " + comment;
l[this.lines.length + (comment == null ? 1 : 2)] = enabled ? key : "#" + key;
this.lines = l;
try {
commit();
} catch (final IOException e) {
}
return false;
}
public void fill(final ConfigurationSet other) {
final Iterator<Entry> i = other.allIterator();
Entry e;
while (i.hasNext()) {
e = i.next();
if (contains(e.key) || containsDisabled(e.key)) continue;
this.add(e.key(), other.commentHeadline(e.key()), e.enabled());
}
}
@Override
public boolean isEmpty() {