Search in sources :

Example 66 with XmppStringprepException

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

the class ReceiveFileTransfer 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 67 with XmppStringprepException

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

the class BuzzRoomDecorator method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    Jid jid;
    try {
        jid = JidCreate.from(((ChatRoomImpl) chatRoom).getParticipantJID());
    } catch (XmppStringprepException exception) {
        throw new IllegalStateException(exception);
    }
    XMPPConnection connection = SparkManager.getConnection();
    Message message = connection.getStanzaFactory().buildMessageStanza().to(jid).addExtension(new AttentionExtension()).build();
    try {
        connection.sendStanza(message);
    } catch (SmackException.NotConnectedException | InterruptedException e1) {
        Log.warning("Unable to send stanza to " + jid, e1);
    }
    chatRoom.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.sent"), ChatManager.NOTIFICATION_COLOR);
    buzzButton.setEnabled(false);
    // Enable the button after 30 seconds to prevent abuse.
    final TimerTask enableTask = new SwingTimerTask() {

        @Override
        public void doRun() {
            buzzButton.setEnabled(true);
        }
    };
    TaskEngine.getInstance().schedule(enableTask, 30000);
}
Also used : SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) Jid(org.jxmpp.jid.Jid) Message(org.jivesoftware.smack.packet.Message) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) TimerTask(java.util.TimerTask) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) XMPPConnection(org.jivesoftware.smack.XMPPConnection) AttentionExtension(org.jivesoftware.smackx.attention.packet.AttentionExtension) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 68 with XmppStringprepException

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

the class PrivacyPresenceHandler method setIconsForItem.

private void setIconsForItem(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);
        }
        setBlockedIconToContact(jid);
        if (item.isFilterPresenceOut()) {
            sendUnavailableTo(jid);
        }
    }
    if (item.getType().equals(PrivacyItem.Type.group)) {
        ContactGroup group = SparkManager.getWorkspace().getContactList().getContactGroup(item.getValue());
        for (ContactItem contact : group.getContactItems()) {
            setBlockedIconToContact(contact.getJid());
            if (item.isFilterPresenceOut()) {
                sendUnavailableTo(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 69 with XmppStringprepException

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

the class TransportUtils method isRegistered.

/**
 * Checks if the user is registered with a gateway.
 *
 * @param con       the XMPPConnection.
 * @param transport the transport.
 * @return true if the user is registered with the transport.
 */
public static boolean isRegistered(XMPPConnection con, Transport transport) {
    if (!con.isConnected()) {
        return false;
    }
    ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con);
    try {
        Jid jid = JidCreate.from(transport.getXMPPServiceDomain());
        DiscoverInfo info = discoveryManager.discoverInfo(jid);
        return info.containsFeature("jabber:iq:registered");
    } catch (XMPPException | SmackException | XmppStringprepException | InterruptedException e) {
        Log.error(e);
    }
    return false;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Jid(org.jxmpp.jid.Jid) DomainBareJid(org.jxmpp.jid.DomainBareJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 70 with XmppStringprepException

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

the class ConferenceRoomBrowser method addTableListener.

private void addTableListener() {
    roomsTable.getSelectionModel().addListSelectionListener(e -> {
        if (e.getValueIsAdjusting())
            return;
        int selectedRow = roomsTable.getSelectedRow();
        if (selectedRow != -1) {
            joinRoomButton.setEnabled(true);
            joinRoomItem.setEnabled(true);
            String roomJIDString = roomsTable.getValueAt(selectedRow, 2) + "@" + serviceName;
            EntityBareJid roomJID;
            try {
                roomJID = JidCreate.entityBareFrom(roomJIDString);
            } catch (XmppStringprepException ex) {
                Log.error("Not a JID", ex);
                return;
            }
            addRoomButton.setEnabled(true);
            addRoomItem.setEnabled(true);
            addBookmarkUI(!isBookmarked(roomJID));
        } else {
            joinRoomButton.setEnabled(false);
            addRoomButton.setEnabled(false);
            joinRoomItem.setEnabled(false);
            addRoomItem.setEnabled(false);
            addBookmarkUI(true);
        }
    });
}
Also used : XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) EntityBareJid(org.jxmpp.jid.EntityBareJid)

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