Search in sources :

Example 11 with VCard

use of org.jivesoftware.smackx.vcardtemp.packet.VCard in project Smack by igniterealtime.

the class VCardTest method testNoWorkHomeSpecifier_ADDR.

@Test
public void testNoWorkHomeSpecifier_ADDR() throws Throwable {
    // @formatter:off
    final String request = "<iq id='v1' to='user@igniterealtime.org/mobile' type='result'>" + "<vCard xmlns='vcard-temp'><ADR><STREET>Some street</STREET><FF>ddss</FF></ADR></vCard>" + "</iq>";
    // @formatter:on
    VCard vCard = (VCard) PacketParserUtils.parseStanza(request);
    assertEquals("Some street", vCard.getAddressFieldWork("STREET"));
    assertEquals("ddss", vCard.getAddressFieldWork("FF"));
}
Also used : VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard) Test(org.junit.Test)

Example 12 with VCard

use of org.jivesoftware.smackx.vcardtemp.packet.VCard in project Smack by igniterealtime.

the class VCardTest method testFN.

@Test
public void testFN() throws Throwable {
    // @formatter:off
    final String request = "<iq id='v1' to='user@igniterealtime.org/mobile' type='result'>" + "<vCard xmlns='vcard-temp'><FN>kir max</FN></vCard>" + "</iq>";
    // @formatter:on
    VCard vCard = (VCard) PacketParserUtils.parseStanza(request);
    assertEquals("kir max", vCard.getField("FN"));
}
Also used : VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard) Test(org.junit.Test)

Example 13 with VCard

use of org.jivesoftware.smackx.vcardtemp.packet.VCard in project Smack by igniterealtime.

the class VCardTest method testNoWorkHomeSpecifier_TEL.

@Test
public void testNoWorkHomeSpecifier_TEL() throws Throwable {
    // @formatter:off
    final String request = "<iq id='v1' to='user@igniterealtime.org/mobile' type='result'>" + "<vCard xmlns='vcard-temp'><TEL><FAX/><NUMBER>3443233</NUMBER></TEL></vCard>" + "</iq>";
    // @formatter:on
    VCard vCard = (VCard) PacketParserUtils.parseStanza(request);
    assertEquals("3443233", vCard.getPhoneWork("FAX"));
}
Also used : VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard) Test(org.junit.Test)

Example 14 with VCard

use of org.jivesoftware.smackx.vcardtemp.packet.VCard in project Smack by igniterealtime.

the class VCardTest method testUnknownTopLevelElementAdded.

@Test
public void testUnknownTopLevelElementAdded() throws Throwable {
    // @formatter:off
    final String request = "<iq id='v1' to='user@igniterealtime.org/mobile' type='result'>" + "<vCard xmlns='vcard-temp'><UNKNOWN>1234</UNKNOWN></vCard>" + "</iq>";
    // @formatter:on
    VCard vCard = (VCard) PacketParserUtils.parseStanza(request);
    assertEquals("1234", vCard.getField("UNKNOWN"));
}
Also used : VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard) Test(org.junit.Test)

Example 15 with VCard

use of org.jivesoftware.smackx.vcardtemp.packet.VCard in project xabber-android by redsolution.

the class VCardManager method requestVCard.

private void requestVCard(final String account, final String srcUser) {
    final String userBareJid = srcUser;
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    ConnectionThread connectionThread = accountItem.getConnectionThread();
    if (!accountItem.getFactualStatusMode().isOnline() || connectionThread == null) {
        onVCardFailed(account, userBareJid);
        return;
    }
    final org.jivesoftware.smackx.vcardtemp.VCardManager vCardManager = org.jivesoftware.smackx.vcardtemp.VCardManager.getInstanceFor(connectionThread.getXMPPConnection());
    final Thread thread = new Thread("Get vCard user " + userBareJid + " for account " + account) {

        @Override
        public void run() {
            VCard vCard = null;
            vCardRequests.add(userBareJid);
            try {
                vCard = vCardManager.loadVCard(userBareJid);
            } catch (SmackException.NoResponseException | SmackException.NotConnectedException e) {
                LogManager.w(this, "Error getting vCard: " + e.getMessage());
            } catch (XMPPException.XMPPErrorException e) {
                LogManager.w(this, "XMPP error getting vCard: " + e.getMessage() + e.getXMPPError());
                if (e.getXMPPError().getCondition() == XMPPError.Condition.item_not_found) {
                    vCard = new VCard();
                }
            } catch (ClassCastException e) {
                // http://stackoverflow.com/questions/31498721/error-loading-vcard-information-using-smack-emptyresultiq-cannot-be-cast-to-or
                LogManager.w(this, "ClassCastException: " + e.getMessage());
                vCard = new VCard();
            }
            vCardRequests.remove(userBareJid);
            final VCard finalVCard = vCard;
            Application.getInstance().runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (finalVCard == null) {
                        onVCardFailed(account, userBareJid);
                    } else {
                        onVCardReceived(account, userBareJid, finalVCard);
                    }
                }
            });
        }
    };
    thread.start();
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ConnectionThread(com.xabber.android.data.connection.ConnectionThread) ConnectionThread(com.xabber.android.data.connection.ConnectionThread) XMPPException(org.jivesoftware.smack.XMPPException) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard)

Aggregations

VCard (org.jivesoftware.smackx.vcardtemp.packet.VCard)16 Test (org.junit.Test)10 AccountItem (com.xabber.android.data.account.AccountItem)2 ContactVcardViewerFragment (com.xabber.android.ui.fragment.ContactVcardViewerFragment)2 XMPPException (org.jivesoftware.smack.XMPPException)2 Intent (android.content.Intent)1 ConnectionThread (com.xabber.android.data.connection.ConnectionThread)1 UserJid (com.xabber.android.data.entity.UserJid)1 IOException (java.io.IOException)1 SmackException (org.jivesoftware.smack.SmackException)1 EntityBareJid (org.jxmpp.jid.EntityBareJid)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1