Search in sources :

Example 16 with XmppStringprepException

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

the class SendFileTransfer method saveEventToHistory.

/**
 * Adds an event text as a message to transcript and saves it to history
 * @param eventText Contains file transfer event text
 */
private void saveEventToHistory(String eventText) {
    try {
        Message message = new Message(nickname, eventText);
        message.setFrom(SparkManager.getSessionManager().getJID());
        chatRoom.addToTranscript(message, false);
        SparkManager.getWorkspace().getTranscriptPlugin().persistChatRoom(chatRoom);
    } catch (XmppStringprepException e) {
        e.printStackTrace();
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException)

Example 17 with XmppStringprepException

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

the class PrivacyPresenceHandler method removeIconsForItem.

private void removeIconsForItem(PrivacyItem item) throws SmackException.NotConnectedException {
    if (item.getType().equals(PrivacyItem.Type.jid)) {
        Jid jid;
        try {
            jid = JidCreate.from(item.getValue());
        } catch (XmppStringprepException e) {
            throw new IllegalStateException(e);
        }
        removeBlockedIconFromContact(jid);
        if (item.isFilterPresenceOut()) {
            sendRealPresenceTo(jid);
        }
    }
    if (item.getType().equals(PrivacyItem.Type.group)) {
        ContactGroup group = SparkManager.getWorkspace().getContactList().getContactGroup(item.getValue());
        for (ContactItem contact : group.getContactItems()) {
            removeBlockedIconFromContact(contact.getJid());
            if (item.isFilterPresenceOut()) {
                sendRealPresenceTo(contact.getJid());
            }
        }
    }
}
Also used : Jid(org.jxmpp.jid.Jid) ContactItem(org.jivesoftware.spark.ui.ContactItem) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) ContactGroup(org.jivesoftware.spark.ui.ContactGroup)

Example 18 with XmppStringprepException

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

the class JabberBrowser method browse.

private void browse(String serviceNameString) {
    Jid serviceName;
    try {
        serviceName = JidCreate.from(serviceNameString);
    } catch (XmppStringprepException e) {
        throw new IllegalStateException(e);
    }
    browsePanel.removeAll();
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(con);
    DiscoverItems result;
    try {
        result = discoManager.discoverItems(serviceName);
    } catch (XMPPException | SmackException | InterruptedException e) {
        Log.error(e);
        return;
    }
    addAddress(serviceName.toString());
    for (DiscoverItems.Item item : result.getItems()) {
        Entity entity = new Entity(item);
        browsePanel.add(entity);
    }
    browsePanel.invalidate();
    browsePanel.validate();
    browsePanel.repaint();
}
Also used : Jid(org.jxmpp.jid.Jid) SmackException(org.jivesoftware.smack.SmackException) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) XMPPException(org.jivesoftware.smack.XMPPException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 19 with XmppStringprepException

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

the class VCardManager method reloadVCard.

/**
 * Forces a reload of a <code>VCard</code>. To load a VCard you should use
 * getVCard(String jid) instead. This method will perform a network lookup
 * which could take some time. If you're having problems with request
 * timeout you should also use getVCard(String jid). Use addToQueue(String
 * jid) if you want VCardManager to update the VCard by the given jid. The
 * method will block until the result is available or a timeout occurs.
 *
 * @param jidString the JID of the user.
 *
 * @return the new network vCard or a vCard with an error
 */
public VCard reloadVCard(BareJid jidString) {
    EntityBareJid jid;
    try {
        jid = JidCreate.entityBareFrom(jidString);
    } catch (XmppStringprepException e) {
        throw new IllegalStateException(e);
    }
    VCard vcard = new VCard();
    try {
        vcard = org.jivesoftware.smackx.vcardtemp.VCardManager.getInstanceFor(SparkManager.getConnection()).loadVCard(jid);
        vcard.setJabberId(jid.toString());
        if (vcard.getNickName() != null && vcard.getNickName().length() > 0) {
            // update nickname.
            ContactItem item = SparkManager.getWorkspace().getContactList().getContactItemByJID(jid.toString());
            item.setNickname(vcard.getNickName());
        // TODO: this doesn't work if someone removes his nickname. If we remove it in that case, it will cause problems with people using another way to manage their nicknames.
        }
        addVCard(jid, vcard);
        persistVCard(jid, vcard);
    } catch (XMPPException | SmackException | InterruptedException e) {
        // //System.out.println(jid+" Fehler in reloadVCard ----> null");
        StanzaError.Builder errorBuilder = StanzaError.getBuilder(StanzaError.Condition.resource_constraint);
        vcard.setError(errorBuilder);
        vcard.setJabberId(jid.toString());
        delayedContacts.add(jid);
        return vcard;
    // We dont want cards with error
    // vcard.setError(new StanzaError(XMPPError.Condition.request_timeout));
    // addVCard(jid, vcard);
    }
    return vcard;
}
Also used : ContactItem(org.jivesoftware.spark.ui.ContactItem) SmackException(org.jivesoftware.smack.SmackException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) XMPPException(org.jivesoftware.smack.XMPPException) EntityBareJid(org.jxmpp.jid.EntityBareJid) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard)

Example 20 with XmppStringprepException

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

the class VCardManager method initializeUI.

/**
 * Adds VCard capabilities to menus and other components in Spark.
 */
private void initializeUI() {
    // See if we should disable the "Edit my profile" option under "File"
    if (Default.getBoolean(Default.DISABLE_EDIT_PROFILE) || !Enterprise.containsFeature(Enterprise.VCARD_FEATURE))
        return;
    // Add Actions Menu
    final JMenu contactsMenu = SparkManager.getMainWindow().getMenuByName(Res.getString("menuitem.contacts"));
    final JMenu communicatorMenu = SparkManager.getMainWindow().getJMenuBar().getMenu(0);
    JMenuItem editProfileMenu = new JMenuItem(SparkRes.getImageIcon(SparkRes.SMALL_BUSINESS_MAN_VIEW));
    ResourceUtils.resButton(editProfileMenu, Res.getString("menuitem.edit.my.profile"));
    int size = contactsMenu.getMenuComponentCount();
    communicatorMenu.insert(editProfileMenu, 1);
    editProfileMenu.addActionListener(e -> {
        SwingWorker vcardLoaderWorker = new SwingWorker() {

            @Override
            public Object construct() {
                try {
                    final org.jivesoftware.smackx.vcardtemp.VCardManager smackVCardManager = org.jivesoftware.smackx.vcardtemp.VCardManager.getInstanceFor(SparkManager.getConnection());
                    personalVCard = smackVCardManager.loadVCard();
                } catch (XMPPException | SmackException | InterruptedException e) {
                    Log.error("Error loading vcard information.", e);
                }
                return true;
            }

            @Override
            public void finished() {
                editor.editProfile(personalVCard, SparkManager.getWorkspace());
                personalVCardAvatar = null;
                personalVCardHash = null;
            }
        };
        vcardLoaderWorker.start();
    });
    JMenuItem viewProfileMenu = new JMenuItem("", SparkRes.getImageIcon(SparkRes.FIND_TEXT_IMAGE));
    ResourceUtils.resButton(viewProfileMenu, Res.getString("menuitem.lookup.profile"));
    contactsMenu.insert(viewProfileMenu, size > 0 ? size - 3 : 0);
    viewProfileMenu.addActionListener(e -> {
        String jidToView = JOptionPane.showInputDialog(SparkManager.getMainWindow(), Res.getString("message.enter.jabber.id") + ":", Res.getString("title.lookup.profile"), JOptionPane.QUESTION_MESSAGE);
        if (ModelUtil.hasLength(jidToView) && jidToView.contains("@") && ModelUtil.hasLength(XmppStringUtils.parseDomain(jidToView))) {
            BareJid bareJid;
            try {
                bareJid = JidCreate.bareFrom(jidToView);
            } catch (XmppStringprepException e1) {
                throw new IllegalStateException(e1);
            }
            viewProfile(bareJid, SparkManager.getWorkspace());
        } else if (ModelUtil.hasLength(jidToView)) {
            UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
            JOptionPane.showMessageDialog(SparkManager.getMainWindow(), Res.getString("message.invalid.jabber.id"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
        }
    });
}
Also used : EntityBareJid(org.jxmpp.jid.EntityBareJid) BareJid(org.jxmpp.jid.BareJid) SmackException(org.jivesoftware.smack.SmackException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) XMPPException(org.jivesoftware.smack.XMPPException)

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