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
......@@ -43,4 +49,83 @@ public class TransportInstanceManager {
}
}
/**
* 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"/>
......
......@@ -26,8 +26,7 @@
JspWriter out = null;
Integer jsID = 0; // Javascript incrementable id
GatewaySettings(JspWriter out, GatewayPlugin plugin, TransportType gatewayType,
String desc) {
GatewaySettings(JspWriter out, GatewayPlugin plugin, TransportType gatewayType, String desc) {
this.description = desc;
this.gatewayType = gatewayType;
this.gwEnabled = plugin.serviceEnabled(gatewayType.toString());
......@@ -111,7 +110,6 @@
void printSettingsDialog() {
try {
Document optConfig = plugin.getOptionsConfig(gatewayType);
Log.debug("Options config is " + optConfig.asXML());
Element leftPanel = optConfig.getRootElement().element("leftpanel");
Element rightPanel = optConfig.getRootElement().element("rightpanel");
%>
......@@ -129,18 +127,20 @@
<a href="#" onclick="togglePanel(jive<%= this.gatewayType.toString().toUpperCase() %>perms); return false" id="jive<%= this.gatewayType.toString().toUpperCase() %>permsLink" <%= ((!this.gwEnabled) ? "style='display:none'" : "") %>>Permissions</a>
</div>
</div>
<!-- Tests Window -->
<div class="jive-gatewayPanel" id="jive<%= this.gatewayType.toString().toUpperCase() %>tests" style="display: none;">
<div>
<span style="font-weight: bold">Connect to host:</span> <span id="testhost">ninja</span><br />
<span style="font-weight: bold">Connect to port:</span> <span id="testport">1234</span><br />
<form action="">
<form id="jive<%= this.gatewayType.toString().toUpperCase() %>testsform" action="">
<span style="font-weight: bold">Connect to host:</span> <span id="testhost">[reading]</span><br />
<span style="font-weight: bold">Connect to port:</span> <span id="testport">[reading]</span><br />
<input type="submit" name="submit" value="Test Connection" onclick="togglePanel(jive<%= this.gatewayType.toString().toUpperCase() %>tests,jive<%= this.gatewayType.toString().toUpperCase() %>tests); return false" class="jive-formButton">
</form>
</div>
</div>
<!-- Options Window -->
<div class="jive-gatewayPanel" id="jive<%= this.gatewayType.toString().toUpperCase() %>options" style="display: none;">
<div>
<form action="">
<form id="jive<%= this.gatewayType.toString().toUpperCase() %>optionsform" action="">
<table border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<td align="left" width="50%">
......@@ -175,14 +175,15 @@
</td>
</tr>
</table>
<input type="submit" name="submit" value="Save Options" onclick="togglePanel(jive<%= this.gatewayType.toString().toUpperCase() %>options,jive<%= this.gatewayType.toString().toUpperCase() %>perms); return false" class="jive-formButton">
<input type="button" name="submit" value="Save Options" onclick="saveOptions('<%= this.gatewayType.toString() %>'); return false" class="jive-formButton">
<input type="reset" name="cancel" value="Cancel" onclick="togglePanel(jive<%= this.gatewayType.toString().toUpperCase() %>options,jive<%= this.gatewayType.toString().toUpperCase() %>perms); return false" class="jive-formButton">
</form>
</div>
</div>
<!-- Permissions Window -->
<div class="jive-gatewayPanel" id="jive<%= this.gatewayType.toString().toUpperCase() %>perms" style="display: none;">
<div>
<form action="">
<form id="jive<%= this.gatewayType.toString().toUpperCase() %>permsform" action="">
<input type="radio" name="userreg" value="all" onClick="getElementById('userreg_specific').style.display = 'none'" checked> All users can register<br>
<input type="radio" name="userreg" value="specific" onClick="getElementById('userreg_specific').style.display = 'block'"> These users and/or groups can register<br>
<div id="userreg_specific" style="display: none; margin: 0; padding: 0; font-size: 80%">
......@@ -200,6 +201,7 @@
</table>
</div>
<input type="radio" name="userreg" value="manual" onClick="getElementById('userreg_specific').style.display = 'none'"> Manual registration only (see the Registrations section to manage)<br>
<input type="submit" name="submit" value="Save Permissions" onclick="togglePanel(jive<%= this.gatewayType.toString().toUpperCase() %>perms,jive<%= this.gatewayType.toString().toUpperCase() %>options); return false" class="jive-formButton">
<input type="reset" name="cancel" value="Cancel" onclick="togglePanel(jive<%= this.gatewayType.toString().toUpperCase() %>perms,jive<%= this.gatewayType.toString().toUpperCase() %>options); return false" class="jive-formButton">
</form>
......@@ -234,14 +236,25 @@
<style type="text/css">
<!-- @import url("style/gateways.css"); -->
</style>
<script language="JavaScript" type="text/javascript" src="scripts/gateways.js"></script>
<script src="dwr/engine.js" type="text/javascript"></script>
<script src="dwr/util.js" type="text/javascript"></script>
<script src="dwr/interface/TransportInstanceManager.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript" src="scripts/gateways.js"></script>
<script type="text/javascript" >
DWREngine.setErrorHandler(handleError);
function handleError(error) {
alert(error);
}
var settings;
function saveOptions(transportID) {
var transportSettings = new Array();
transportSettings["host"] = DWRUtil.getValue(transportID+"host");
transportSettings["port"] = DWRUtil.getValue(transportID+"port");
transportSettings["encoding"] = DWRUtil.getValue(transportID+"encoding");
TransportInstanceManager.saveSettings(null, transportID, transportSettings);
}
</script>
</head>
......
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