}
@Override
public boolean saveRegistration(String name, GitblitRegistration reg) {
try {
StoredConfig config = getConfig();
if (!StringUtils.isEmpty(name) && !name.equals(reg.name)) {
// delete old registration
registrations.remove(name);
config.unsetSection(SERVER, name);
}
// update registration
config.setString(SERVER, reg.name, "url", reg.url);
config.setString(SERVER, reg.name, "account", reg.account);
if (reg.savePassword) {
config.setString(SERVER, reg.name, "password",
Base64.encodeBytes(new String(reg.password).getBytes("UTF-8")));
} else {
config.setString(SERVER, reg.name, "password", "");
}
if (reg.lastLogin != null) {
config.setString(SERVER, reg.name, "lastLogin", dateFormat.format(reg.lastLogin));
}
// serialize the feed definitions
List<String> definitions = new ArrayList<String>();
for (FeedModel feed : reg.feeds) {
definitions.add(feed.toString());
}
if (definitions.size() > 0) {
config.setStringList(SERVER, reg.name, FEED, definitions);
}
config.save();
return true;
} catch (Throwable t) {
Utils.showException(GitblitManager.this, t);
}
return false;