"Register new account for Jabber" - a plugin from Nicolas Grandclaude

cusax-fix
Yana Stamcheva 19 years ago
parent 1c33af095e
commit d0ae9e93ba

@ -751,6 +751,9 @@
<sysproperty key="java.net.preferIPv6Addresses"
value="false"/>
<!--sysproperty key="net.java.sip.communicator.SC_HOME_DIR_LOCATION"
value="${user.home}"/-->
<!-- Setting properties necessary for dependencies on native libs.-->
<sysproperty key="java.library.path" path="${ld.library.path}:${path}:${dyld.library.path}"/>
<env key="LD_LIBRARY_PATH" path="${ld.library.path}"/>
@ -1367,6 +1370,11 @@ javax.swing.event, javax.swing.border"/>
manifest="src/net/java/sip/communicator/plugin/jabberaccregwizz/jabberaccregwizz.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/plugin/jabberaccregwizz"
prefix="net/java/sip/communicator/plugin/jabberaccregwizz"/>
<zipfileset src="${lib.noinst}/smack.jar" prefix=""/>
<zipfileset src="${lib.noinst}/smackx.jar" prefix=""/>
<zipfileset src="${lib.noinst}/smackx-jingle.jar" prefix=""/>
<zipfileset src="${lib.noinst}/retroweaver-rt-2.0.jar" prefix=""/>
<zipfileset src="${lib.noinst}/backport-util-concurrent.jar" prefix=""/>
<zipfileset dir="resources/images/jabber"
prefix="resources/images/jabber"/>
</jar>

@ -107,6 +107,8 @@ public class OperationSetPersistentPresenceJabberImpl
private JabberSubscriptionListener subscribtionPacketListener = null;
private int resourcePriority = 10;
public OperationSetPersistentPresenceJabberImpl(
ProtocolProviderServiceJabberImpl provider)
{
@ -416,7 +418,7 @@ public void publishPresenceStatus(PresenceStatus status,
{
presence = new Presence(Presence.Type.available);
presence.setMode(presenceStatusToJabberMode((JabberStatusEnum)status));
presence.setPriority(resourcePriority);
presence.setStatus(statusMessage);
presence.addExtension(new Version());
@ -1167,4 +1169,24 @@ else if (presence != null && presence.getType() == Presence.Type.subscribed)
}
}
}
/**
* Returns the jabber account resource priority property value.
*
* @return the jabber account resource priority property value
*/
public int getResourcePriority()
{
return resourcePriority;
}
/**
* Updates the jabber account resource priority property value.
*
* @param resourcePriority the new priority to set
*/
public void setResourcePriority(int resourcePriority)
{
this.resourcePriority = resourcePriority;
}
}

@ -11,6 +11,7 @@
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.util.*;
import org.jivesoftware.smack.packet.*;
import net.java.sip.communicator.impl.protocol.gibberish.*;
import net.java.sip.communicator.service.protocol.*;
@ -261,6 +262,10 @@ private void connectAndLogin(SecurityAuthority authority)
getAccountProperties().get(
ProtocolProviderFactory.SERVER_PORT);
String accountResource = (String)getAccountID().
getAccountProperties().get(
ProtocolProviderFactory.RESOURCE);
// check to see is there SRV records for this server domain
try
{
@ -314,7 +319,11 @@ private void connectAndLogin(SecurityAuthority authority)
, RegistrationState.REGISTERING
, RegistrationStateChangeEvent.REASON_NOT_SPECIFIED
, null);
connection.login(userID, password, "sip-comm");
if(accountResource == null || accountResource == "")
accountResource = "sip-comm";
connection.login(userID, password, accountResource);
if(connection.isAuthenticated())
{
@ -447,10 +456,19 @@ protected void initialize(String screenname,
String keepAliveStrValue = (String)accountID.getAccountProperties().
get("SEND_KEEP_ALIVE");
String resourcePriority = (String)accountID.getAccountProperties().
get(ProtocolProviderFactory.RESOURCE_PRIORITY);
//initialize the presence operationset
OperationSetPersistentPresence persistentPresence =
OperationSetPersistentPresenceJabberImpl persistentPresence =
new OperationSetPersistentPresenceJabberImpl(this);
if(resourcePriority != null)
{
persistentPresence.setResourcePriority(
new Integer(resourcePriority).intValue());
}
supportedOperationSets.put(
OperationSetPersistentPresence.class.getName(),
persistentPresence);

@ -15,23 +15,32 @@
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
/**
* The <tt>FirstWizardPage</tt> is the page, where user could enter the user ID
* and the password of the account.
*
* The <tt>FirstWizardPage</tt> is the page, where user could enter the user
* ID and the password of the account.
*
* @author Yana Stamcheva
* @author Damian Minkov
*/
public class FirstWizardPage
extends JPanel implements WizardPage, DocumentListener
extends JPanel
implements
WizardPage,
DocumentListener
{
private static final Logger logger = Logger
.getLogger(FirstWizardPage.class);
public static final String FIRST_PAGE_IDENTIFIER = "FirstPageIdentifier";
private static final String GOOGLE_USER_SUFFIX = "gmail.com";
private static final String GOOGLE_CONNECT_SRV = "talk.google.com";
private JabberNewAccountDialog jabberNewAccountDialog;
private JPanel userIDPassPanel = new JPanel(new BorderLayout(10, 10));
private JPanel labelsPanel = new JPanel();
@ -42,8 +51,8 @@ public class FirstWizardPage
private JLabel passLabel = new JLabel(Resources.getString("password"));
private JLabel existingAccountLabel
= new JLabel(Resources.getString("existingAccount"));
private JLabel existingAccountLabel = new JLabel(Resources
.getString("existingAccount"));
private JPanel emptyPanel = new JPanel();
@ -53,8 +62,8 @@ public class FirstWizardPage
private JPasswordField passField = new JPasswordField();
private JCheckBox rememberPassBox = new JCheckBox(
Resources.getString("rememberPassword"));
private JCheckBox rememberPassBox = new JCheckBox(Resources
.getString("rememberPassword"));
private JPanel advancedOpPanel = new JPanel(new BorderLayout(10, 10));
@ -62,18 +71,38 @@ public class FirstWizardPage
private JPanel valuesAdvOpPanel = new JPanel(new GridLayout(0, 1, 10, 10));
private JCheckBox sendKeepAliveBox = new JCheckBox(
Resources.getString("sendKeepAlive"));
private JCheckBox sendKeepAliveBox = new JCheckBox(Resources
.getString("sendKeepAlive"));
private JCheckBox enableAdvOpButton = new JCheckBox(Resources
.getString("ovverideServerOps"), false);
private JLabel resourceLabel = new JLabel("Resource");
private JTextField resourceField = new JTextField("sip-comm");
private JCheckBox enableAdvOpButton = new JCheckBox(
Resources.getString("ovverideServerOps"), false);
private JLabel priorityLabel = new JLabel("Priority");
private JTextField priorityField = new JTextField("10");
private JLabel serverLabel = new JLabel(Resources.getString("server"));
private JTextField serverField = new JTextField();
private JLabel portLabel = new JLabel(Resources.getString("port"));
private JTextField portField = new JTextField("5222");
private JPanel registerPanel = new JPanel(new GridLayout(0, 1));
private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
private JTextArea registerArea = new JTextArea(Resources
.getString("registerNewAccountText"));
private JButton registerButton = new JButton(Resources
.getString("registerNewAccount"));
private JPanel mainPanel = new JPanel();
private Object nextPageIdentifier = WizardPage.SUMMARY_PAGE_IDENTIFIER;
@ -84,13 +113,13 @@ public class FirstWizardPage
/**
* Creates an instance of <tt>FirstWizardPage</tt>.
* @param registration the <tt>JabberAccountRegistration</tt>, where
* all data through the wizard are stored
* @param wizardContainer the wizardContainer, where this page will
* be added
*
* @param registration the <tt>JabberAccountRegistration</tt>, where all
* data through the wizard are stored
* @param wizardContainer the wizardContainer, where this page will be added
*/
public FirstWizardPage(JabberAccountRegistration registration,
WizardContainer wizardContainer)
WizardContainer wizardContainer)
{
super(new BorderLayout());
@ -99,7 +128,7 @@ public FirstWizardPage(JabberAccountRegistration registration,
this.registration = registration;
this.setPreferredSize(new Dimension(300, 150));
this.setPreferredSize(new Dimension(300, 480));
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
@ -107,9 +136,11 @@ public FirstWizardPage(JabberAccountRegistration registration,
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
this.labelsPanel.setLayout(new BoxLayout(labelsPanel, BoxLayout.Y_AXIS));
this.labelsPanel
.setLayout(new BoxLayout(labelsPanel, BoxLayout.Y_AXIS));
this.valuesPanel.setLayout(new BoxLayout(valuesPanel, BoxLayout.Y_AXIS));
this.valuesPanel
.setLayout(new BoxLayout(valuesPanel, BoxLayout.Y_AXIS));
}
/**
@ -118,13 +149,14 @@ public FirstWizardPage(JabberAccountRegistration registration,
private void init()
{
this.userIDField.getDocument().addDocumentListener(this);
this.resourceField.getDocument().addDocumentListener(this);
this.rememberPassBox.setSelected(true);
this.existingAccountLabel.setForeground(Color.RED);
this.userIDExampleLabel.setForeground(Color.GRAY);
this.userIDExampleLabel.setFont(userIDExampleLabel.getFont().deriveFont(
8));
this.userIDExampleLabel.setFont(userIDExampleLabel.getFont()
.deriveFont(8));
this.emptyPanel.setMaximumSize(new Dimension(40, 35));
this.userIDExampleLabel.setBorder(BorderFactory.createEmptyBorder(0, 0,
8, 0));
@ -141,14 +173,15 @@ private void init()
userIDPassPanel.add(valuesPanel, BorderLayout.CENTER);
userIDPassPanel.add(rememberPassBox, BorderLayout.SOUTH);
userIDPassPanel.setBorder(BorderFactory
.createTitledBorder(Resources.getString(
"userIDAndPassword")));
userIDPassPanel.setBorder(BorderFactory.createTitledBorder(Resources
.getString("userIDAndPassword")));
mainPanel.add(userIDPassPanel);
serverField.setEditable(false);
portField.setEditable(false);
resourceField.setEditable(false);
priorityField.setEditable(false);
enableAdvOpButton.addActionListener(new ActionListener()
{
@ -159,30 +192,54 @@ public void actionPerformed(ActionEvent evt)
serverField.setEditable(cb.isSelected());
portField.setEditable(cb.isSelected());
resourceField.setEditable(cb.isSelected());
priorityField.setEditable(cb.isSelected());
}
});
portField.getDocument().addDocumentListener(new DocumentListener()
{
public void changedUpdate(DocumentEvent evt)
{}
{
}
public void insertUpdate(DocumentEvent evt)
{
setNextButtonAccordingToPortAndPriority();
}
public void removeUpdate(DocumentEvent evt)
{
setNextButtonAccordingToPortAndPriority();
}
});
priorityField.getDocument().addDocumentListener(new DocumentListener()
{
public void changedUpdate(DocumentEvent evt)
{
}
public void insertUpdate(DocumentEvent evt)
{
setNextButtonAccordingToPort();
setNextButtonAccordingToPortAndPriority();
}
public void removeUpdate(DocumentEvent evt)
{
setNextButtonAccordingToPort();
setNextButtonAccordingToPortAndPriority();
}
});
labelsAdvOpPanel.add(serverLabel);
labelsAdvOpPanel.add(portLabel);
labelsAdvOpPanel.add(resourceLabel);
labelsAdvOpPanel.add(priorityLabel);
valuesAdvOpPanel.add(serverField);
valuesAdvOpPanel.add(portField);
valuesAdvOpPanel.add(resourceField);
valuesAdvOpPanel.add(priorityField);
JPanel checkBoxesPanel = new JPanel(new GridLayout(0, 1, 10, 10));
checkBoxesPanel.add(sendKeepAliveBox);
@ -192,19 +249,58 @@ public void removeUpdate(DocumentEvent evt)
advancedOpPanel.add(labelsAdvOpPanel, BorderLayout.WEST);
advancedOpPanel.add(valuesAdvOpPanel, BorderLayout.CENTER);
advancedOpPanel.setBorder(BorderFactory
.createTitledBorder(Resources.getString(
"advancedOptions")));
advancedOpPanel.setBorder(BorderFactory.createTitledBorder(Resources
.getString("advancedOptions")));
mainPanel.add(advancedOpPanel);
registerButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
logger.debug("Reg OK");
// Open the new account dialog.
jabberNewAccountDialog = new JabberNewAccountDialog();
if (jabberNewAccountDialog.isOK == true)
{
serverField.setText(jabberNewAccountDialog.server);
portField.setText(jabberNewAccountDialog.port);
// This userIDField contains the username "@" the server.
userIDField.setText(jabberNewAccountDialog.userID + "@"
+ jabberNewAccountDialog.server);
passField.setText(jabberNewAccountDialog.password);
}
logger.debug("Reg End");
}
});
buttonPanel.add(registerButton);
registerArea.setEditable(false);
registerArea.setOpaque(false);
registerArea.setLineWrap(true);
registerArea.setWrapStyleWord(true);
registerPanel.add(registerArea);
registerPanel.add(buttonPanel);
registerPanel.setBorder(BorderFactory.createTitledBorder(Resources
.getString("registerNewAccount")));
mainPanel.add(registerPanel);
this.add(mainPanel, BorderLayout.NORTH);
}
/**
* Implements the <code>WizardPage.getIdentifier</code> to return
* this page identifier.
*
* Implements the <code>WizardPage.getIdentifier</code> to return this
* page identifier.
*
* @return the id of the first wizard page.
*/
public Object getIdentifier()
@ -215,7 +311,7 @@ public Object getIdentifier()
/**
* Implements the <code>WizardPage.getNextPageIdentifier</code> to return
* the next page identifier - the summary page.
*
*
* @return the id of the next wizard page.
*/
public Object getNextPageIdentifier()
@ -226,7 +322,7 @@ public Object getNextPageIdentifier()
/**
* Implements the <code>WizardPage.getBackPageIdentifier</code> to return
* the next back identifier - the default page.
*
*
* @return the id of the default wizard page.
*/
public Object getBackPageIdentifier()
@ -235,9 +331,9 @@ public Object getBackPageIdentifier()
}
/**
* Implements the <code>WizardPage.getWizardForm</code> to return
* this panel.
*
* Implements the <code>WizardPage.getWizardForm</code> to return this
* panel.
*
* @return this wizard page.
*/
public Object getWizardForm()
@ -251,7 +347,7 @@ public Object getWizardForm()
*/
public void pageShowing()
{
this.setNextButtonAccordingToUserID();
this.setNextButtonAccordingToUserIDAndResource();
}
/**
@ -278,12 +374,16 @@ public void pageNext()
registration.setServerAddress(serverField.getText());
registration.setSendKeepAlive(sendKeepAliveBox.isSelected());
registration.setResource(resourceField.getText());
try
{
registration.setPort(Integer.parseInt(portField.getText()));
registration.setPriority(Integer.parseInt(priorityField
.getText()));
}
catch (NumberFormatException ex)
{}
{
}
}
}
@ -291,9 +391,11 @@ public void pageNext()
* Enables or disables the "Next" wizard button according to whether the
* UserID field is empty.
*/
private void setNextButtonAccordingToUserID()
private void setNextButtonAccordingToUserIDAndResource()
{
if (userIDField.getText() == null || userIDField.getText().equals(""))
if (userIDField.getText() == null || userIDField.getText().equals("")
|| resourceField.getText() == null
|| resourceField.getText().equals(""))
{
wizardContainer.setNextFinishButtonEnabled(false);
}
@ -307,12 +409,12 @@ private void setNextButtonAccordingToUserID()
* Handles the <tt>DocumentEvent</tt> triggered when user types in the
* UserID field. Enables or disables the "Next" wizard button according to
* whether the UserID field is empty.
*
*
* @param evt the document event that has triggered this method call.
*/
public void insertUpdate(DocumentEvent evt)
{
this.setNextButtonAccordingToUserID();
this.setNextButtonAccordingToUserIDAndResource();
this.setServerFieldAccordingToUserID();
}
@ -320,12 +422,12 @@ public void insertUpdate(DocumentEvent evt)
* Handles the <tt>DocumentEvent</tt> triggered when user deletes letters
* from the User ID field. Enables or disables the "Next" wizard button
* according to whether the User ID field is empty.
*
*
* @param evt the document event that has triggered this method call.
*/
public void removeUpdate(DocumentEvent evt)
{
this.setNextButtonAccordingToUserID();
this.setNextButtonAccordingToUserIDAndResource();
this.setServerFieldAccordingToUserID();
}
@ -348,14 +450,15 @@ public void pageBack()
/**
* Fills the User ID and Password fields in this panel with the data comming
* from the given protocolProvider.
* @param protocolProvider The <tt>ProtocolProviderService</tt> to load the
* data from.
*
* @param protocolProvider The <tt>ProtocolProviderService</tt> to load
* the data from.
*/
public void loadAccount(ProtocolProviderService protocolProvider)
{
AccountID accountID = protocolProvider.getAccountID();
String password = (String) accountID.getAccountProperties()
.get(ProtocolProviderFactory.PASSWORD);
String password = (String) accountID.getAccountProperties().get(
ProtocolProviderFactory.PASSWORD);
this.userIDField.setText(accountID.getUserID());
@ -367,8 +470,8 @@ public void loadAccount(ProtocolProviderService protocolProvider)
}
/**
* Parse the server part from the jabber id and set it to server
* as default value. If Advanced option is enabled Do nothing.
* Parse the server part from the jabber id and set it to server as default
* value. If Advanced option is enabled Do nothing.
*/
private void setServerFieldAccordingToUserID()
{
@ -394,12 +497,12 @@ private void setServerFieldAccordingToUserID()
/**
* Disables Next Button if Port field value is incorrect
*/
private void setNextButtonAccordingToPort()
private void setNextButtonAccordingToPortAndPriority()
{
try
{
String portValue = portField.getText();
new Integer(portField.getText());
new Integer(priorityField.getText());
wizardContainer.setNextFinishButtonEnabled(true);
}
catch (NumberFormatException ex)
@ -408,10 +511,17 @@ private void setNextButtonAccordingToPort()
}
}
/**
* Checks if the accountName corresponds to an already existing account.
*
* @param accountName the name of the account to check
* @return TRUE if an account with the specified name already exists, FALSE -
* otherwise.
*/
private boolean isExistingAccount(String accountName)
{
ProtocolProviderFactory factory
= JabberAccRegWizzActivator.getJabberProtocolProviderFactory();
ProtocolProviderFactory factory = JabberAccRegWizzActivator
.getJabberProtocolProviderFactory();
ArrayList registeredAccounts = factory.getRegisteredAccounts();

@ -25,6 +25,10 @@ public class JabberAccountRegistration
private int port;
private String resource;
private int priority;
private boolean sendKeepAlive;
/**
@ -135,4 +139,24 @@ public void setSendKeepAlive(boolean sendKeepAlive)
{
this.sendKeepAlive = sendKeepAlive;
}
public String getResource()
{
return resource;
}
public void setResource(String resource)
{
this.resource = resource;
}
public int getPriority()
{
return priority;
}
public void setPriority(int priority)
{
this.priority = priority;
}
}

@ -6,14 +6,17 @@
*/
package net.java.sip.communicator.plugin.jabberaccregwizz;
import java.awt.*;
import java.util.*;
import org.osgi.framework.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.plugin.gibberishaccregwizz.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
import org.osgi.framework.*;
/**
* The <tt>JabberAccountRegistrationWizard</tt> is an implementation of the
* <tt>AccountRegistrationWizard</tt> for the Jabber protocol. It should allow
@ -46,7 +49,7 @@ public class JabberAccountRegistrationWizard
*/
public JabberAccountRegistrationWizard(WizardContainer wizardContainer)
{
this.wizardContainer = wizardContainer;
this.wizardContainer = wizardContainer;
}
/**
@ -121,6 +124,7 @@ public Iterator getSummary()
/**
* Installs the account created through this wizard.
*
* @return ProtocolProviderService
*/
public ProtocolProviderService finish()
@ -136,6 +140,7 @@ public ProtocolProviderService finish()
/**
* Creates an account for the given user and password.
*
* @param providerFactory the ProtocolProviderFactory which will create
* the account
* @param user the user identifier
@ -164,6 +169,12 @@ public ProtocolProviderService installAccount(
accountProperties.put("SEND_KEEP_ALIVE",
String.valueOf(registration.isSendKeepAlive()));
accountProperties.put("RESOURCE",
registration.getResource());
accountProperties.put("PRIORITY",
String.valueOf(registration.getPriority()));
if (isModification)
{
providerFactory.uninstallAccount(protocolProvider.getAccountID());
@ -202,11 +213,11 @@ public ProtocolProviderService installAccount(
*/
public void loadAccount(ProtocolProviderService protocolProvider)
{
this.protocolProvider = protocolProvider;
this.firstWizardPage.loadAccount(protocolProvider);
isModification = true;
}
}

@ -0,0 +1,372 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.jabberaccregwizz;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import net.java.sip.communicator.util.*;
import org.jivesoftware.smack.*;
/**
* Dialog for adding a new Jabber account.
*
* @author Nicolas Grandclaude
*/
public class JabberNewAccountDialog
extends JDialog
implements
DocumentListener
{
private static final Logger logger = Logger
.getLogger(JabberNewAccountDialog.class);
private JabberServerChooserDialog jabberServerChooserDialog;
// Panels
private JPanel userIDPassPanel = new JPanel(new BorderLayout(10, 10));
private JPanel labelsPanel = new JPanel(new GridLayout(0, 1, 10, 10));
private JPanel valuesPanel = new JPanel(new GridLayout(0, 1, 10, 10));
private JPanel serverPanel = new JPanel(new BorderLayout(10, 10));
private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
private Box buttonBox = new Box(BoxLayout.X_AXIS);
private JPanel mainPanel = new JPanel(new BorderLayout());
private JPanel westPanel = new JPanel(new BorderLayout(10, 10));
// Labels
private JLabel serverLabel = new JLabel(Resources.getString("cserver"));
private JLabel userIDLabel = new JLabel(Resources.getString("userID"));
private JLabel passLabel = new JLabel(Resources.getString("password"));
private JLabel pass2Label = new JLabel(Resources.getString("password2"));
private JLabel portLabel = new JLabel(Resources.getString("port"));
private JLabel westIconLabel = new JLabel();
// Textfield
private JTextField serverField = new JTextField();
private JTextField userIDField = new JTextField();
private JPasswordField passField = new JPasswordField();
private JPasswordField pass2Field = new JPasswordField();
private JTextField portField = new JTextField("5222");
// Button
private JButton chooseButton = new JButton();
private JButton okButton = new JButton();
private JButton cancelButton = new JButton();
// Smack objects
private XMPPConnection xmppConnection = null;
private AccountManager accountManager = null;
// Variables for FirstWizardPage
public boolean isOK = false;
public String userID = null;
public String password = null;
public String server = null;
public String port = null;
private LoadingAccountGlassPane loadingAccountGlassPane
= new LoadingAccountGlassPane();
/**
* Creates an instance of <tt>JabberNewAccountDialog</tt>.
*/
public JabberNewAccountDialog()
{
this.setSize(new Dimension(450, 250));
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setTitle(Resources.getString("newAccountTitle"));
this.setModal(true);
this.setGlassPane(loadingAccountGlassPane);
// Place the window in the screen center
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(screenSize.width / 2 - this.getWidth() / 2,
screenSize.height / 2 - this.getHeight() / 2);
this.init();
}
/**
* Connect to the choose server and create a new account with Smack
*
* @param server the server domain
* @param port TCP port to connect
* @param username username
* @param password password
*/
private boolean addNewAccount(String server, int port, String username,
String password)
{
try
{
ConnectionConfiguration config = new ConnectionConfiguration(
server, port);
xmppConnection = new XMPPConnection(config);
xmppConnection.connect();
accountManager = new AccountManager(xmppConnection);
accountManager.createAccount(username, password);
return true;
}
catch (XMPPException exc)
{
if (exc.getXMPPError().getCode() == 409)
{
JOptionPane.showMessageDialog(null, Resources
.getString("userExist"), Resources.getString("xmppError"),
JOptionPane.ERROR_MESSAGE);
logger.error(
"Error when created a new Jabber account : user already exist");
}
else
{
JOptionPane.showMessageDialog(null, Resources
.getString("unknownXmppError"), Resources
.getString("xmppError"), JOptionPane.ERROR_MESSAGE);
}
return false;
}
}
/**
* Initializes all panels, buttons, etc.
*/
private void init()
{
labelsPanel.add(serverLabel);
labelsPanel.add(userIDLabel);
labelsPanel.add(passLabel);
labelsPanel.add(pass2Label);
labelsPanel.add(portLabel);
userIDField.setColumns(30);
serverPanel.add(serverField, BorderLayout.CENTER);
serverPanel.add(chooseButton, BorderLayout.EAST);
valuesPanel.add(serverPanel);
valuesPanel.add(userIDField);
valuesPanel.add(passField);
valuesPanel.add(pass2Field);
valuesPanel.add(portField);
serverField.getDocument().addDocumentListener(this);
userIDField.getDocument().addDocumentListener(this);
passField.getDocument().addDocumentListener(this);
pass2Field.getDocument().addDocumentListener(this);
portField.getDocument().addDocumentListener(this);
userIDPassPanel.add(labelsPanel, BorderLayout.WEST);
userIDPassPanel.add(valuesPanel, BorderLayout.CENTER);
chooseButton.setText(Resources.getString("chooseLabel"));
chooseButton.setMnemonic(Resources.getMnemonic("chooseLabel"));
westIconLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(20, 20, 20, 20), BorderFactory
.createTitledBorder("")));
try
{
westIconLabel.setIcon(new ImageIcon(ImageIO
.read(new ByteArrayInputStream(Resources
.getImage(Resources.PAGE_IMAGE)))));
}
catch (IOException e)
{
logger.error("Could not read image.", e);
}
westPanel.add(westIconLabel, BorderLayout.NORTH);
this.mainPanel.add(westPanel, BorderLayout.WEST);
// Choose button open the JabberServerChooserDialog
chooseButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
jabberServerChooserDialog = new JabberServerChooserDialog();
if (jabberServerChooserDialog.isOK) // OK pressed in
// JabberServerChooserDialog
{
serverField
.setText(jabberServerChooserDialog.serverSelected);
}
}
});
// Ok button
okButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
if (new String(passField.getPassword()).equals(new String(
pass2Field.getPassword())))
{ // the two password fields are the same
new Thread()
{
public void run()
{
boolean result = addNewAccount(serverField.getText(),
Integer.parseInt(portField.getText()),
userIDField.getText(),
new String(passField.getPassword()));
if (result == true)
{
// Update FirstWizardDialog field
isOK = true;
userID = new String(userIDField.getText());
password = new String(passField.getPassword());
server = new String(serverField.getText());
port = new String(portField.getText());
dispose();
}
}
}.start();
loadingAccountGlassPane.setVisible(true);
}
else
{
JOptionPane.showMessageDialog(null, Resources
.getString("notSamePassword"), Resources
.getString("xmppError"), JOptionPane.ERROR_MESSAGE);
}
}
});
// Cancel button
cancelButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
dispose();
}
});
okButton.setText(Resources.getString("okLabel"));
okButton.setMnemonic(Resources.getMnemonic("okLabel"));
okButton.setEnabled(false);
cancelButton.setText(Resources.getString("cancelLabel"));
cancelButton.setMnemonic(Resources.getMnemonic("cancelLabel"));
buttonBox.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
buttonBox.add(okButton);
buttonBox.add(Box.createHorizontalStrut(10));
buttonBox.add(cancelButton);
buttonPanel.add(buttonBox);
this.mainPanel.add(userIDPassPanel, BorderLayout.CENTER);
this.mainPanel.add(buttonPanel, BorderLayout.SOUTH);
mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
this.getContentPane().add(mainPanel, BorderLayout.NORTH);
this.setVisible(true);
}
/**
* Sets the "Ok" button enabled if all fields are filled.
*/
private void enableOKButton()
{
okButton.setEnabled(false);
try
{
Integer.parseInt(portField.getText());
}
catch (NumberFormatException ex)
{
okButton.setEnabled(false);
return;
}
if (serverField.getText().equals("")
|| userIDField.getText().equals("")
|| (new String(passField.getPassword())).equals("")
|| (new String(pass2Field.getPassword())).equals(""))
{
okButton.setEnabled(false);
}
else
{
okButton.setEnabled(true);
}
}
public void insertUpdate(DocumentEvent evt)
{
this.enableOKButton();
}
public void removeUpdate(DocumentEvent evt)
{
this.enableOKButton();
}
public void changedUpdate(DocumentEvent evt)
{
}
public void pageHiding()
{
}
public void pageShown()
{
}
public void pageBack()
{
}
/**
* A GlassPane that would change the cursor to a waiting cursor until the
* new account is registered.
*/
private class LoadingAccountGlassPane extends JComponent
{
public LoadingAccountGlassPane()
{
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
}
}
}

@ -0,0 +1,378 @@
/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.jabberaccregwizz;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.table.*;
import javax.xml.parsers.*;
import net.java.sip.communicator.service.fileaccess.*;
import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
import org.w3c.dom.*;
import org.xml.sax.*;
/**
* A dialog that shows the list of available Jabber servers.
*
* @author Nicolas Grandclaude
*/
public class JabberServerChooserDialog
extends JDialog
implements ListSelectionListener
{
private static final Logger logger = Logger
.getLogger(JabberServerChooserDialog.class);
private static final String DEFAULT_FILE_NAME = "jabberservers.xml";
// Servers Table
private JTable serversTable;
private JTextArea chooseArea = new JTextArea(Resources
.getString("chooseServerText"));
// Panel
private JPanel mainPanel = new JPanel(new BorderLayout());
private JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
private Box buttonBox = new Box(BoxLayout.X_AXIS);
private JPanel chooseAreaPanel = new JPanel(new BorderLayout());
private JPanel westPanel = new JPanel(new BorderLayout(10, 10));
private JPanel eastPanel = new JPanel(new BorderLayout(10, 10));
private JLabel westIconLabel = new JLabel();
private JButton okButton = new JButton(Resources.getString("okLabel"));
private JButton cancelButton = new JButton(Resources
.getString("cancelLabel"));
private Vector servers = new Vector();
private FileAccessService faService = null;
private String[] columnNames =
{ Resources.getString("serverColumn"), Resources.getString("commentColumn") };
public boolean isOK = false;
public String serverSelected;
/**
* Creates an instance of <tt>JabberServerChooserDialog</tt>.
*/
public JabberServerChooserDialog()
{
this.setSize(new Dimension(550, 450));
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setTitle(Resources.getString("chooseTitle"));
this.setModal(true);
// Place the window in the center
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(screenSize.width / 2 - this.getWidth() / 2,
screenSize.height / 2 - this.getHeight() / 2);
this.init();
}
/**
* Initializes all panels, buttons, etc.
*/
private void init()
{
chooseArea.setEditable(false);
chooseArea.setOpaque(false);
chooseArea.setLineWrap(true);
chooseArea.setWrapStyleWord(true);
chooseAreaPanel
.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 10));
chooseAreaPanel.add(chooseArea, BorderLayout.NORTH);
eastPanel.add(chooseAreaPanel, BorderLayout.NORTH);
// West Jabber icon
westIconLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(20, 20, 20, 20), BorderFactory
.createTitledBorder("")));
try
{
westIconLabel.setIcon(new ImageIcon(ImageIO
.read(new ByteArrayInputStream(Resources
.getImage(Resources.PAGE_IMAGE)))));
}
catch (IOException e)
{
logger.error("Could not read image.", e);
}
this.westPanel.add(westIconLabel, BorderLayout.NORTH);
this.mainPanel.add(westPanel, BorderLayout.WEST);
// Table with servers and comments
serversTable = new JTable(new ServerChooserTableModel());
serversTable.setRowHeight(22);
serversTable.getSelectionModel().addListSelectionListener(this);
serversTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
serversTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
// Fill the servers array with servers from servers.xml
fillTable();
JScrollPane scrollPane = new JScrollPane(serversTable);
eastPanel.add(scrollPane, BorderLayout.CENTER);
// Ok button
okButton.setText(Resources.getString("okLabel"));
okButton.setMnemonic(Resources.getMnemonic("okLabel"));
okButton.setEnabled(false);
// Cancel button
cancelButton.setText(Resources.getString("cancelLabel"));
cancelButton.setMnemonic(Resources.getMnemonic("cancelLabel"));
// Box with Ok and Cancel
buttonBox.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
buttonBox.add(okButton);
buttonBox.add(Box.createHorizontalStrut(10));
buttonBox.add(cancelButton);
buttonPanel.add(buttonBox);
okButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
isOK = true;
dispose();
}
});
cancelButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
dispose();
}
});
this.mainPanel.add(eastPanel, BorderLayout.CENTER);
this.mainPanel.add(buttonPanel, BorderLayout.SOUTH);
mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
this.getContentPane().add(mainPanel, BorderLayout.CENTER);
this.setVisible(true);
}
/**
* Fill the servers array variable with data from the remote servers.xml
*/
public void fillTable()
{
BundleContext bc = JabberAccRegWizzActivator.bundleContext;
ServiceReference faServiceReference = bc
.getServiceReference(FileAccessService.class.getName());
faService = (FileAccessService) bc.getService(faServiceReference);
try
{
File localServersListFile = faService
.getPrivatePersistentFile(DEFAULT_FILE_NAME);
// Get the file containing the servers list.
if (!localServersListFile.exists())
{
try
{
localServersListFile.createNewFile();
}
catch (IOException e)
{
logger.error("Failed to create file"
+ localServersListFile.getAbsolutePath(), e);
}
}
try
{
URL file = new URL("http://www.jabber.org/servers.xml");
InputStream stream = file.openStream();
try
{
// Copy the remote file to the disk
byte[] buf = new byte[2048];
int len;
if (stream.available() > 0)
{
FileOutputStream fos
= new FileOutputStream(localServersListFile);
while ((len = stream.read(buf)) > 0)
{
fos.write(buf, 0, len);
}
fos.close();
}
} finally
{
stream.close();
}
}
catch (Exception e)
{
logger.error("");
}
FileInputStream fis = new FileInputStream(localServersListFile);
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder constructor = factory.newDocumentBuilder();
Document document = constructor.parse(fis);
Element root = document.getDocumentElement();
NodeList list = root.getElementsByTagName("item");
// Read the xml and fill servers variable for the JTable
for (int i = 0; i < list.getLength(); i++)
{
Element e = (Element) list.item(i);
servers.add(new String(e.getAttribute("jid")));
}
fis.close();
}
catch (Exception e)
{
logger.error(
"Failed to get a reference to the Jabber servers list file.", e);
}
}
/**
* When a table row is selected enable the "Ok" button, otherwise disable it.
*/
public void valueChanged(ListSelectionEvent e)
{
int row = serversTable.getSelectedRow();
if (row != -1)
{
okButton.setEnabled(true);
serverSelected = (String) serversTable.getValueAt(row, 0);
}
else
{
okButton.setEnabled(false);
}
}
/**
* The table model used for the table containing all servers.
*/
private class ServerChooserTableModel extends AbstractTableModel
{
private Document serverComments;
private NodeList commentsList;
public ServerChooserTableModel()
{
try
{
// Create a builder factory
DocumentBuilderFactory factory
= DocumentBuilderFactory.newInstance();
// Create the builder and parse the file
serverComments = factory.newDocumentBuilder()
.parse(new File(Resources.getString("commentsFile")));
}
catch (SAXException e)
{
logger.error("Failed to parse: " + DEFAULT_FILE_NAME, e);
}
catch (ParserConfigurationException e)
{
logger.error("Failed to parse: " + DEFAULT_FILE_NAME, e);
}
catch (IOException e)
{
logger.error("Failed to parse: " + DEFAULT_FILE_NAME, e);
}
Element root = serverComments.getDocumentElement();
commentsList = root.getElementsByTagName("item");
}
public int getColumnCount()
{
return 2;
}
public int getRowCount()
{
return servers.size();
}
public String getColumnName(int col)
{
return columnNames[col];
}
public Object getValueAt(int row, int col)
{
String commentString = new String("");
if (col == 0) // Column 1 (Server name)
{
return servers.get(row);
}
else
{ // Column 2 (Comment)
int i = 0;
Element e = (Element) commentsList.item(i);
while ((i < commentsList.getLength())
&& (e.getAttribute("jid").equals(servers.get(row)) == false))
{
e = (Element) commentsList.item(i);
i++;
}
if (e.getAttribute("jid").equals(servers.get(row)))
{
commentString = e.getAttribute("comment");
}
return commentString;
}
}
}
}

@ -39,18 +39,56 @@ public class Resources
*/
public static String getString(String key)
{
String resourceString;
try
{
return RESOURCE_BUNDLE.getString(key);
}
resourceString = RESOURCE_BUNDLE.getString(key);
int mnemonicIndex = resourceString.indexOf('&');
if(mnemonicIndex > -1)
{
String firstPart = resourceString.substring(0, mnemonicIndex);
String secondPart = resourceString.substring(mnemonicIndex + 1);
resourceString = firstPart.concat(secondPart);
}
}
catch (MissingResourceException e)
{
return '!' + key + '!';
resourceString = '!' + key + '!';
}
return resourceString;
}
/**
* Returns an internationalized string corresponding to the given key.
* @param key The key of the string.
* @return An internationalized string corresponding to the given key.
*/
public static char getMnemonic(String key)
{
String resourceString;
try {
resourceString = RESOURCE_BUNDLE.getString(key);
int mnemonicIndex = resourceString.indexOf('&');
if(mnemonicIndex > -1)
{
return resourceString.charAt(mnemonicIndex + 1);
}
}
catch (MissingResourceException e)
{
return '!';
}
return '!';
}
/**
* Loads an image from a given image identifier.
* @param imageID The identifier of the image.

@ -14,6 +14,12 @@ Import-Package: org.osgi.framework,
net.java.sip.communicator.service.contactlist.event,
net.java.sip.communicator.service.gui,
net.java.sip.communicator.service.gui.event,
net.java.sip.communicator.service.fileaccess,
javax.naming,
javax.naming.directory,
javax.xml.parsers,
org.w3c.dom,
org.xml.sax,
javax.swing,
javax.swing.event,
javax.swing.table,
@ -27,4 +33,5 @@ Import-Package: org.osgi.framework,
javax.swing.filechooser,
javax.swing.tree,
javax.swing.undo,
javax.swing.border
javax.swing.border,
javax.net.ssl

@ -1,15 +1,35 @@
protocolName=Jabber
protocolDescription=The Jabber protocol
userID=Jabber id:
password=Password:
userID=Jabber id
username=Jabber username
password=Password
password2=Confirm password
rememberPassword=Remember password
userIDAndPassword=ID and Password
advancedOptions=Advanced Options
ovverideServerOps=Override server default options
cserver=Server
server=Connect Server
port=Port
sendKeepAlive=Send keep alive packets
existingAccount=* The account you entered is already installed.
newAccountTitle=Jabber new account registration
registerNewAccount=Register new account
registerNewAccountText=In case you don't have a Jabber account, click on this button to create a new one.
chooseTitle=Jabber new account server chooser
chooseServerText=Choose the server for your new account in the list below.
okLabel=&Ok
cancelLabel=C&ancel
chooseLabel=&Choose
serverColumn=Server
commentColumn=Comment
xmppError=XMPP Error
userExist=This user already exist on this server. Choose another user or server.
unknownXmppError=Unknown XMPP error. Verify that the server name is correct.
notSamePassword=The two entered password aren't the same.
commentsFile=classes/net/java/sip/communicator/plugin/jabberaccregwizz/resources/servercomments.xml
protocolIcon=resources/images/jabber/jabber16x16-online.png
pageImage=resources/images/jabber/jabber48x48.png

@ -0,0 +1,5 @@
<!-- This file lists the open Jabber servers registered with the XMPP Federation. The format of this file is defined by the Service Discovery protocol: http://www.xmpp.org/extensions/xep-0030.html ... To add your server to the list, register at https://www.xmpp.net/ -->
<query xmlns='http://jabber.org/protocol/disco#items'>
<item jid='jabber.org' comment='Jabber Software Foundation Server'/>
</query>
Loading…
Cancel
Save