Search in sources :

Example 31 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class ConferenceAddFragment method addConference.

public void addConference() {
    Resourcepart nick;
    try {
        nick = Resourcepart.from(nickView.getText().toString().trim());
    } catch (XmppStringprepException e) {
        LogManager.exception(this, e);
        Toast.makeText(getActivity(), getString(R.string.EMPTY_NICK_NAME), Toast.LENGTH_LONG).show();
        return;
    }
    String password = passwordView.getText().toString();
    final boolean join = true;
    MUCManager.getInstance().createRoom(account, conferenceJid, nick, password, join);
    // add conference to bookmarks
    BookmarksManager.getInstance().addConferenceToBookmarks(account, conferenceJid.getLocalpart().toString(), conferenceJid, nick);
    try {
        startActivity(ChatActivity.createSpecificChatIntent(getActivity(), account, UserJid.from(conferenceJid)));
    } catch (UserJid.UserJidCreateException e) {
        LogManager.exception(this, e);
    }
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) Resourcepart(org.jxmpp.jid.parts.Resourcepart)

Example 32 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class ContactAddFragment method addContact.

@Override
public void addContact() {
    final AccountJid account = (AccountJid) accountView.getSelectedItem();
    if (account == null || getAccount() == null) {
        Toast.makeText(getActivity(), getString(R.string.EMPTY_ACCOUNT), Toast.LENGTH_LONG).show();
        return;
    }
    String contactString = userView.getText().toString();
    contactString = contactString.trim();
    if (contactString.contains(" ")) {
        userView.setError(getString(R.string.INCORRECT_USER_NAME));
        return;
    }
    if (TextUtils.isEmpty(contactString)) {
        userView.setError(getString(R.string.EMPTY_USER_NAME));
        return;
    }
    final UserJid user;
    try {
        EntityBareJid entityFullJid = JidCreate.entityBareFrom(contactString);
        user = UserJid.from(entityFullJid);
    } catch (XmppStringprepException | UserJid.UserJidCreateException e) {
        e.printStackTrace();
        userView.setError(getString(R.string.INCORRECT_USER_NAME));
        return;
    }
    if (listenerActivity != null)
        listenerActivity.showProgress(true);
    final String name = nameView.getText().toString();
    final ArrayList<String> groups = getSelected();
    Application.getInstance().runInBackgroundUserRequest(new Runnable() {

        @Override
        public void run() {
            try {
                RosterManager.getInstance().createContact(account, user, name, groups);
                PresenceManager.getInstance().requestSubscription(account, user);
            } catch (SmackException.NotLoggedInException | SmackException.NotConnectedException e) {
                Application.getInstance().onError(R.string.NOT_CONNECTED);
                stopAddContactProcess(false);
            } catch (XMPPException.XMPPErrorException e) {
                Application.getInstance().onError(R.string.XMPP_EXCEPTION);
                stopAddContactProcess(false);
            } catch (SmackException.NoResponseException e) {
                Application.getInstance().onError(R.string.CONNECTION_FAILED);
                stopAddContactProcess(false);
            } catch (NetworkException e) {
                Application.getInstance().onError(e);
                stopAddContactProcess(false);
            } catch (InterruptedException e) {
                LogManager.exception(this, e);
                stopAddContactProcess(false);
            }
            stopAddContactProcess(true);
        }
    });
}
Also used : SmackException(org.jivesoftware.smack.SmackException) UserJid(com.xabber.android.data.entity.UserJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) AccountJid(com.xabber.android.data.entity.AccountJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) NetworkException(com.xabber.android.data.NetworkException)

Example 33 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class ConferenceSelectFragment method onNextClick.

private void onNextClick() {
    if (account == null) {
        Toast.makeText(getActivity(), getString(R.string.EMPTY_ACCOUNT), Toast.LENGTH_SHORT).show();
        return;
    }
    DomainBareJid server;
    try {
        server = JidCreate.domainBareFrom(serverView.getText().toString());
    } catch (XmppStringprepException e) {
        Toast.makeText(getActivity(), getString(R.string.EMPTY_SERVER_NAME), Toast.LENGTH_SHORT).show();
        return;
    }
    Localpart room;
    try {
        room = Localpart.from(roomView.getText().toString());
    } catch (XmppStringprepException e) {
        Toast.makeText(getActivity(), getString(R.string.EMPTY_ROOM_NAME), Toast.LENGTH_LONG).show();
        return;
    }
    UserJid roomJid = null;
    try {
        roomJid = UserJid.from(JidCreate.entityBareFrom(room, server));
        startActivity(ConferenceAddActivity.createIntent(getActivity(), account, roomJid));
    } catch (UserJid.UserJidCreateException e) {
        LogManager.exception(this, e);
    }
}
Also used : Localpart(org.jxmpp.jid.parts.Localpart) UserJid(com.xabber.android.data.entity.UserJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) DomainBareJid(org.jxmpp.jid.DomainBareJid)

Example 34 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class XMPPAuthManager method addContactToRoster.

private void addContactToRoster(String apiJid, String clientJid) {
    UserJid user;
    AccountJid account;
    try {
        user = UserJid.from(apiJid);
        account = AccountJid.from(clientJid);
        RosterManager.getInstance().createContact(account, user, "xabber", Collections.EMPTY_LIST);
        PresenceManager.getInstance().requestSubscription(account, user, false);
    } catch (UserJid.UserJidCreateException | XmppStringprepException | InterruptedException | SmackException | NetworkException | XMPPException.XMPPErrorException e) {
        LogManager.exception(this, e);
        return;
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) SmackException(org.jivesoftware.smack.SmackException) UserJid(com.xabber.android.data.entity.UserJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NetworkException(com.xabber.android.data.NetworkException)

Example 35 with XmppStringprepException

use of org.jxmpp.stringprep.XmppStringprepException in project xabber-android by redsolution.

the class UploadService method startWork.

private void startWork(AccountJid account, UserJid user, List<String> filePaths, CharSequence uploadServerUrl, String existMessageId) {
    // get account item
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        publishError(null, "Account not found");
        return;
    }
    // get upload jid
    Jid uploadJid;
    try {
        uploadJid = JidCreate.bareFrom(uploadServerUrl);
    } catch (XmppStringprepException e) {
        publishError(null, "Wrong upload jid");
        return;
    }
    final String fileMessageId;
    if (existMessageId == null) {
        // create fileMessage with files
        List<File> files = new ArrayList<>();
        for (String filePath : filePaths) {
            files.add(new File(filePath));
        }
        fileMessageId = MessageManager.getInstance().createFileMessage(account, user, files);
    } else
        // use existing fileMessage
        fileMessageId = existMessageId;
    HashMap<String, String> uploadedFilesUrls = new HashMap<>();
    List<String> notUploadedFilesPaths = new ArrayList<>();
    List<File> notUploadedFiles = new ArrayList<>();
    List<String> errors = new ArrayList<>();
    for (String filePath : filePaths) {
        if (needStop) {
            stopWork(fileMessageId);
            return;
        }
        try {
            File uncompressedFile = new File(filePath);
            final File file;
            // compress file if image
            if (FileManager.fileIsImage(uncompressedFile) && SettingsManager.connectionCompressImage()) {
                file = ImageCompressor.compressImage(uncompressedFile, getCompressedDirPath());
                if (file == null)
                    throw new Exception("Compress image failed");
            } else
                file = uncompressedFile;
            // request slot
            Stanza slot = requestSlot(accountItem, file, uploadJid);
            if (!(slot instanceof Slot))
                throw new Exception("Could not request upload slot");
            // upload file
            Response response = uploadFileToSlot(account, (Slot) slot, file);
            if (response.isSuccessful())
                uploadedFilesUrls.put(filePath, ((Slot) slot).getGetUrl());
            else
                throw new Exception("Upload failed: " + response.message());
        } catch (Exception e) {
            notUploadedFilesPaths.add(filePath);
            notUploadedFiles.add(new File(filePath));
            errors.add(e.toString());
        }
        publishProgress(fileMessageId, uploadedFilesUrls.size(), filePaths.size());
    }
    removeTempDirectory();
    // check that files are uploaded
    if (uploadedFilesUrls.size() == 0) {
        setErrorForMessage(fileMessageId, generateErrorDescriptionForFiles(notUploadedFilesPaths, errors));
        publishError(fileMessageId, "Could not upload any files");
        return;
    }
    // save results to Realm and send message
    MessageManager.getInstance().updateFileMessage(account, user, fileMessageId, uploadedFilesUrls, notUploadedFilesPaths);
    publishCompleted(fileMessageId);
    // if some files have errors move its to separate message
    if (notUploadedFilesPaths.size() > 0) {
        String messageId = MessageManager.getInstance().createFileMessage(account, user, notUploadedFiles);
        setErrorForMessage(messageId, generateErrorDescriptionForFiles(notUploadedFilesPaths, errors));
    }
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) AccountItem(com.xabber.android.data.account.AccountItem) HashMap(java.util.HashMap) Stanza(org.jivesoftware.smack.packet.Stanza) ArrayList(java.util.ArrayList) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) SmackException(org.jivesoftware.smack.SmackException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XMPPException(org.jivesoftware.smack.XMPPException) Response(okhttp3.Response) Slot(com.xabber.xmpp.httpfileupload.Slot) File(java.io.File)

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