Java 类org.jivesoftware.smackx.vcardtemp.packet.VCard 实例源码

项目:X-Messenger    文件:XMPPManager.java   
public void changeImage(final File file) {
    xmppQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            try {
                VCard vcard = new VCard();
                vcard.load(connection);

                byte[] bytes;

                bytes = getFileBytes(file);
                if(file == null)
                {vcard.removeAvatar();}
                else
                {vcard.setAvatar(bytes);}
                // FileLog.e("x-messenger", "changeImage "+vcard.getFirstName());
                vcard.save(connection);
                UserConfig.clientUserPhoto = file.getAbsolutePath();
                UserConfig.saveConfig(false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

}
项目:X-Messenger    文件:XMPPManager.java   
public VCard getUserVCard(String jid) {
    //ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp", new VCardProvider());

    VCard vCard = new VCard();

    try {
        vCard.load(XMPPManager.getInstance().getConnection(),JidCreate.entityBareFrom(jid/*+DOMAIN*/));
        VCardProvider vCardProvider = new VCardProvider();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return vCard;
}
项目:XMPPSample_Studio    文件:XMPP.java   
public void login(String user, String pass, StatusItem status, String username)
            throws XMPPException, SmackException, IOException, InterruptedException {
        Log.i(TAG, "inside XMPP getlogin Method");
        long l = System.currentTimeMillis();
        XMPPTCPConnection connect = connect();
        if (connect.isAuthenticated()) {
            Log.i(TAG, "User already logged in");
            return;
        }

        Log.i(TAG, "Time taken to connect: " + (System.currentTimeMillis() - l));

        l = System.currentTimeMillis();
        connect.login(user, pass);
        Log.i(TAG, "Time taken to login: " + (System.currentTimeMillis() - l));

        Log.i(TAG, "login step passed");

        Presence p = new Presence(Presence.Type.available);
        p.setMode(Presence.Mode.available);
        p.setPriority(24);
        p.setFrom(connect.getUser());
        if (status != null) {
            p.setStatus(status.toJSON());
        } else {
            p.setStatus(new StatusItem().toJSON());
        }
//        p.setTo("");
        VCard ownVCard = new VCard();
        ownVCard.load(connect);
        ownVCard.setNickName(username);
        ownVCard.save(connect);

        PingManager pingManager = PingManager.getInstanceFor(connect);
        pingManager.setPingInterval(150000);
        connect.sendPacket(p);


    }
项目:xmpp-service    文件:XmppServiceConnection.java   
private byte[] getAvatarFor(String remoteAccount) {
    try {
        VCardManager manager = VCardManager.getInstanceFor(mConnection);

        byte[] data;
        VCard card;
        if (remoteAccount == null || remoteAccount.isEmpty()) {
            card = manager.loadVCard();
        } else {
            card = manager.loadVCard(remoteAccount);
        }

        if (card == null) return null;

        data = card.getAvatar();

        if (data != null && data.length > 0) {
            return data;
        }

        return null;

    } catch (Exception exc) {
        Logger.debug(TAG, "Can't get vCard for " + remoteAccount);
        return null;
    }
}
项目:Smack    文件:VCardManager.java   
/**
 * Save this vCard for the user connected by 'connection'. XMPPConnection should be authenticated
 * and not anonymous.
 *
 * @throws XMPPErrorException thrown if there was an issue setting the VCard in the server.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException 
 */
public void saveVCard(VCard vcard) throws NoResponseException, XMPPErrorException, NotConnectedException {
    // XEP-54 § 3.2 "A user may publish or update his or her vCard by sending an IQ of type "set" with no 'to' address…"
    vcard.setTo(null);
    vcard.setType(IQ.Type.set);
    // Also make sure to generate a new stanza id (the given vcard could be a vcard result), in which case we don't
    // want to use the same stanza id again (although it wouldn't break if we did)
    vcard.setStanzaId(StanzaIdUtil.newStanzaId());
    connection().createPacketCollectorAndSend(vcard).nextResultOrThrow();
}
项目:Smack    文件:VCardProvider.java   
private static void parseAddress(XmlPullParser parser, VCard vCard) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();
    boolean isWork = true;
    outerloop: while (true) {
        int eventType = parser.next();
        switch (eventType) {
        case XmlPullParser.START_TAG:
            String name = parser.getName();
            if ("HOME".equals(name)) {
                isWork = false;
            }
            else {
                for (String adr : ADR) {
                    if (adr.equals(name)) {
                        if (isWork) {
                            vCard.setAddressFieldWork(name, parser.nextText());
                        }
                        else {
                            vCard.setAddressFieldHome(name, parser.nextText());
                        }
                    }
                }
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            break;
        }
    }
}
项目:Smack    文件:VCardProvider.java   
private static void parseOrg(XmlPullParser parser, VCard vCard) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();

    outerloop: while (true) {
        int eventType = parser.next();
        switch (eventType) {
        case XmlPullParser.START_TAG:
            String name = parser.getName();
            switch (name) {
            case "ORGNAME":
                vCard.setOrganization(parser.nextText());
                break;
            case "ORGUNIT":
                vCard.setOrganizationUnit(parser.nextText());
                break;
            default:
                break;
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            break;
        }
    }
}
项目:Smack    文件:VCardProvider.java   
private static void parseEmail(XmlPullParser parser, VCard vCard) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();
    boolean isWork = false;

    outerloop: while (true) {
        int eventType = parser.next();
        switch (eventType) {
        case XmlPullParser.START_TAG:
            String name = parser.getName();
            switch (name) {
            case "WORK":
                isWork = true;
                break;
            case "USERID":
                if (isWork) {
                    vCard.setEmailWork(parser.nextText());
                }
                else {
                    vCard.setEmailHome(parser.nextText());
                }
                break;
            default:
                break;
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            break;
        }
    }
}
项目:Smack    文件:VCardProvider.java   
private static void parseName(XmlPullParser parser, VCard vCard) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();

    outerloop: while (true) {
        int eventType = parser.next();
        switch (eventType) {
        case XmlPullParser.START_TAG:
            String name = parser.getName();
            switch (name) {
            case "FAMILY":
                vCard.setLastName(parser.nextText());
                break;
            case "GIVEN":
                vCard.setFirstName(parser.nextText());
                break;
            case "MIDDLE":
                vCard.setMiddleName(parser.nextText());
                break;
            case "PREFIX":
                vCard.setPrefix(parser.nextText());
                break;
            case "SUFFIX":
                vCard.setSuffix(parser.nextText());
                break;
            default:
                break;
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            break;

        }
    }
}
项目:Smack    文件:VCardProvider.java   
private static void parsePhoto(XmlPullParser parser, VCard vCard) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();
    String binval = null;
    String mimetype = null;

    outerloop: while (true) {
        int eventType = parser.next();
        switch (eventType) {
        case XmlPullParser.START_TAG:
            String name = parser.getName();
            switch (name) {
            case "BINVAL":
                binval = parser.nextText();
                break;
            case "TYPE":
                mimetype = parser.nextText();
                break;
            default:
                break;
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            break;
        }
    }

    if (binval == null || mimetype == null) {
        return;
    }

    vCard.setAvatar(binval, mimetype);
}
项目:Smack    文件:VCardProvider.java   
@Override
public VCard parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException,
                SmackException {
    VCard vCard = new VCard();
    String name = null;

    outerloop: while (true) {
        int eventType = parser.next();
        switch (eventType) {
        case XmlPullParser.START_TAG:
            name = parser.getName();
            switch (name) {
            case "N":
                parseName(parser, vCard);
                break;
            case "ORG":
                parseOrg(parser, vCard);
                break;
            case "TEL":
                parseTel(parser, vCard);
                break;
            case "ADR":
                parseAddress(parser, vCard);
                break;
            case "EMAIL":
                parseEmail(parser, vCard);
                break;
            case "NICKNAME":
                vCard.setNickName(parser.nextText());
                break;
            case "JABBERID":
                vCard.setJabberId(parser.nextText());
                break;
            case "PHOTO":
                parsePhoto(parser, vCard);
                break;
            default:
                break;
            }
            break;
        case XmlPullParser.TEXT:
            if (initialDepth + 1 == parser.getDepth()) {
                vCard.setField(name, parser.getText());
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            break;
        }
    }

    return vCard;
}
项目:Smack    文件:VCardProvider.java   
private static void parseTel(XmlPullParser parser, VCard vCard) throws XmlPullParserException, IOException {
    final int initialDepth = parser.getDepth();
    boolean isWork = true;
    String telLabel = null;

    outerloop: while (true) {
        int eventType = parser.next();
        switch (eventType) {
        case XmlPullParser.START_TAG:
            String name = parser.getName();
            if ("HOME".equals(name)) {
                isWork = false;
            }
            else {
                if (telLabel != null && "NUMBER".equals(name)) {
                    if (isWork) {
                        vCard.setPhoneWork(telLabel, parser.nextText());
                    }
                    else {
                        vCard.setPhoneHome(telLabel, parser.nextText());
                    }
                }
                else {
                    for (String tel : TEL) {
                        if (tel.equals(name)) {
                            telLabel = name;
                        }
                    }
                }
            }
            break;
        case XmlPullParser.END_TAG:
            if (parser.getDepth() == initialDepth) {
                break outerloop;
            }
            break;
        default:
            break;
        }
    }
}
项目:Zom-Android    文件:XmppConnection.java   
private boolean loadVCard (ContentResolver resolver, String jid)
{
    try {
            debug(TAG, "loading vcard for: " + jid);

            EntityBareJid bareJid = JidCreate.entityBareFrom(jid);

            VCardManager vCardManager = VCardManager.getInstanceFor(mConnection);
            VCard vCard = vCardManager.loadVCard(bareJid);

            Contact contact = mContactListManager.getContact(bareJid.toString());

            if (!TextUtils.isEmpty(vCard.getNickName()))
            {
                if (!vCard.getNickName().equals(contact.getName()))
                {
                    contact.setName(vCard.getNickName());
                    mContactListManager.doSetContactName(contact.getAddress().getBareAddress(), contact.getName());
                }

            }

            //check for a forwarding address
            if (vCard.getJabberId() != null && (!vCard.getJabberId().equals(bareJid.toString())))
            {
                contact.setForwardingAddress(vCard.getJabberId());

            }
            else
            {
                contact.setForwardingAddress(null);
            }

                // If VCard is loaded, then save the avatar to the personal folder.
            String avatarHash = vCard.getAvatarHash();

            if (avatarHash != null)
            {
                byte[] avatarBytes = vCard.getAvatar();

                if (avatarBytes != null)
                {

                    debug(TAG, "found avatar image in vcard for: " + bareJid.toString());
                    debug(TAG, "start avatar length: " + avatarBytes.length);

                    int rowsUpdated = DatabaseUtils.updateAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, avatarBytes, bareJid.toString());

                    if (rowsUpdated <= 0)
                        DatabaseUtils.insertAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, mProviderId, mAccountId, avatarBytes, avatarHash, bareJid.toString());

                    return true;
                }
            }



    } catch (Exception e) {

        debug(TAG, "err loading vcard: " + e.toString());

        if (e.getMessage() != null)
        {
            String streamErr = e.getMessage();

            if (streamErr != null && (streamErr.contains("404") || streamErr.contains("503")))
            {
                return false;
            }
        }

    }

    return false;
}
项目:Smack    文件:VCardManager.java   
/**
 * Load VCard information for a given user.
 *
 * @throws XMPPErrorException 
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException 
 */
public VCard loadVCard(String bareJid) throws NoResponseException, XMPPErrorException, NotConnectedException {
    VCard vcardRequest = new VCard();
    vcardRequest.setTo(bareJid);
    VCard result = connection().createPacketCollectorAndSend(vcardRequest).nextResultOrThrow();
    return result;
}
项目:Smack    文件:VCardManager.java   
/**
 * Load the VCard of the current user.
 *
 * @throws XMPPErrorException 
 * @throws NoResponseException 
 * @throws NotConnectedException 
 */
public VCard loadVCard() throws NoResponseException, XMPPErrorException, NotConnectedException {
    return loadVCard(null);
}