當前位置: 首頁>>代碼示例>>Java>>正文


Java Presence.getExtension方法代碼示例

本文整理匯總了Java中org.jivesoftware.smack.packet.Presence.getExtension方法的典型用法代碼示例。如果您正苦於以下問題:Java Presence.getExtension方法的具體用法?Java Presence.getExtension怎麽用?Java Presence.getExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jivesoftware.smack.packet.Presence的用法示例。


在下文中一共展示了Presence.getExtension方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Occupant

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
Occupant(Presence presence) {
    MUCUser mucUser = (MUCUser) presence.getExtension("x",
            "http://jabber.org/protocol/muc#user");
    MUCItem item = mucUser.getItem();
    this.jid = item.getJid();
    this.affiliation = item.getAffiliation();
    this.role = item.getRole();
    // Get the nickname from the FROM attribute of the presence
    this.nick = XmppStringUtils.parseResource(presence.getFrom());
}
 
開發者ID:TTalkIM,項目名稱:Smack,代碼行數:11,代碼來源:Occupant.java

示例2: Occupant

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
Occupant(Presence presence) {
    super();
    MUCUser mucUser = (MUCUser) presence.getExtension("x",
            "http://jabber.org/protocol/muc#user");
    MUCUser.Item item = mucUser.getItem();
    this.jid = item.getJid();
    this.affiliation = item.getAffiliation();
    this.role = item.getRole();
    // Get the nickname from the FROM attribute of the presence
    this.nick = StringUtils.parseResource(presence.getFrom());
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:12,代碼來源:Occupant.java

示例3: interceptPacket

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void interceptPacket(Packet packet) {
    Presence presence = (Presence) packet;
    // Check if user is joining a room
    if (Presence.Type.available == presence.getType() &&
            presence.getExtension("x", "http://jabber.org/protocol/muc") != null) {
        // Add extension that indicates that user wants to be a deaf occupant
        packet.addExtension(new DeafExtension());
    }
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:10,代碼來源:DeafOccupantInterceptor.java

示例4: createSubscribed

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private Stanza createSubscribed(Presence p) {
    ExtensionElement _pkey = p.getExtension(PublicKeyPresence.ELEMENT_NAME, PublicKeyPresence.NAMESPACE);

    try {

        if (_pkey instanceof PublicKeyPresence) {
            PublicKeyPresence pkey = (PublicKeyPresence) _pkey;

            byte[] keydata = pkey.getKey();
            // just to ensure it's valid data
            PGP.readPublicKeyring(keydata);

            String jid = p.getFrom().asBareJid().toString();
            // store key to users table
            Keyring.setKey(getContext(), jid, keydata, MyUsers.Keys.TRUST_VERIFIED);
        }

        Presence p2 = new Presence(Presence.Type.subscribed);
        p2.setTo(p.getFrom());
        return p2;

    }
    catch (Exception e) {
        Log.w(MessageCenterService.TAG, "unable to accept subscription from user", e);
        // TODO should we notify the user about this?
        // TODO throw new PGPException(...)
        return null;
    }
}
 
開發者ID:kontalk,項目名稱:androidclient,代碼行數:30,代碼來源:PresenceListener.java

示例5: Occupant

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
Occupant(Presence presence) {
	super();
	MUCUser mucUser = (MUCUser) presence.getExtension("x",
			"http://jabber.org/protocol/muc#user");
	MUCUser.Item item = mucUser.getItem();
	this.jid = item.getJid();
	this.affiliation = item.getAffiliation();
	this.role = item.getRole();
	// Get the nickname from the FROM attribute of the presence
	this.nick = StringUtils.parseResource(presence.getFrom());
}
 
開發者ID:ikantech,項目名稱:xmppsupport_v2,代碼行數:12,代碼來源:Occupant.java

示例6: interceptPacket

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void interceptPacket(Packet packet) {
	Presence presence = (Presence) packet;
	// Check if user is joining a room
	if (Presence.Type.available == presence.getType()
			&& presence.getExtension("x", "http://jabber.org/protocol/muc") != null) {
		// Add extension that indicates that user wants to be a deaf
		// occupant
		packet.addExtension(new DeafExtension());
	}
}
 
開發者ID:ikantech,項目名稱:xmppsupport_v2,代碼行數:11,代碼來源:DeafOccupantInterceptor.java

示例7: processPacket

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void processPacket(Packet packet)
{
    Presence presence = (Presence) packet;
    String iqString = presence.toString();
    final PacketExtension extension = presence.getExtension("http://jabber.org/protocol/caps");
    
    if (extension != null)
        System.out.println("T" + System.currentTimeMillis() + " Pres: " + iqString + ": " + presence.toXML());
}
 
開發者ID:alessandroleite,項目名稱:dohko,代碼行數:10,代碼來源:Client.java

示例8: createSubscribe

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private Packet createSubscribe(Presence p) {
    PacketExtension _pkey = p.getExtension(SubscribePublicKey.ELEMENT_NAME, SubscribePublicKey.NAMESPACE);

    try {

        if (_pkey instanceof SubscribePublicKey) {
            SubscribePublicKey pkey = (SubscribePublicKey) _pkey;

            PGPPublicKeyRing pubRing = PGP.readPublicKeyring(pkey.getKey());
            PGPPublicKey publicKey = PGP.getMasterKey(pubRing);
            String fingerprint = MessageUtils.bytesToHex(publicKey.getFingerprint());

            // store key to users table
            String userId = StringUtils.parseName(p.getFrom());
            UsersProvider.setUserKey(getContext(), userId,
                pkey.getKey(), fingerprint);
        }

        Presence p2 = new Presence(Presence.Type.subscribed);
        p2.setTo(p.getFrom());
        return p2;

    }
    catch (Exception e) {
        Log.w(MessageCenterService.TAG, "unable add user to whitelist", e);
        // TODO should we notify the user about this?
        // TODO throw new PGPException(...)
        return null;
    }
}
 
開發者ID:ShadiNachat,項目名稱:Chatting-App-,代碼行數:31,代碼來源:PresenceListener.java

示例9: createIntent

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public static Intent createIntent(Context ctx, Presence p, RosterEntry entry) {
    Intent i = new Intent(ACTION_PRESENCE);
    Presence.Type type = p.getType();
    i.putExtra(EXTRA_TYPE, type != null ? type.name() : Presence.Type.available.name());
    i.putExtra(EXTRA_PACKET_ID, p.getStanzaId());

    i.putExtra(EXTRA_FROM, StringUtils.maybeToString(p.getFrom().toString()));
    i.putExtra(EXTRA_TO, StringUtils.maybeToString(p.getTo()));
    i.putExtra(EXTRA_STATUS, p.getStatus());
    Presence.Mode mode = p.getMode();
    i.putExtra(EXTRA_SHOW, mode != null ? mode.name() : Presence.Mode.available.name());
    i.putExtra(EXTRA_PRIORITY, p.getPriority());

    String jid = p.getFrom().asBareJid().toString();

    long timestamp;
    DelayInformation delay = p.getExtension(DelayInformation.ELEMENT, DelayInformation.NAMESPACE);
    if (delay != null) {
        timestamp = delay.getStamp().getTime();
    }
    else {
        // try last seen from database
        timestamp = UsersProvider.getLastSeen(ctx, jid);
        if (timestamp < 0)
            timestamp = System.currentTimeMillis();
    }

    i.putExtra(EXTRA_STAMP, timestamp);

    // public key fingerprint
    String fingerprint = PublicKeyPresence.getFingerprint(p);
    if (fingerprint == null) {
        // try untrusted fingerprint from database
        fingerprint = Keyring.getFingerprint(ctx, jid, MyUsers.Keys.TRUST_UNKNOWN);
    }
    i.putExtra(EXTRA_FINGERPRINT, fingerprint);

    // subscription information
    if (entry != null) {
        i.putExtra(EXTRA_ROSTER_NAME, entry.getName());

        RosterPacket.ItemType subscriptionType = entry.getType();
        i.putExtra(EXTRA_SUBSCRIBED_FROM, subscriptionType == RosterPacket.ItemType.both ||
            subscriptionType == RosterPacket.ItemType.from);
        i.putExtra(EXTRA_SUBSCRIBED_TO, subscriptionType == RosterPacket.ItemType.both ||
            subscriptionType == RosterPacket.ItemType.to);
    }

    return i;
}
 
開發者ID:kontalk,項目名稱:androidclient,代碼行數:51,代碼來源:PresenceListener.java

示例10: updateUsersDatabase

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
@SuppressWarnings("WeakerAccess")
int updateUsersDatabase(Presence p) {
    String jid = p.getFrom().asBareJid().toString();

    ContentValues values = new ContentValues(4);
    values.put(Users.REGISTERED, 1);

    // status
    String status = p.getStatus();
    if (status != null)
        values.put(Users.STATUS, status);
    else
        values.putNull(Users.STATUS);

    // delay
    long timestamp;
    DelayInformation delay = p.getExtension(DelayInformation.ELEMENT, DelayInformation.NAMESPACE);
    if (delay != null) {
        // delay from presence (rare)
        timestamp = delay.getStamp().getTime();
    }
    else {
        // logged in/out now
        timestamp = System.currentTimeMillis();
    }

    if (timestamp > 0)
        values.put(Users.LAST_SEEN, timestamp);

    // public key extension (for fingerprint)
    PublicKeyPresence pkey = p.getExtension(PublicKeyPresence.ELEMENT_NAME, PublicKeyPresence.NAMESPACE);
    if (pkey != null) {
        String fingerprint = pkey.getFingerprint();
        if (fingerprint != null) {
            // insert new key with empty key data
            Keyring.setKey(getContext(), jid, fingerprint, new Date());
        }
    }

    return getContext().getContentResolver().update(Users.CONTENT_URI,
        values, Users.JID + "=?", new String[] { jid });
}
 
開發者ID:kontalk,項目名稱:androidclient,代碼行數:43,代碼來源:PresenceListener.java

示例11: initStatusListener

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public static void initStatusListener() {
    ChatManager chatManager = ChatManager.getInstance();

    final PacketListener presenceListener = new PacketListener() {
        public void processPacket(Packet packet) {
            if (packet instanceof Presence) {
                Presence p = (Presence)packet;
                DefaultPacketExtension ext = (DefaultPacketExtension)p.getExtension("workgroup", "http://jivesoftware.com/protocol/workgroup");
                if (ext != null) {
                    String lastModified = ext.getValue("lastModified");
                    if (lastModified != null) {
                        String workgroupName = StringUtils.parseName(p.getFrom());
                        String previousDate = (String)CHANGE_MAP.get(workgroupName);

                        final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
                        UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0"));

                        try {
                            Date newDate = UTC_FORMAT.parse(lastModified);

                            if (ModelUtil.hasLength(previousDate)) {
                                Date oldDate = UTC_FORMAT.parse(previousDate);
                                if (newDate.getTime() > oldDate.getTime()) {
                                    CHANGE_MAP.put(workgroupName, lastModified);
                                    fireWorkgroupChanged(p.getFrom());
                                    workgroupForms.remove(p.getFrom());
                                }
                            }
                            else {
                                CHANGE_MAP.put(workgroupName, lastModified);
                            }
                        }
                        catch (ParseException e) {
                            WebLog.logError("Error processing workgroup packet.", e);
                        }

                    }
                }
            }
        }
    };

    if (chatManager.getGlobalConnection() == null || !chatManager.getGlobalConnection().isConnected()) {
        ConnectionSettings settings = chatManager.getChatSettingsManager().getSettings();
        WebLog.logError("A connection to the server could not be made when attempting connection to " + settings.getServerDomain());
    }
    else {
        chatManager.getGlobalConnection().addPacketListener(presenceListener, new PacketTypeFilter(Presence.class));
        workgroups.clear();
        workgroupForms.clear();
        workgroupPresence.clear();
    }
}
 
開發者ID:igniterealtime,項目名稱:Fastpath-webchat,代碼行數:54,代碼來源:WorkgroupStatus.java

示例12: handleSubscribe

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private void handleSubscribe(Presence p)
        throws NotConnectedException, IOException, PGPException {

    Context ctx = getContext();

    // auto-accept subscription
    if (Preferences.getAutoAcceptSubscriptions(ctx)) {

        Packet r = createSubscribe(p);
        if (r != null)
            getConnection().sendPacket(r);

    }

    // ask the user
    else {

        /*
         * Subscription procedure:
         * 1. update (or insert) users table with the public key just received
         * 2. update (or insert) threads table with a special subscription record
         * 3. user will either accept or refuse
         */

        String from = StringUtils.parseName(p.getFrom());

        // extract public key
        String name = null, fingerprint = null;
        byte[] publicKey = null;
        PacketExtension _pkey = p.getExtension(SubscribePublicKey.ELEMENT_NAME, SubscribePublicKey.NAMESPACE);
        if (_pkey instanceof SubscribePublicKey) {
            SubscribePublicKey pkey = (SubscribePublicKey) _pkey;
            byte[] _publicKey = pkey.getKey();
            // extract the name from the uid
            PGPPublicKeyRing ring = PGP.readPublicKeyring(_publicKey);
            if (ring != null) {
                PGPPublicKey pk = PGP.getMasterKey(ring);
                if (pk != null) {
                    // set all parameters
                    name = PGP.getUserId(pk, getServer().getNetwork());
                    fingerprint = PGP.getFingerprint(pk);
                    publicKey = _publicKey;
                }
            }
        }

        ContentResolver cr = ctx.getContentResolver();
        ContentValues values = new ContentValues(4);

        // insert public key into the users table
        values.put(Users.HASH, from);
        values.put(Users.PUBLIC_KEY, publicKey);
        values.put(Users.FINGERPRINT, fingerprint);
        values.put(Users.DISPLAY_NAME, name);
        cr.insert(Users.CONTENT_URI.buildUpon()
                .appendQueryParameter(Users.DISCARD_NAME, "true")
                .build(), values);

        // invalidate cache for this user
        Contact.invalidate(from);

        // insert request into the database
        values.clear();
        values.put(CommonColumns.PEER, from);
        values.put(CommonColumns.TIMESTAMP, System.currentTimeMillis());
        cr.insert(Requests.CONTENT_URI, values);

        // fire up a notification
        MessagingNotification.chatInvitation(ctx, from);
    }
}
 
開發者ID:ShadiNachat,項目名稱:Chatting-App-,代碼行數:72,代碼來源:PresenceListener.java

示例13: handlePresence

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private void handlePresence(Presence p) {
    Intent i = new Intent(ACTION_PRESENCE);
    Presence.Type type = p.getType();
    i.putExtra(EXTRA_TYPE, type != null ? type.name() : Presence.Type.available.name());
    i.putExtra(EXTRA_PACKET_ID, p.getPacketID());

    String from = p.getFrom();
    String network = StringUtils.parseServer(from);
    // our network - convert to userId
    if (network.equalsIgnoreCase(getServer().getNetwork())) {
        StringBuilder b = new StringBuilder();
        b.append(StringUtils.parseName(from));
        b.append(StringUtils.parseResource(from));
        i.putExtra(EXTRA_FROM_USERID, b.toString());
    }

    i.putExtra(EXTRA_FROM, from);
    i.putExtra(EXTRA_TO, p.getTo());
    i.putExtra(EXTRA_STATUS, p.getStatus());
    Presence.Mode mode = p.getMode();
    i.putExtra(EXTRA_SHOW, mode != null ? mode.name() : Presence.Mode.available.name());
    i.putExtra(EXTRA_PRIORITY, p.getPriority());

    // getExtension doesn't work here
    Iterator<PacketExtension> iter = p.getExtensions().iterator();
    while (iter.hasNext()) {
        PacketExtension _ext = iter.next();
        if (_ext instanceof DelayInformation) {
            DelayInformation delay = (DelayInformation) _ext;
            i.putExtra(EXTRA_STAMP, delay.getStamp().getTime());
            break;
        }
    }

    // non-standard stanza group extension
    PacketExtension ext = p.getExtension(StanzaGroupExtension.ELEMENT_NAME, StanzaGroupExtension.NAMESPACE);
    if (ext != null && ext instanceof StanzaGroupExtension) {
        StanzaGroupExtension g = (StanzaGroupExtension) ext;
        i.putExtra(EXTRA_GROUP_ID, g.getId());
        i.putExtra(EXTRA_GROUP_COUNT, g.getCount());
    }

    Log.v(MessageCenterService.TAG, "broadcasting presence: " + i);
    sendBroadcast(i);
}
 
開發者ID:ShadiNachat,項目名稱:Chatting-App-,代碼行數:46,代碼來源:PresenceListener.java


注:本文中的org.jivesoftware.smack.packet.Presence.getExtension方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。