forked from I2P_Developers/i2p.i2p
* Router: Clean up config map methods and uses
This commit is contained in:
@ -1,11 +1,13 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
|
||||
/**
|
||||
* Handler to deal with form submissions from the advanced config form and act
|
||||
@ -39,28 +41,26 @@ public class ConfigAdvancedHandler extends FormHandler {
|
||||
*
|
||||
*/
|
||||
private void saveChanges() {
|
||||
HashSet unsetKeys = new HashSet(_context.router().getConfigMap().keySet());
|
||||
Set<String> unsetKeys = new HashSet(_context.router().getConfigSettings());
|
||||
if (_config != null) {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(_config.getBytes())));
|
||||
String line = null;
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
while ( (line = reader.readLine()) != null) {
|
||||
int eq = line.indexOf('=');
|
||||
if (eq == -1) continue;
|
||||
if (eq >= line.length() - 1) continue;
|
||||
String key = line.substring(0, eq).trim();
|
||||
String val = line.substring(eq + 1).trim();
|
||||
_context.router().setConfigSetting(key, val);
|
||||
unsetKeys.remove(key);
|
||||
}
|
||||
DataHelper.loadProps(props, new ByteArrayInputStream(_config.getBytes()));
|
||||
} catch (IOException ioe) {
|
||||
_log.error("Config error", ioe);
|
||||
addFormError(ioe.toString());
|
||||
addFormError(_("Error updating the configuration - please see the error logs"));
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator cleaner = unsetKeys.iterator();
|
||||
while (cleaner.hasNext()) {
|
||||
String unsetKey = (String)cleaner.next();
|
||||
for (Map.Entry e : props.entrySet()) {
|
||||
String key = (String) e.getKey();
|
||||
String val = (String) e.getValue();
|
||||
_context.router().setConfigSetting(key, val);
|
||||
unsetKeys.remove(key);
|
||||
}
|
||||
|
||||
for (String unsetKey : unsetKeys) {
|
||||
_context.router().removeConfigSetting(unsetKey);
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
package net.i2p.router.web;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
||||
public class ConfigAdvancedHelper extends HelperBase {
|
||||
@ -10,11 +9,11 @@ public class ConfigAdvancedHelper extends HelperBase {
|
||||
|
||||
public String getSettings() {
|
||||
StringBuilder buf = new StringBuilder(4*1024);
|
||||
Set names = _context.router().getConfigSettings();
|
||||
TreeSet sortedNames = new TreeSet(names);
|
||||
for (Iterator iter = sortedNames.iterator(); iter.hasNext(); ) {
|
||||
String name = (String)iter.next();
|
||||
String val = _context.router().getConfigSetting(name);
|
||||
TreeMap<String, String> sorted = new TreeMap();
|
||||
sorted.putAll(_context.router().getConfigMap());
|
||||
for (Map.Entry<String, String> e : sorted.entrySet()) {
|
||||
String name = e.getKey();
|
||||
String val = e.getValue();
|
||||
buf.append(name).append('=').append(val).append('\n');
|
||||
}
|
||||
return buf.toString();
|
||||
|
Reference in New Issue
Block a user