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

Fixed up my options config concept. Still working on it, but getting somewhere.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6340 b35dd754-fafc-0310-a699-88a17e54d16e
parent d21ae01d
...@@ -1705,15 +1705,4 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -1705,15 +1705,4 @@ public abstract class BaseTransport implements Component, RosterEventListener {
*/ */
public abstract Boolean isUsernameValid(String username); public abstract Boolean isUsernameValid(String username);
/**
* Return an xml config for the options panel in the admin interface.
*
* Return nothing for no options. This is not officially documented anywhere yet.
* TODO: like.. document it somewhere. =)
*
* @param type The transport type to distinguish if needed.
* @return XML document describing the options interface.
*/
public static Element getOptionsConfig(TransportType type) { return DocumentHelper.createElement("optionconfig"); }
} }
...@@ -17,8 +17,14 @@ import org.xmpp.component.ComponentManager; ...@@ -17,8 +17,14 @@ import org.xmpp.component.ComponentManager;
import org.xmpp.component.ComponentManagerFactory; import org.xmpp.component.ComponentManagerFactory;
import org.picocontainer.MutablePicoContainer; import org.picocontainer.MutablePicoContainer;
import org.picocontainer.defaults.DefaultPicoContainer; import org.picocontainer.defaults.DefaultPicoContainer;
import org.dom4j.DocumentHelper;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import java.io.File; import java.io.File;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.util.Hashtable; import java.util.Hashtable;
...@@ -34,9 +40,11 @@ import java.util.Hashtable; ...@@ -34,9 +40,11 @@ import java.util.Hashtable;
public class GatewayPlugin implements Plugin { public class GatewayPlugin implements Plugin {
private MutablePicoContainer picoContainer; private MutablePicoContainer picoContainer;
private File pluginDirectory;
private PluginManager pluginManager;
/** /**
* Represents all configured transport handlers. * Represents all configured transport handlers.
*/ */
public Hashtable<String,TransportInstance> transports; public Hashtable<String,TransportInstance> transports;
...@@ -47,6 +55,8 @@ public class GatewayPlugin implements Plugin { ...@@ -47,6 +55,8 @@ public class GatewayPlugin implements Plugin {
} }
public void initializePlugin(PluginManager manager, File pluginDirectory) { public void initializePlugin(PluginManager manager, File pluginDirectory) {
this.pluginDirectory = pluginDirectory;
this.pluginManager = manager;
picoContainer.start(); picoContainer.start();
transports = new Hashtable<String,TransportInstance>(); transports = new Hashtable<String,TransportInstance>();
...@@ -92,6 +102,15 @@ public class GatewayPlugin implements Plugin { ...@@ -92,6 +102,15 @@ public class GatewayPlugin implements Plugin {
return picoContainer.getComponentInstanceOfType(clazz); return picoContainer.getComponentInstanceOfType(clazz);
} }
/**
* Returns the plugin manager handling the plugin.
*
* @return plugin manager in question.
*/
public PluginManager getPluginManager() {
return pluginManager;
}
/** /**
* Starts a transport service, identified by subdomain. The transport * Starts a transport service, identified by subdomain. The transport
* service will only start if it is enabled. * service will only start if it is enabled.
...@@ -114,7 +133,7 @@ public class GatewayPlugin implements Plugin { ...@@ -114,7 +133,7 @@ public class GatewayPlugin implements Plugin {
} }
/** /**
* Disables a transport service, identified by subdomain. * Disables a transport service, identified by subdomain.
* *
* @param serviceName name of service to disable. * @param serviceName name of service to disable.
*/ */
...@@ -124,7 +143,7 @@ public class GatewayPlugin implements Plugin { ...@@ -124,7 +143,7 @@ public class GatewayPlugin implements Plugin {
} }
/** /**
* Returns the state of a transport service, identified by subdomain. * Returns the state of a transport service, identified by subdomain.
* *
* @param serviceName name of service to check. * @param serviceName name of service to check.
* @return True of false if service is enabled. * @return True of false if service is enabled.
...@@ -135,7 +154,7 @@ public class GatewayPlugin implements Plugin { ...@@ -135,7 +154,7 @@ public class GatewayPlugin implements Plugin {
} }
/** /**
* Returns the transport instance, identified by subdomain. * Returns the transport instance, identified by subdomain.
* *
* @param serviceName name of service to get instance of. * @param serviceName name of service to get instance of.
* @return Instance of service requested. * @return Instance of service requested.
...@@ -144,4 +163,34 @@ public class GatewayPlugin implements Plugin { ...@@ -144,4 +163,34 @@ public class GatewayPlugin implements Plugin {
return transports.get(serviceName); return transports.get(serviceName);
} }
/**
* Returns the web options config for the given transport, if it exists.
*
* @param type type of the transport we want the options config for.
* @return XML document with the options config.
*/
public Document getOptionsConfig(TransportType type) {
// Load any custom-defined servlets.
File optConf = new File(this.pluginDirectory, "web" + File.separator + "WEB-INF" +
File.separator + "options" + File.separator + type.toString() + ".xml");
Document optConfXML;
try {
FileReader reader = new FileReader(optConf);
SAXReader xmlReader = new SAXReader();
xmlReader.setEncoding("UTF-8");
optConfXML = xmlReader.read(reader);
}
catch (FileNotFoundException e) {
// Non-existent: Return empty config
optConfXML = DocumentHelper.createDocument();
optConfXML.addElement("optionsconfig");
}
catch (DocumentException e) {
// Bad config: Return empty config
optConfXML = DocumentHelper.createDocument();
optConfXML.addElement("optionsconfig");
}
return optConfXML;
}
} }
...@@ -15,8 +15,6 @@ import org.jivesoftware.util.Log; ...@@ -15,8 +15,6 @@ import org.jivesoftware.util.Log;
import org.jivesoftware.util.PropertyEventListener; import org.jivesoftware.util.PropertyEventListener;
import org.jivesoftware.util.PropertyEventDispatcher; import org.jivesoftware.util.PropertyEventDispatcher;
import org.xmpp.component.ComponentManager; import org.xmpp.component.ComponentManager;
import org.dom4j.Element;
import java.util.Map; import java.util.Map;
/** /**
...@@ -227,8 +225,4 @@ public class TransportInstance implements PropertyEventListener { ...@@ -227,8 +225,4 @@ public class TransportInstance implements PropertyEventListener {
propertyDeleted(property, params); propertyDeleted(property, params);
} }
public Element getOptionsConfig() {
return transport.getOptionsConfig(this.type);
}
} }
...@@ -15,8 +15,6 @@ import org.jivesoftware.util.LocaleUtils; ...@@ -15,8 +15,6 @@ import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.wildfire.gateway.*; import org.jivesoftware.wildfire.gateway.*;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
import org.dom4j.Element;
import org.dom4j.DocumentHelper;
import net.sf.jml.MsnUserStatus; import net.sf.jml.MsnUserStatus;
/** /**
...@@ -74,26 +72,6 @@ public class MSNTransport extends BaseTransport { ...@@ -74,26 +72,6 @@ public class MSNTransport extends BaseTransport {
return username.matches("[^ \\p{Cntrl}()@,;:\\\\\"\\[\\]]+@[^ \\p{Cntrl}()@,;:\\\\\"\\[\\]]+"); return username.matches("[^ \\p{Cntrl}()@,;:\\\\\"\\[\\]]+@[^ \\p{Cntrl}()@,;:\\\\\"\\[\\]]+");
} }
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#getOptionsConfig(org.jivesoftware.wildfire.gateway.TransportType)
* @param type The transport type to distinguish if needed.
* @return XML document describing the options interface.
*/
public static Element getOptionsConfig(TransportType type) {
Element optConfig = DocumentHelper.createElement("optionconfig");
Element leftPanel = optConfig.addElement("leftpanel");
Element rightPanel = optConfig.addElement("rightpanel");
rightPanel.addElement("item")
.addAttribute("type", "text")
.addAttribute("sysprop", "plugin.gateway.msn.connecthost")
.addAttribute("desc", "Host");
rightPanel.addElement("item")
.addAttribute("type", "text")
.addAttribute("sysprop", "plugin.gateway.msn.connectport")
.addAttribute("desc", "Port");
return optConfig;
}
/** /**
* Handles creating a MSN session and triggering a login. * Handles creating a MSN session and triggering a login.
* *
......
...@@ -13,8 +13,6 @@ package org.jivesoftware.wildfire.gateway.protocols.oscar; ...@@ -13,8 +13,6 @@ package org.jivesoftware.wildfire.gateway.protocols.oscar;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.wildfire.gateway.*; import org.jivesoftware.wildfire.gateway.*;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.dom4j.Element;
import org.dom4j.DocumentHelper;
/** /**
* OSCAR Transport Interface. * OSCAR Transport Interface.
...@@ -76,32 +74,6 @@ public class OSCARTransport extends BaseTransport { ...@@ -76,32 +74,6 @@ public class OSCARTransport extends BaseTransport {
} }
} }
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#getOptionsConfig(org.jivesoftware.wildfire.gateway.TransportType)
* @param type The transport type to distinguish if needed.
* @return XML document describing the options interface.
*/
public static Element getOptionsConfig(TransportType type) {
Element optConfig = DocumentHelper.createElement("optionconfig");
Element leftPanel = optConfig.addElement("leftpanel");
Element rightPanel = optConfig.addElement("rightpanel");
rightPanel.addElement("item")
.addAttribute("type", "text")
.addAttribute("sysprop", "plugin.gateway."+type.toString()+".connecthost")
.addAttribute("desc", "Host");
rightPanel.addElement("item")
.addAttribute("type", "text")
.addAttribute("sysprop", "plugin.gateway."+type.toString()+".connectport")
.addAttribute("desc", "Port");
if (type == TransportType.icq) {
rightPanel.addElement("item")
.addAttribute("type", "text")
.addAttribute("sysprop", "plugin.gateway.icq.encoding")
.addAttribute("desc", "Encoding");
}
return optConfig;
}
/** /**
* Handles creating an OSCAR session and triggering a login. * Handles creating an OSCAR session and triggering a login.
* *
......
...@@ -15,8 +15,6 @@ import org.jivesoftware.util.LocaleUtils; ...@@ -15,8 +15,6 @@ import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.wildfire.gateway.*; import org.jivesoftware.wildfire.gateway.*;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
import org.dom4j.Element;
import org.dom4j.DocumentHelper;
import ymsg.network.StatusConstants; import ymsg.network.StatusConstants;
/** /**
...@@ -74,26 +72,6 @@ public class YahooTransport extends BaseTransport { ...@@ -74,26 +72,6 @@ public class YahooTransport extends BaseTransport {
return username.matches("\\w+"); return username.matches("\\w+");
} }
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#getOptionsConfig(org.jivesoftware.wildfire.gateway.TransportType)
* @param type The transport type to distinguish if needed.
* @return XML document describing the options interface.
*/
public static Element getOptionsConfig(TransportType type) {
Element optConfig = DocumentHelper.createElement("optionconfig");
Element leftPanel = optConfig.addElement("leftpanel");
Element rightPanel = optConfig.addElement("rightpanel");
rightPanel.addElement("item")
.addAttribute("type", "text")
.addAttribute("sysprop", "plugin.gateway.yahoo.connecthost")
.addAttribute("desc", "Host");
rightPanel.addElement("item")
.addAttribute("type", "text")
.addAttribute("sysprop", "plugin.gateway.yahoo.connectport")
.addAttribute("desc", "Port");
return optConfig;
}
/** /**
* Handles creating a Yahoo session and triggering a login. * Handles creating a Yahoo session and triggering a login.
* *
......
<?xml version="1.0" encoding="UTF-8"?>
<optionsconfig>
<leftpanel></leftpanel>
<rightpanel>
<item type="text" sysprop="plugin.gateway.aim.connecthost" var="host" desc="Host"/>
<item type="text" sysprop="plugin.gateway.aim.connectport" var="port" desc="Port"/>
</rightpanel>
</optionsconfig>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<optionsconfig>
<leftpanel></leftpanel>
<rightpanel>
<item type="text" sysprop="plugin.gateway.icq.connecthost" var="host" desc="Host"/>
<item type="text" sysprop="plugin.gateway.icq.connectport" var="port" desc="Port"/>
<item type="text" sysprop="plugin.gateway.icq.encoding" var="encoding" desc="Encoding"/>
</rightpanel>
</optionsconfig>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<optionsconfig>
<leftpanel></leftpanel>
<rightpanel>
<item type="text" sysprop="plugin.gateway.irc.connecthost" var="host" desc="Host"/>
<item type="text" sysprop="plugin.gateway.irc.connectport" var="port" desc="Port"/>
</rightpanel>
</optionsconfig>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<optionsconfig>
<leftpanel></leftpanel>
<rightpanel>
<item type="text" sysprop="plugin.gateway.msn.connecthost" var="host" desc="Host"/>
<item type="text" sysprop="plugin.gateway.msn.connectport" var="port" desc="Port"/>
</rightpanel>
</optionsconfig>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<optionsconfig>
<leftpanel></leftpanel>
<rightpanel>
<item type="text" sysprop="plugin.gateway.yahoo.connecthost" var="host" desc="Host"/>
<item type="text" sysprop="plugin.gateway.yahoo.connectport" var="port" desc="Port"/>
</rightpanel>
</optionsconfig>
\ No newline at end of file
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
errorPage="error.jsp" errorPage="error.jsp"
%> %>
<%@ page import="org.jivesoftware.util.LocaleUtils"%> <%@ page import="org.jivesoftware.util.LocaleUtils"%>
<%@ page import="org.jivesoftware.wildfire.gateway.TransportInstance" %>
<%@ page import="org.dom4j.Element" %> <%@ page import="org.dom4j.Element" %>
<%@ page import="org.dom4j.Attribute" %> <%@ page import="org.dom4j.Attribute" %>
<%@ page import="org.jivesoftware.util.Log" %> <%@ page import="org.jivesoftware.util.Log" %>
<%@ page import="org.dom4j.Document" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
...@@ -32,34 +32,64 @@ ...@@ -32,34 +32,64 @@
this.out = out; this.out = out;
} }
// <tr valign = "middle" >
// <td width = "1%" ><input type = "checkbox"
// name = "filetransfer"
// value = "enabled" ></td >
// <td > Enable
// file transfer</td >
// </tr >
// <tr valign = "middle" >
// <td width = "1%" ><input type = "checkbox"
// name = "reconnect"
// value = "enabled" ></td >
// <td > Reconnect
// on disconnect</td >
// </tr >
// <tr valign = "middle" >
// <td width = "1%" > & nbsp;</td >
// <td > Reconnect
// Attemps:<input type = "text"
// style = "margin: 0.0px; padding: 0.0px"
// name = "reconnect_attempts"
// size = "4"
// maxlength = "4"
// value = "10" / ></td >
// </tr >
// <tr valign="middle">
// <td align="right" width="1%">Host:</td>
// <td><input type="text" name="host" value="blar" onChange="getElementById('testhost').innerHTML = this.value" /></td>
// </tr>
// <tr valign="middle">
// <td align="right" width="1%">Port:</td>
// <td><input type="text" name="host" value="1234" onChange="getElementById('testport').innerHTML = this.value" /></td>
// </tr>
void printConfigNode(Element node) { void printConfigNode(Element node) {
Log.debug("HI!");
try { try {
Log.debug("WHEE: " + node);
Attribute type = node.attribute("type"); Attribute type = node.attribute("type");
if (type.equals("text")) { if (type.getText().equals("text")) {
Attribute desc = node.attribute("desc"); Attribute desc = node.attribute("desc");
out.println("<tr valign='middle'>"); out.println("<tr valign='middle'>");
out.println("<td align='right' width='1%'>" + desc + ":</td>"); out.println("<td align='right' width='1%'>" + (desc != null ? desc.getText() : "&nbsp;") + ":</td>");
out.println("<td><input type='text' name='var' value='blar'/></td>"); out.println("<td><input type='text' name='var' value='blar'/></td>");
out.println("</tr>"); out.println("</tr>");
// <tr valign="middle">
// <td align="right" width="1%">Host:</td>
// <td><input type="text" name="host" value="blar" onChange="getElementById('testhost').innerHTML = this.value" /></td>
// </tr>
} }
} }
catch (Exception e) { catch (Exception e) {
// Uhm, yeah, that sucks. // Uhm, yeah, that sucks.
Log.error("Error printing config node:", e);
} }
} }
void printSettingsDialog() { void printSettingsDialog() {
try { try {
TransportInstance trInstance = plugin.getTransportInstance(gatewayType.toString()); Document optConfig = plugin.getOptionsConfig(gatewayType);
Element optConfig = trInstance.getOptionsConfig(); Log.debug("Options config is " + optConfig.asXML());
Element leftPanel = optConfig.element("leftpanel"); Element leftPanel = optConfig.getRootElement().element("leftpanel");
Element rightPanel = optConfig.element("rightpanel"); Element rightPanel = optConfig.getRootElement().element("rightpanel");
%> %>
<!-- BEGIN gateway - <%= this.gatewayType.toString().toUpperCase() %> --> <!-- BEGIN gateway - <%= this.gatewayType.toString().toUpperCase() %> -->
...@@ -91,62 +121,34 @@ ...@@ -91,62 +121,34 @@
<tr valign="top"> <tr valign="top">
<td align="left" width="50%"> <td align="left" width="50%">
<% <%
if (leftPanel != null && leftPanel.nodeCount() > 0) { if (leftPanel != null && leftPanel.nodeCount() > 0) {
Log.debug("left WTF?"); out.println("<table border='0' cellpadding='1' cellspacing='2'>");
out.println("<table border='0' cellpadding='1' cellspacing='2'"); for (Object nodeObj : leftPanel.elements("item")) {
for (Object nodeObj : leftPanel.elements()) { Log.debug("whee!");
Log.debug("more left WTF?"+nodeObj); Element node = (Element)nodeObj;
Element node = (Element)nodeObj; printConfigNode(node);
printConfigNode(node); }
} out.println("</table");
out.println("</table"); }
} else {
// <tr valign = "middle" > out.println("&nbsp;");
// <td width = "1%" ><input type = "checkbox" }
// name = "filetransfer"
// value = "enabled" ></td >
// <td > Enable
// file transfer</td >
// </tr >
// <tr valign = "middle" >
// <td width = "1%" ><input type = "checkbox"
// name = "reconnect"
// value = "enabled" ></td >
// <td > Reconnect
// on disconnect</td >
// </tr >
// <tr valign = "middle" >
// <td width = "1%" > & nbsp;</td >
// <td > Reconnect
// Attemps:<input type = "text"
// style = "margin: 0.0px; padding: 0.0px"
// name = "reconnect_attempts"
// size = "4"
// maxlength = "4"
// value = "10" / ></td >
// </tr >
%> %>
</td> </td>
<td align="left" width="50%"> <td align="left" width="50%">
<% <%
if (rightPanel != null && rightPanel.nodeCount() > 0) { if (rightPanel != null && rightPanel.nodeCount() > 0) {
Log.debug("right WTF?"); out.println("<table border='0' cellpadding='1' cellspacing='2'>");
out.println("<table border='0' cellpadding='1' cellspacing='2'"); for (Object nodeObj : rightPanel.elements("item")) {
for (Object nodeObj : rightPanel.elements()) { Log.debug("whee!");
Log.debug("more right WTF?"+nodeObj); Element node = (Element)nodeObj;
Element node = (Element)nodeObj; printConfigNode(node);
printConfigNode(node); }
} out.println("</table");
out.println("</table"); }
} else {
// <tr valign="middle"> out.println("&nbsp;");
// <td align="right" width="1%">Host:</td> }
// <td><input type="text" name="host" value="blar" onChange="getElementById('testhost').innerHTML = this.value" /></td>
// </tr>
// <tr valign="middle">
// <td align="right" width="1%">Port:</td>
// <td><input type="text" name="host" value="1234" onChange="getElementById('testport').innerHTML = this.value" /></td>
// </tr>
%> %>
</td> </td>
</tr> </tr>
...@@ -187,6 +189,7 @@ ...@@ -187,6 +189,7 @@
} }
catch (Exception e) { catch (Exception e) {
// Uhm, yeah, that sucks. // Uhm, yeah, that sucks.
Log.error("Error printing settings section:", e);
} }
} }
} }
...@@ -199,36 +202,32 @@ ...@@ -199,36 +202,32 @@
%> %>
<html> <html>
<head> <head>
<title>Gateway Settings</title> <title>Gateway Settings</title>
<meta name="pageID" content="gateway-settings"> <meta name="pageID" content="gateway-settings">
<style type="text/css"> <style type="text/css">
<!-- @import url("style/gateways.css"); --> <!-- @import url("style/gateways.css"); -->
</style> </style>
<script language="JavaScript" type="text/javascript" src="scripts/gateways.js"></script> <script language="JavaScript" type="text/javascript" src="scripts/gateways.js"></script>
<script src="dwr/engine.js" type="text/javascript"></script> <script src="dwr/engine.js" type="text/javascript"></script>
<script src="dwr/util.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 src="dwr/interface/TransportInstanceManager.js" type="text/javascript"></script>
<script type="text/javascript" > <script type="text/javascript" >
DWREngine.setErrorHandler(handleError); DWREngine.setErrorHandler(handleError);
function handleError(error) { function handleError(error) {
} }
</script> </script>
</head> </head>
<body>
<body>
<p><fmt:message key="gateway.web.settings.instructions" /> <p><fmt:message key="gateway.web.settings.instructions" />
<b>Note:</b> Please be aware that Tests, Options, and Permissions are not yet functional. They are only present for demonstration.</p> <b>Note:</b> Please be aware that Tests, Options, and Permissions are not yet functional. They are only present for demonstration.</p>
<form action="" name="gatewayForm"> <form action="" name="gatewayForm">
<% aimSettings.printSettingsDialog(); %> <% aimSettings.printSettingsDialog(); %>
...@@ -238,10 +237,7 @@ ...@@ -238,10 +237,7 @@
<% yahooSettings.printSettingsDialog(); %> <% yahooSettings.printSettingsDialog(); %>
</form> </form>
<br clear="all"> <br clear="all">
</body> </body>
</html> </html>
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