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 {
*/
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;
import org.xmpp.component.ComponentManagerFactory;
import org.picocontainer.MutablePicoContainer;
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.FileReader;
import java.io.FileNotFoundException;
import java.util.Hashtable;
......@@ -34,6 +40,8 @@ import java.util.Hashtable;
public class GatewayPlugin implements Plugin {
private MutablePicoContainer picoContainer;
private File pluginDirectory;
private PluginManager pluginManager;
/**
* Represents all configured transport handlers.
......@@ -47,6 +55,8 @@ public class GatewayPlugin implements Plugin {
}
public void initializePlugin(PluginManager manager, File pluginDirectory) {
this.pluginDirectory = pluginDirectory;
this.pluginManager = manager;
picoContainer.start();
transports = new Hashtable<String,TransportInstance>();
......@@ -92,6 +102,15 @@ public class GatewayPlugin implements Plugin {
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
* service will only start if it is enabled.
......@@ -144,4 +163,34 @@ public class GatewayPlugin implements Plugin {
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;
import org.jivesoftware.util.PropertyEventListener;
import org.jivesoftware.util.PropertyEventDispatcher;
import org.xmpp.component.ComponentManager;
import org.dom4j.Element;
import java.util.Map;
/**
......@@ -227,8 +225,4 @@ public class TransportInstance implements PropertyEventListener {
propertyDeleted(property, params);
}
public Element getOptionsConfig() {
return transport.getOptionsConfig(this.type);
}
}
......@@ -15,8 +15,6 @@ import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.wildfire.gateway.*;
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import org.dom4j.Element;
import org.dom4j.DocumentHelper;
import net.sf.jml.MsnUserStatus;
/**
......@@ -74,26 +72,6 @@ public class MSNTransport extends BaseTransport {
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.
*
......
......@@ -13,8 +13,6 @@ package org.jivesoftware.wildfire.gateway.protocols.oscar;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.wildfire.gateway.*;
import org.xmpp.packet.JID;
import org.dom4j.Element;
import org.dom4j.DocumentHelper;
/**
* OSCAR Transport Interface.
......@@ -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.
*
......
......@@ -15,8 +15,6 @@ import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.wildfire.gateway.*;
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import org.dom4j.Element;
import org.dom4j.DocumentHelper;
import ymsg.network.StatusConstants;
/**
......@@ -74,26 +72,6 @@ public class YahooTransport extends BaseTransport {
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.
*
......
<?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 @@
errorPage="error.jsp"
%>
<%@ page import="org.jivesoftware.util.LocaleUtils"%>
<%@ page import="org.jivesoftware.wildfire.gateway.TransportInstance" %>
<%@ page import="org.dom4j.Element" %>
<%@ page import="org.dom4j.Attribute" %>
<%@ 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/fmt_rt" prefix="fmt" %>
......@@ -32,34 +32,64 @@
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) {
Log.debug("HI!");
try {
Log.debug("WHEE: " + node);
Attribute type = node.attribute("type");
if (type.equals("text")) {
if (type.getText().equals("text")) {
Attribute desc = node.attribute("desc");
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("</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) {
// Uhm, yeah, that sucks.
Log.error("Error printing config node:", e);
}
}
void printSettingsDialog() {
try {
TransportInstance trInstance = plugin.getTransportInstance(gatewayType.toString());
Element optConfig = trInstance.getOptionsConfig();
Element leftPanel = optConfig.element("leftpanel");
Element rightPanel = optConfig.element("rightpanel");
Document optConfig = plugin.getOptionsConfig(gatewayType);
Log.debug("Options config is " + optConfig.asXML());
Element leftPanel = optConfig.getRootElement().element("leftpanel");
Element rightPanel = optConfig.getRootElement().element("rightpanel");
%>
<!-- BEGIN gateway - <%= this.gatewayType.toString().toUpperCase() %> -->
......@@ -92,61 +122,33 @@
<td align="left" width="50%">
<%
if (leftPanel != null && leftPanel.nodeCount() > 0) {
Log.debug("left WTF?");
out.println("<table border='0' cellpadding='1' cellspacing='2'");
for (Object nodeObj : leftPanel.elements()) {
Log.debug("more left WTF?"+nodeObj);
out.println("<table border='0' cellpadding='1' cellspacing='2'>");
for (Object nodeObj : leftPanel.elements("item")) {
Log.debug("whee!");
Element node = (Element)nodeObj;
printConfigNode(node);
}
out.println("</table");
}
// <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 >
else {
out.println("&nbsp;");
}
%>
</td>
<td align="left" width="50%">
<%
if (rightPanel != null && rightPanel.nodeCount() > 0) {
Log.debug("right WTF?");
out.println("<table border='0' cellpadding='1' cellspacing='2'");
for (Object nodeObj : rightPanel.elements()) {
Log.debug("more right WTF?"+nodeObj);
out.println("<table border='0' cellpadding='1' cellspacing='2'>");
for (Object nodeObj : rightPanel.elements("item")) {
Log.debug("whee!");
Element node = (Element)nodeObj;
printConfigNode(node);
}
out.println("</table");
}
// <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>
else {
out.println("&nbsp;");
}
%>
</td>
</tr>
......@@ -187,6 +189,7 @@
}
catch (Exception e) {
// Uhm, yeah, that sucks.
Log.error("Error printing settings section:", e);
}
}
}
......@@ -199,36 +202,32 @@
%>
<html>
<head>
<title>Gateway Settings</title>
<meta name="pageID" content="gateway-settings">
<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 type="text/javascript" >
DWREngine.setErrorHandler(handleError);
function handleError(error) {
}
</script>
</head>
<body>
<body>
<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>
<form action="" name="gatewayForm">
<% aimSettings.printSettingsDialog(); %>
......@@ -238,10 +237,7 @@
<% yahooSettings.printSettingsDialog(); %>
</form>
<br clear="all">
</body>
</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