Start of transports.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@4663 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro 2006-07-25 06:00:34 +00:00 committed by derek
parent a5615a9f6d
commit 436d0975c9
19 changed files with 668 additions and 208 deletions

View File

@ -10,11 +10,6 @@
package org.jivesoftware.resource;
import javax.swing.ImageIcon;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import java.io.File;
import java.net.URL;
@ -22,6 +17,11 @@ import java.util.Enumeration;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import javax.swing.ImageIcon;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
public class SparkRes {
private static PropertyResourceBundle prb;
@ -239,6 +239,10 @@ public class SparkRes {
public static final String PANE_DOWN_ARROW_IMAGE = "PANE_DOWN_ARROW_IMAGE";
public static final String CLOSE_DARK_X_IMAGE = "CLOSE_DARK_X_IMAGE";
public static final String CLOSE_WHITE_X_IMAGE = "CLOSE_WHITE_X_IMAGE";
public static final String AIM_TRANSPORT_ACTIVE_IMAGE = "AIM_TRANSPORT_ACTIVE_IMAGE";
public static final String AIM_TRANSPORT_INACTIVE_IMAGE = "AIM_TRANSPORT_INACTIVE_IMAGE";
public static final String MSN_TRANSPORT_ACTIVE_IMAGE = "MSN_TRANSPORT_ACTIVE_IMAGE";
public static final String MSN_TRANSPORT_INACTIVE_IMAGE = "MSN_TRANSPORT_INACTIVE_IMAGE";
static ClassLoader cl = SparkRes.class.getClassLoader();

View File

@ -237,4 +237,10 @@ FASTPATH_OFFLINE_IMAGE_16x16 = images/fastpath16_offline.png
FASTPATH_OFFLINE_IMAGE_24x24 = images/fastpath24_offline.png
USER1_ADD_16x16 = images/user1_add.png
END_BUTTON_24x24 = images/end_button_24x24.png
POWERED_BY_IMAGE = images/powered_by.png
POWERED_BY_IMAGE = images/powered_by.png
# Transport images
AIM_TRANSPORT_ACTIVE_IMAGE = images/aim.gif
AIM_TRANSPORT_INACTIVE_IMAGE = images/aim-gray.gif
MSN_TRANSPORT_ACTIVE_IMAGE = images/msn.gif
MSN_TRANSPORT_INACTIVE_IMAGE = images/msn-gray.gif

View File

@ -0,0 +1,104 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.plugin.gateways;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.packet.DiscoverItems.Item;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.plugin.Plugin;
import org.jivesoftware.spark.util.ResourceUtils;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.AIMTransport;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.MSNTransport;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.TransportFactory;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
/**
*
*/
public class GatewayPlugin implements Plugin {
public static final String GATEWAY = "gateway";
public void initialize() {
try {
populateTransports(SparkManager.getConnection());
}
catch (Exception e) {
return;
}
// Add to Menu Item
// Register with action menu
final JMenu actionsMenu = SparkManager.getMainWindow().getMenuByName("Actions");
JMenuItem transportsMenu = new JMenuItem("Transports", SparkRes.getImageIcon(SparkRes.AIM_TRANSPORT_ACTIVE_IMAGE));
ResourceUtils.resButton(transportsMenu, "&Transports");
actionsMenu.add(transportsMenu);
transportsMenu.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final Transports transports = new Transports(SparkManager.getConnection());
transports.showTransports();
}
});
}
public void shutdown() {
}
public boolean canShutDown() {
return false;
}
public void uninstall() {
}
public void populateTransports(XMPPConnection con) throws Exception {
ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(con);
DiscoverItems discoItems = manager.discoverItems(con.getServiceName());
DiscoverItems.Item item;
DiscoverInfo info;
DiscoverInfo.Identity identity;
Iterator it = discoItems.getItems();
while (it.hasNext()) {
item = (Item)it.next();
info = manager.discoverInfo(item.getEntityID());
Iterator itx = info.getIdentities();
while (itx.hasNext()) {
identity = (Identity)itx.next();
if (identity.getCategory().equalsIgnoreCase(GATEWAY)) {
if (item.getEntityID().startsWith("aim.")) {
AIMTransport aim = new AIMTransport(item.getEntityID());
TransportFactory.addTransport(item.getEntityID(), aim);
}
else if (item.getEntityID().startsWith("msn.")) {
MSNTransport msn = new MSNTransport(item.getEntityID());
TransportFactory.addTransport(item.getEntityID(), msn);
}
}
}
}
}
}

View File

@ -0,0 +1,125 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.plugin.gateways;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Registration;
import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.util.ModelUtil;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.TransportFactory;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
/**
*
*/
public class RegistrationDialog {
public void registerWithService(final XMPPConnection con, final String serviceName) {
final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
final TransportRegistrationPanel regPanel = new TransportRegistrationPanel(serviceName);
mainPanel.add(regPanel, BorderLayout.CENTER);
final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
final RolloverButton registerButton = new RolloverButton("Register", null);
final RolloverButton cancelButton = new RolloverButton("Cancel", null);
buttonPanel.add(registerButton);
buttonPanel.add(cancelButton);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
// Create Dialog
Transport transport = TransportFactory.getTransport(serviceName);
final JDialog dialog = new JDialog(new JFrame(), transport.getTitle(), true);
dialog.add(mainPanel);
dialog.pack();
dialog.setSize(400, 200);
registerButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String username = regPanel.getScreenName();
String password = regPanel.getPassword();
if (!ModelUtil.hasLength(username) || !ModelUtil.hasLength(password)) {
JOptionPane.showMessageDialog(mainPanel, "Username and/or Password need to be supplied.", "Registration Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
registerUser(con, serviceName, username, password);
}
catch (XMPPException e1) {
JOptionPane.showMessageDialog(mainPanel, "Unable to register with Transport.", "Registration Error", JOptionPane.ERROR_MESSAGE);
}
dialog.dispose();
}
});
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});
dialog.setVisible(true);
}
private void registerUser(XMPPConnection con, String gatewayDomain, String username, String password) throws XMPPException {
Registration registration = new Registration();
registration.setType(IQ.Type.SET);
registration.setTo(gatewayDomain);
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("username", username);
attributes.put("password", password);
registration.setAttributes(attributes);
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(registration.getPacketID()));
con.sendPacket(registration);
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("Server timed out");
}
if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException("Error registering user", response.getError());
}
}
}

View File

@ -8,7 +8,9 @@
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.plugin.transports;
package org.jivesoftware.sparkimpl.plugin.gateways;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport;
import java.awt.Color;
import java.awt.Font;
@ -16,7 +18,6 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JPanel;
@ -32,7 +33,9 @@ public class TransportItem extends JPanel {
private String transportAddress;
public TransportItem(Icon icon, String title, String description, boolean active, String address) {
private Transport transport;
public TransportItem(Transport transport, boolean active, String address) {
setLayout(new GridBagLayout());
iconLabel = new JLabel();
@ -40,17 +43,19 @@ public class TransportItem extends JPanel {
descriptionLabel = new JLabel();
activeLabel = new JLabel();
iconLabel.setIcon(icon);
iconLabel.setIcon(transport.getIcon());
titleLabel.setText(title);
titleLabel.setFont(new Font("Verdana", Font.BOLD, 12));
titleLabel.setText(transport.getTitle());
titleLabel.setFont(new Font("Dialog", Font.BOLD, 11));
descriptionLabel.setText(description);
// descriptionLabel.setText(description);
descriptionLabel.setFont(new Font("Dialog", Font.PLAIN, 11));
descriptionLabel.setForeground(Color.lightGray);
descriptionLabel.setHorizontalTextPosition(JLabel.LEFT);
descriptionLabel.setHorizontalAlignment(JLabel.LEFT);
activeLabel.setFont(new Font("Dialog", Font.PLAIN, 10));
if (active) {
activeLabel.setText("Active");
activeLabel.setForeground(Color.green);
@ -62,14 +67,16 @@ public class TransportItem extends JPanel {
this.transportAddress = address;
this.transport = transport;
// Build UI
buildUI();
}
private void buildUI() {
add(iconLabel, new GridBagConstraints(0, 0, 1, 2, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 0), 0, 0));
add(titleLabel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
add(descriptionLabel, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 2, 0), 0, 0));
add(titleLabel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
// add(descriptionLabel, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 2, 0), 0, 0));
add(activeLabel, new GridBagConstraints(1, 2, 1, 2, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 0, 0), 0, 0));
}
@ -80,4 +87,8 @@ public class TransportItem extends JPanel {
public void setTransportAddress(String transportAddress) {
this.transportAddress = transportAddress;
}
public Transport getTransport(){
return transport;
}
}

View File

@ -0,0 +1,69 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.plugin.gateways;
import org.jivesoftware.spark.component.TitlePanel;
import org.jivesoftware.spark.util.ResourceUtils;
import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.smack.packet.Registration;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.TransportFactory;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/**
*
*/
public class TransportRegistrationPanel extends JPanel {
private TitlePanel titlePanel;
private JTextField usernameField = new JTextField();
private JPasswordField passwordField = new JPasswordField();
public TransportRegistrationPanel(String serviceName) {
setLayout(new GridBagLayout());
final Transport transport = TransportFactory.getTransport(serviceName);
titlePanel = new TitlePanel("AIM Registration", transport.getTitle(), transport.getIcon(), true);
add(titlePanel, new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
final JLabel usernameLabel = new JLabel();
usernameLabel.setFont(new Font("Dialog", Font.BOLD, 11));
ResourceUtils.resLabel(usernameLabel, usernameField, "&Username:");
add(usernameLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
add(usernameField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
final JLabel passwordLabel = new JLabel();
passwordLabel.setFont(new Font("Dialog", Font.BOLD, 11));
ResourceUtils.resLabel(passwordLabel, passwordField, "&Password:");
add(passwordLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
add(passwordField, new GridBagConstraints(1, 2, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
}
public String getScreenName() {
return usernameField.getText();
}
public String getPassword() {
return new String(passwordField.getPassword());
}
}

View File

@ -0,0 +1,140 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.plugin.gateways;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Registration;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.TitlePanel;
import org.jivesoftware.spark.component.renderer.JPanelRenderer;
import org.jivesoftware.spark.util.GraphicUtils;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport;
import org.jivesoftware.sparkimpl.plugin.gateways.transports.TransportFactory;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.Map;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
/**
*
*/
public class Transports extends JPanel {
private JList list;
private DefaultListModel model = new DefaultListModel();
private RegistrationDialog registrationDialog;
public Transports(final XMPPConnection con) {
setLayout(new GridBagLayout());
list = new JList(model);
// Use JPanel Renderer
list.setCellRenderer(new JPanelRenderer());
registrationDialog = new RegistrationDialog();
TitlePanel titlePanel = new TitlePanel("Available Transports", "Register with these available transports.", null, true);
add(titlePanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
final JScrollPane pane = new JScrollPane(list);
add(pane, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
TransportItem item = (TransportItem)list.getSelectedValue();
Presence presence = con.getRoster().getPresence(item.getTransport().getServiceName());
boolean registered = presence != null && presence.getMode() != null;
if (registered) {
int confirm = JOptionPane.showConfirmDialog(item, "Would you like to disable this active transport?", "Disable Transport", JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
try {
unregister(con, item.getTransport().getServiceName());
}
catch (XMPPException e1) {
e1.printStackTrace();
}
}
}
else {
registrationDialog.registerWithService(con, item.getTransport().getServiceName());
}
}
}
});
for (Transport transport : TransportFactory.getTransports()) {
final TransportItem transportItem = new TransportItem(transport, TransportFactory.isRegistered(con, transport), transport.getServiceName());
model.addElement(transportItem);
}
}
private void unregister(XMPPConnection con, String gatewayDomain) throws XMPPException {
Registration registration = new Registration();
registration.setType(IQ.Type.SET);
registration.setTo(gatewayDomain);
Map map = new HashMap();
map.put("remove", "");
registration.setAttributes(map);
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(registration.getPacketID()));
con.sendPacket(registration);
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("Server timed out");
}
if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException("Error registering user", response.getError());
}
}
public void showTransports() {
final JFrame frame = new JFrame("Transports");
Transports panel = new Transports(SparkManager.getConnection());
frame.getContentPane().add(panel);
frame.pack();
frame.setSize(400, 200);
GraphicUtils.centerWindowOnScreen(frame);
frame.setVisible(true);
}
}

View File

@ -0,0 +1,51 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.plugin.gateways.transports;
import org.jivesoftware.resource.SparkRes;
import javax.swing.Icon;
/**
*
*/
public class AIMTransport implements Transport {
private String serviceName;
public AIMTransport(String serviceName){
this.serviceName = serviceName;
}
public String getTitle(){
return "AIM Registration";
}
public String getInstructions() {
return "Enter your AIM Screen Name and password below.";
}
public Icon getIcon() {
return SparkRes.getImageIcon(SparkRes.AIM_TRANSPORT_ACTIVE_IMAGE);
}
public Icon getInactiveIcon() {
return SparkRes.getImageIcon(SparkRes.AIM_TRANSPORT_INACTIVE_IMAGE);
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
}

View File

@ -0,0 +1,51 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.plugin.gateways.transports;
import org.jivesoftware.resource.SparkRes;
import javax.swing.Icon;
/**
*
*/
public class MSNTransport implements Transport {
private String serviceName;
public MSNTransport(String serviceName) {
this.serviceName = serviceName;
}
public String getTitle() {
return "MSN Registration";
}
public String getInstructions() {
return "Enter your MSN Screen Name and password below.";
}
public Icon getIcon() {
return SparkRes.getImageIcon(SparkRes.MSN_TRANSPORT_ACTIVE_IMAGE);
}
public Icon getInactiveIcon() {
return SparkRes.getImageIcon(SparkRes.MSN_TRANSPORT_INACTIVE_IMAGE);
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
}

View File

@ -0,0 +1,29 @@
/**
* $Revision$
* $Date$
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.sparkimpl.plugin.gateways.transports;
import javax.swing.Icon;
/**
*
*/
public interface Transport {
String getTitle();
String getInstructions();
Icon getIcon();
Icon getInactiveIcon();
String getServiceName();
}

View File

@ -0,0 +1,54 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.plugin.gateways.transports;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Presence;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
public class TransportFactory {
private static Map<String, Transport> transports = new HashMap<String, Transport>();
private TransportFactory() {
}
public static Transport getTransport(String serviceName) {
// Return transport.
if (transports.containsKey(serviceName)) {
return transports.get(serviceName);
}
return null;
}
public static void addTransport(String serviceName, Transport transport) {
transports.put(serviceName, transport);
}
public static Collection<Transport> getTransports() {
return transports.values();
}
public static boolean isRegistered(XMPPConnection con, Transport transport) {
Presence presence = con.getRoster().getPresence(transport.getServiceName());
boolean registered = presence != null && presence.getMode() != null;
return registered;
}
}

View File

@ -1,33 +0,0 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.plugin.transports;
import org.jivesoftware.spark.plugin.Plugin;
/**
*
*/
public class TransportPlugin implements Plugin {
public void initialize() {
}
public void shutdown() {
}
public boolean canShutDown() {
return false;
}
public void uninstall() {
}
}

View File

@ -1,17 +0,0 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.plugin.transports;
/**
*
*/
public class TransportViewer {
}

View File

@ -1,143 +0,0 @@
/**
* $Revision: $
* $Date: $
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Lesser Public License (LGPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.sparkimpl.plugin.transports;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Registration;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.packet.DiscoverInfo;
import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.packet.DiscoverItems.Item;
import org.jivesoftware.spark.component.renderer.JPanelRenderer;
import java.awt.GridBagLayout;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
/**
*
*/
public class TransportViewerPanel extends JPanel {
private JList list;
private DefaultListModel model = new DefaultListModel();
private static final String GATEWAY = "gateway";
public TransportViewerPanel() {
setLayout(new GridBagLayout());
list = new JList(model);
// Use JPanel Renderer
list.setCellRenderer(new JPanelRenderer());
}
public void populateTransports(XMPPConnection con) throws Exception {
ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(con);
DiscoverItems discoItems = manager.discoverItems(con.getServiceName());
DiscoverItems.Item item;
DiscoverInfo info;
DiscoverInfo.Identity identity;
Iterator it = discoItems.getItems();
while (it.hasNext()) {
item = (Item)it.next();
info = manager.discoverInfo(item.getEntityID());
Iterator itx = info.getIdentities();
while (itx.hasNext()) {
identity = (Identity)itx.next();
if (identity.getCategory().equalsIgnoreCase(GATEWAY)) {
Presence presence = con.getRoster().getPresence(item.getEntityID());
boolean registered = presence != null && presence.getMode() != null;
}
}
}
}
private void registerUser(XMPPConnection con, String gatewayDomain, String username, String password) throws XMPPException {
Registration registration = new Registration();
registration.setType(IQ.Type.SET);
registration.setTo(gatewayDomain);
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("username", username);
attributes.put("password", password);
registration.setAttributes(attributes);
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(registration.getPacketID()));
con.sendPacket(registration);
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("Server timed out");
}
if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException("Error registering user", response.getError());
}
}
private void getForm(XMPPConnection con, String gateway) throws Exception {
Registration registration = new Registration();
registration.setType(IQ.Type.GET);
registration.setTo(gateway);
PacketCollector collector = con.createPacketCollector(new PacketIDFilter(registration.getPacketID()));
con.sendPacket(registration);
IQ response = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
collector.cancel();
if (response == null) {
throw new XMPPException("Server timed out");
}
if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException("Error registering user", response.getError());
}
System.out.println(response);
}
public static void main(String args[]) throws Exception {
XMPPConnection con = new XMPPConnection("derek", 5222);
con.login("derek", "test");
final JFrame frame = new JFrame("Test");
TransportViewerPanel panel = new TransportViewerPanel();
panel.populateTransports(con);
panel.getForm(con, "aim.derek");
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
}

View File

@ -120,4 +120,13 @@
<description>Allows users to have bookmarks.</description>
<class>org.jivesoftware.sparkimpl.plugin.bookmarks.BookmarkPlugin</class>
</plugin>
<plugin>
<name>Transports Plugin</name>
<version>1.0</version>
<author>Derek DeMoro</author>
<homePage>http://www.jivesoftware.com</homePage>
<email>derek@jivesoftware.com</email>
<description>Allows users to register with Gateways.</description>
<class>org.jivesoftware.sparkimpl.plugin.gateways.GatewayPlugin</class>
</plugin>
</plugins>

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 657 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 622 B