Search in sources :

Example 11 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.

the class RosterDialog method addEntry.

private void addEntry() {
    Transport transport = null;
    AccountItem item;
    if (publicBox.isSelected()) {
        item = (AccountItem) accounts.getSelectedItem();
        transport = item.getTransport();
    }
    if (transport == null) {
        String jid = getJID();
        if (!jid.contains("@")) {
            jid = jid + "@" + SparkManager.getConnection().getXMPPServiceDomain();
        }
        String nickname = nicknameField.getText();
        String group = (String) groupBox.getSelectedItem();
        jid = UserManager.escapeJID(jid);
        BareJid bareJid;
        try {
            bareJid = JidCreate.bareFrom(jid);
        } catch (XmppStringprepException e) {
            throw new IllegalStateException(e);
        }
        // Add as a new entry
        addRosterEntry(bareJid, nickname, group);
    } else {
        String jid = getJID();
        try {
            jid = Gateway.getJID(transport.getXMPPServiceDomain(), jid);
        } catch (SmackException | InterruptedException e) {
            Log.error(e);
        }
        String nickname = nicknameField.getText();
        String group = (String) groupBox.getSelectedItem();
        BareJid bareJid;
        try {
            bareJid = JidCreate.bareFrom(jid);
        } catch (XmppStringprepException e) {
            throw new IllegalStateException(e);
        }
        addRosterEntry(bareJid, nickname, group);
    }
}
Also used : DomainBareJid(org.jxmpp.jid.DomainBareJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) BareJid(org.jxmpp.jid.BareJid) SmackException(org.jivesoftware.smack.SmackException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Transport(org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport)

Example 12 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.

the class BookmarksUI method browseRooms.

public void browseRooms(String serviceNameString) {
    DomainBareJid serviceName;
    try {
        serviceName = JidCreate.domainBareFrom(serviceNameString);
    } catch (XmppStringprepException e) {
        throw new IllegalStateException(e);
    }
    browseRooms(serviceName);
}
Also used : XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 13 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.

the class BookmarksUI method getServicePanel.

private JPanel getServicePanel() {
    final JPanel servicePanel = new JPanel();
    servicePanel.setOpaque(false);
    servicePanel.setLayout(new GridBagLayout());
    final JLabel serviceLabel = new JLabel();
    final RolloverButton addButton = new RolloverButton(SparkRes.getImageIcon(SparkRes.SMALL_ADD_IMAGE));
    addButton.setToolTipText(Res.getString("message.add.conference.service"));
    final JTextField serviceField = new JTextField();
    servicePanel.add(serviceLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 2, 5), 0, 0));
    servicePanel.add(serviceField, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 2, 5), 0, 0));
    servicePanel.add(addButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 2, 5), 0, 0));
    // Add resource utils
    ResourceUtils.resLabel(serviceLabel, serviceField, Res.getString("label.add.conference.service"));
    final Action conferenceAction = new AbstractAction() {

        private static final long serialVersionUID = 7973928300442518496L;

        @Override
        public void actionPerformed(ActionEvent e) {
            final String conferenceService = serviceField.getText();
            if (hasService(conferenceService)) {
                UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                JOptionPane.showMessageDialog(null, Res.getString("message.service.already.exists"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
                serviceField.setText("");
            } else {
                final List<DomainBareJid> serviceList = new ArrayList<>();
                serviceField.setText(Res.getString("message.searching.please.wait"));
                serviceField.setEnabled(false);
                addButton.setEnabled(false);
                SwingWorker worker = new SwingWorker() {

                    DiscoverInfo discoInfo;

                    @Override
                    public Object construct() {
                        XMPPConnection connection = SparkManager.getConnection();
                        ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
                        try {
                            DomainBareJid conferenceServiceJid = JidCreate.domainBareFrom(conferenceService);
                            discoInfo = discoManager.discoverInfo(conferenceServiceJid);
                            for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) {
                                if ("conference".equals(identity.getCategory())) {
                                    serviceList.add(conferenceServiceJid);
                                    break;
                                } else if ("server".equals(identity.getCategory())) {
                                    try {
                                        Collection<DomainBareJid> services = getConferenceServices(conferenceServiceJid);
                                        serviceList.addAll(services);
                                    } catch (Exception e1) {
                                        Log.error("Unable to load conference services in server.", e1);
                                    }
                                }
                            }
                        } catch (XMPPException | SmackException | XmppStringprepException | InterruptedException e1) {
                            Log.error("Error in disco discovery.", e1);
                        }
                        return true;
                    }

                    @Override
                    public void finished() {
                        if (discoInfo != null) {
                            for (DomainBareJid aServiceList : serviceList) {
                                if (!hasService(aServiceList)) {
                                    addServiceToList(aServiceList);
                                }
                            }
                        } else {
                            UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                            JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.conference.service.error"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
                        }
                        serviceField.setText("");
                        serviceField.setEnabled(true);
                        addButton.setEnabled(true);
                    }
                };
                worker.start();
            }
        }
    };
    addButton.addActionListener(conferenceAction);
    serviceField.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                conferenceAction.actionPerformed(null);
            }
        }
    });
    return servicePanel;
}
Also used : XMPPConnection(org.jivesoftware.smack.XMPPConnection) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) RolloverButton(org.jivesoftware.spark.component.RolloverButton) DomainBareJid(org.jxmpp.jid.DomainBareJid) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) SmackException(org.jivesoftware.smack.SmackException) SmackException(org.jivesoftware.smack.SmackException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) XMPPException(org.jivesoftware.smack.XMPPException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) SwingWorker(org.jivesoftware.spark.util.SwingWorker) XMPPException(org.jivesoftware.smack.XMPPException)

Example 14 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.

the class UriManager method handleRemove.

/**
 * Handles the ?remove URI
 *
 * @param uri
 *            the decoded uri
 * @throws Exception
 */
public void handleRemove(URI uri) throws Exception {
    // xmpp:romeo@montague.net?remove
    BareJid jid;
    try {
        jid = JidCreate.bareFrom(retrieveJID(uri));
    } catch (XmppStringprepException e) {
        throw new IllegalStateException(e);
    }
    Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
    RosterEntry entry = roster.getEntry(jid);
    roster.removeEntry(entry);
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) BareJid(org.jxmpp.jid.BareJid) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 15 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project Spark by igniterealtime.

the class UriManager method handleRoster.

/**
 * Handles the ?roster URI<br>
 * with name= and group=
 *
 * @param uri
 *            the decoded uri
 * @throws Exception
 */
public void handleRoster(URI uri) throws Exception {
    // xmpp:romeo@montague.net?roster
    // xmpp:romeo@montague.net?roster;name=Romeo%20Montague
    // xmpp:romeo@montague.net?roster;group=Friends
    // xmpp:romeo@montague.net?roster;name=Romeo%20Montague;group=Friends
    BareJid jid;
    try {
        jid = JidCreate.bareFrom(retrieveJID(uri));
    } catch (XmppStringprepException e) {
        throw new IllegalStateException(e);
    }
    String name = "";
    String query = uri.getQuery();
    if (query.contains("name=")) {
        StringBuilder buf = new StringBuilder();
        int x = query.indexOf("name=") + 5;
        while (x < query.length() && query.charAt(x) != ';') {
            buf.append(query.charAt(x));
            x++;
        }
    }
    String group = "";
    if (query.contains("group=")) {
        StringBuilder buf = new StringBuilder();
        int x = query.indexOf("group=") + 6;
        while (x < query.length() && query.charAt(x) != ';') {
            buf.append(query.charAt(x));
            x++;
        }
    }
    Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
    RosterEntry userEntry = roster.getEntry(jid);
    roster.createEntry(jid, name, new String[] { group });
    RosterGroup rosterGroup = roster.getGroup(group);
    if (rosterGroup == null) {
        rosterGroup = roster.createGroup(group);
    }
    if (userEntry == null) {
        roster.createEntry(jid, name, new String[] { group });
    } else {
        userEntry.setName(name);
        rosterGroup.addEntry(userEntry);
    }
}
Also used : Roster(org.jivesoftware.smack.roster.Roster) BareJid(org.jxmpp.jid.BareJid) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) RosterGroup(org.jivesoftware.smack.roster.RosterGroup)

Aggregations

XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)76 DomainBareJid (org.jxmpp.jid.DomainBareJid)20 SmackException (org.jivesoftware.smack.SmackException)18 Jid (org.jxmpp.jid.Jid)18 EntityBareJid (org.jxmpp.jid.EntityBareJid)16 AccountJid (com.xabber.android.data.entity.AccountJid)12 XMPPException (org.jivesoftware.smack.XMPPException)12 UserJid (com.xabber.android.data.entity.UserJid)11 BareJid (org.jxmpp.jid.BareJid)9 Resourcepart (org.jxmpp.jid.parts.Resourcepart)9 ArrayList (java.util.ArrayList)8 Localpart (org.jxmpp.jid.parts.Localpart)8 Cursor (android.database.Cursor)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 HashMap (java.util.HashMap)5 SwingWorker (org.jivesoftware.spark.util.SwingWorker)5 IOException (java.io.IOException)4 KeyManagementException (java.security.KeyManagementException)4 NetworkException (com.xabber.android.data.NetworkException)3 InetAddress (java.net.InetAddress)3