Java 类org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension 实例源码

项目:Camel    文件:XmppBinding.java   
public Map<String, Object> extractHeadersFromXmpp(Packet xmppPacket, Exchange exchange) {
    Map<String, Object> answer = new HashMap<String, Object>();

    PacketExtension jpe = xmppPacket.getExtension(JivePropertiesExtension.NAMESPACE);
    if (jpe != null && jpe instanceof JivePropertiesExtension) {
        extractHeadersFrom((JivePropertiesExtension)jpe, exchange, answer);
    }
    if (jpe != null && jpe instanceof DefaultPacketExtension) {
        extractHeadersFrom((DefaultPacketExtension)jpe, exchange, answer);
    }

    if (xmppPacket instanceof Message) {
        Message xmppMessage = (Message) xmppPacket;
        answer.put(XmppConstants.MESSAGE_TYPE, xmppMessage.getType());
        answer.put(XmppConstants.SUBJECT, xmppMessage.getSubject());
        answer.put(XmppConstants.THREAD_ID, xmppMessage.getThread());
    } else if (xmppPacket instanceof PubSub) {
        PubSub pubsubPacket = (PubSub) xmppPacket;
        answer.put(XmppConstants.MESSAGE_TYPE, pubsubPacket.getType());
    }
    answer.put(XmppConstants.FROM, xmppPacket.getFrom());
    answer.put(XmppConstants.PACKET_ID, xmppPacket.getPacketID());
    answer.put(XmppConstants.TO, xmppPacket.getTo());

    return answer;
}
项目:Smack    文件:JivePropertiesManager.java   
/**
 * Convenience method to get a property from a packet. Will return null if the stanza(/packet) contains
 * not property with the given name.
 * 
 * @param packet
 * @param name
 * @return the property or <tt>null</tt> if none found.
 */
public static Object getProperty(Stanza packet, String name) {
    Object res = null;
    JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.NAMESPACE);
    if (jpe != null) {
        res = jpe.getProperty(name);
    }
    return res;
}
项目:Smack    文件:JivePropertiesManager.java   
/**
 * Return a collection of the names of all properties of the given packet. If the packet
 * contains no properties extension, then an empty collection will be returned.
 * 
 * @param packet
 * @return a collection of the names of all properties.
 */
public static Collection<String> getPropertiesNames(Stanza packet) {
    JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.NAMESPACE);
    if (jpe == null) {
        return Collections.emptyList();
    }
    return jpe.getPropertyNames();
}
项目:Smack    文件:JivePropertiesManager.java   
/**
 * Return a map of all properties of the given packet. If the stanza(/packet) contains no properties
 * extension, an empty map will be returned.
 * 
 * @param packet
 * @return a map of all properties of the given packet.
 */
public static Map<String, Object> getProperties(Stanza packet) {
    JivePropertiesExtension jpe = (JivePropertiesExtension) packet.getExtension(JivePropertiesExtension.NAMESPACE);
    if (jpe == null) {
        return Collections.emptyMap();
    }
    return jpe.getProperties();
}
项目:Camel    文件:XmppBinding.java   
private void extractHeadersFrom(JivePropertiesExtension jpe, Exchange exchange, Map<String, Object> answer) {
    for (String name : jpe.getPropertyNames()) {
        Object value = jpe.getProperty(name);
        if (!headerFilterStrategy.applyFilterToExternalHeaders(name, value, exchange)) {
            answer.put(name, value);
        }
    }
}
项目:mangosta-android    文件:XMPPSession.java   
private void manageMessageReceived(Message message, Date delayDate, String messageId, boolean fromMam) {
    String[] jidList = message.getFrom().toString().split("/");

    ChatMessage chatMessage = new ChatMessage();
    chatMessage.setMessageId(messageId);

    String chatRoomJID;
    if (!jidList[0].equals(Preferences.getInstance().getUserXMPPJid())) {
        chatRoomJID = jidList[0];
    } else {
        chatRoomJID = message.getTo().toString().split("/")[0];
    }
    chatMessage.setRoomJid(chatRoomJID);

    // not saving messages with my affiliation changes to "none", and delete the chat in that case
    if (checkIfMyIsAffiliationNone(message)) {
        deleteChat(chatRoomJID);
        return;
    }

    if (message.hasExtension(JivePropertiesExtension.ELEMENT, JivePropertiesExtension.NAMESPACE)) {
        return;
    }

    RoomsListManager.getInstance().createChatIfNotExists(chatRoomJID, true);

    manageSender(jidList, chatMessage, chatRoomJID);

    chatMessage.setStatus(ChatMessage.STATUS_SENT);
    chatMessage.setUnread(true);

    if (isBoBMessage(message)) {
        BoBExtension bobExtension = BoBExtension.from(message);
        chatMessage.setContent(Base64.decodeToString(bobExtension.getBoBHash().getHash()));
        chatMessage.setType(ChatMessage.TYPE_STICKER);
    } else {
        chatMessage.setContent(message.getBody());
        chatMessage.setType(ChatMessage.TYPE_CHAT);
    }

    Realm realm = RealmManager.getInstance().getRealm();
    Chat chatRoom = realm.where(Chat.class).equalTo("jid", chatRoomJID).findFirst();
    realm.beginTransaction();

    if (canBeTextMessageOrSticker(message) && !fromMam) {
        chatRoom.addUnreadMessage();
    }

    // room name or subject change
    manageConfigurationsChange(message, chatMessage, chatRoom);

    // not saving invalid messages
    if (chatMessage.getContent() == null || chatMessage.getContent().isEmpty() || chatMessage.getUserSender() == null) {
        realm.commitTransaction();
        realm.close();
        return;
    }

    // assign date
    manageDelayDate(delayDate, chatMessage);

    realm.copyToRealmOrUpdate(chatMessage);
    realm.commitTransaction();
    realm.close();
}