Commit 42223153 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Working on options update functionality.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@6349 b35dd754-fafc-0310-a699-88a17e54d16e
parent c0ca37c7
......@@ -13,6 +13,12 @@ package org.jivesoftware.wildfire.gateway.web;
import org.jivesoftware.wildfire.container.PluginManager;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.gateway.GatewayPlugin;
import org.jivesoftware.wildfire.gateway.TransportType;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.JiveGlobals;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Attribute;
/**
* Transport Instance Manager
......@@ -42,5 +48,84 @@ public class TransportInstanceManager {
return false;
}
}
/**
* Saves settings from options screen.
*
* @param transportName Name of the transport to have it's options saved (type of transport)
* @param options Options passed from options form.
*/
public void saveSettings(String transportName, TransportOptions options) {
PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
GatewayPlugin plugin = (GatewayPlugin)pluginManager.getPlugin("gateway");
Document optConfig = plugin.getOptionsConfig(TransportType.valueOf(transportName));
Element leftPanel = optConfig.getRootElement().element("leftpanel");
if (leftPanel != null && leftPanel.nodeCount() > 0) {
for (Object nodeObj : leftPanel.elements("item")) {
Element node = (Element)nodeObj;
saveOptionSetting(node, options);
}
}
Element rightPanel = optConfig.getRootElement().element("rightpanel");
if (rightPanel != null && rightPanel.nodeCount() > 0) {
for (Object nodeObj : rightPanel.elements("item")) {
Element node = (Element)nodeObj;
saveOptionSetting(node, options);
}
}
}
/**
* Helper function designed to handle saving option types.
*
* @param node Node describing the configuration item.
* @param options Options passed from form.
*/
private void saveOptionSetting(Element node, TransportOptions options) {
Attribute type = node.attribute("type");
if (type.getText().equals("text")) {
// Required fields
Attribute desc = node.attribute("desc");
Attribute var = node.attribute("var");
Attribute sysprop = node.attribute("sysprop");
if (desc == null || var == null || sysprop == null) {
Log.error("Missing variable from options config.");
return;
}
// Process any variables that we are setting.
if (var.getText().equals("host")) {
JiveGlobals.setProperty(sysprop.getText(), options.host);
}
else if (var.getText().equals("port")) {
JiveGlobals.setProperty(sysprop.getText(), options.port);
}
else if (var.getText().equals("encoding")) {
JiveGlobals.setProperty(sysprop.getText(), options.encoding);
}
}
else if (type.getText().equals("toggle")) {
// Required fields
Attribute desc = node.attribute("desc");
Attribute var = node.attribute("var");
Attribute sysprop = node.attribute("sysprop");
if (desc == null || var == null || sysprop == null) {
Log.error("Missing variable from options config.");
return;
}
// Process any variables that we are setting.
// None yet.
for (Object itemObj : node.elements("item")) {
Element item = (Element)itemObj;
saveOptionSetting(item, options);
}
}
}
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.gateway.web;
/**
* List of all possible options used by the admin options interface for any particular transport.
*
* @author Daniel Henninger
*/
public class TransportOptions {
public String host;
public String port;
public String encoding;
}
<?xml version="1.0" encoding="UTF-8"?>
<optionsconfig>
<leftpanel>
<item type="toggle" sysprop="plugin.gateway.aim.filetransfer" var="filetransfer" desc="File Transfer Enabled"/>
<item type="toggle" sysprop="plugin.gateway.aim.reconnect" var="reconnect" desc="Reconnect Automatically">
<item type="text" sysprop="plugin.gateway.aim.reconnectattempts" var="reconnectattempts" desc="Attempts" size="4" maxlength="4"/>
</item>
</leftpanel>
<leftpanel></leftpanel>
<rightpanel>
<item type="text" sysprop="plugin.gateway.aim.connecthost" var="host" desc="Host" default="login.oscar.aol.com"/>
<item type="text" sysprop="plugin.gateway.aim.connectport" var="port" desc="Port" default="5190"/>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment