Search in sources :

Example 1 with DefaultPacketExtension

use of org.jivesoftware.smack.packet.DefaultPacketExtension in project ecf by eclipse.

the class PacketParserUtils method parsePacketExtension.

/**
 * Parses a packet extension sub-packet.
 *
 * @param elementName the XML element name of the packet extension.
 * @param namespace the XML namespace of the packet extension.
 * @param parser the XML parser, positioned at the starting element of the extension.
 * @return a PacketExtension.
 * @throws Exception if a parsing error occurs.
 */
public static PacketExtension parsePacketExtension(String elementName, String namespace, XmlPullParser parser) throws Exception {
    // See if a provider is registered to handle the extension.
    Object provider = ProviderManager.getInstance().getExtensionProvider(elementName, namespace);
    if (provider != null) {
        if (provider instanceof PacketExtensionProvider) {
            return ((PacketExtensionProvider) provider).parseExtension(parser);
        } else if (provider instanceof Class) {
            return (PacketExtension) parseWithIntrospection(elementName, (Class<?>) provider, parser);
        }
    }
    // No providers registered, so use a default extension.
    DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace);
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            String name = parser.getName();
            // If an empty element, set the value with the empty string.
            if (parser.isEmptyElementTag()) {
                extension.setValue(name, "");
            } else // Otherwise, get the the element text.
            {
                eventType = parser.next();
                if (eventType == XmlPullParser.TEXT) {
                    String value = parser.getText();
                    extension.setValue(name, value);
                }
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals(elementName)) {
                done = true;
            }
        }
    }
    return extension;
}
Also used : DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) PacketExtensionProvider(org.jivesoftware.smack.provider.PacketExtensionProvider)

Example 2 with DefaultPacketExtension

use of org.jivesoftware.smack.packet.DefaultPacketExtension in project camel by apache.

the class XmppBinding method extractHeadersFromXmpp.

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;
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) PubSub(org.jivesoftware.smackx.pubsub.packet.PubSub) Message(org.jivesoftware.smack.packet.Message) HashMap(java.util.HashMap) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)

Example 3 with DefaultPacketExtension

use of org.jivesoftware.smack.packet.DefaultPacketExtension in project Openfire by igniterealtime.

the class XMPPPresenceHandler method handlePresenceMode.

/**
	 * Handles incoming presence stanzas that relate to presence status / mode
	 * changes. Ignores others.
	 * 
	 * @param presence
	 *            the stanza
	 */
private void handlePresenceMode(final org.jivesoftware.smack.packet.Presence presence) {
    if (!session.getBuddyManager().isActivated()) {
        session.getBuddyManager().storePendingStatus(session.getTransport().convertIDToJID(presence.getFrom()), ((XMPPTransport) session.getTransport()).convertXMPPStatusToGateway(presence.getType(), presence.getMode()), presence.getStatus());
    } else {
        // TODO: Need to handle resources and priorities!
        try {
            final XMPPBuddy xmppBuddy = session.getBuddyManager().getBuddy(session.getTransport().convertIDToJID(presence.getFrom()));
            Log.debug("XMPP: Presence changed detected type " + presence.getType() + " and mode " + presence.getMode() + " for " + presence.getFrom());
            xmppBuddy.setPresenceAndStatus(((XMPPTransport) session.getTransport()).convertXMPPStatusToGateway(presence.getType(), presence.getMode()), presence.getStatus());
            if (JiveGlobals.getBooleanProperty("plugin.gateway." + session.getTransport().getType() + ".avatars", true)) {
                PacketExtension pe = presence.getExtension("x", NameSpace.VCARD_TEMP_X_UPDATE);
                if (pe != null) {
                    DefaultPacketExtension dpe = (DefaultPacketExtension) pe;
                    String hash = dpe.getValue("photo");
                    final String from = presence.getFrom();
                    if (hash != null) {
                        Avatar curAvatar = xmppBuddy.getAvatar();
                        if (curAvatar == null || !curAvatar.getLegacyIdentifier().equals(hash)) {
                            new Thread() {

                                @Override
                                public void run() {
                                    VCard vcard = new VCard();
                                    try {
                                        vcard.load(session.conn, from);
                                        xmppBuddy.setAvatar(new Avatar(xmppBuddy.getJID(), from, vcard.getAvatar()));
                                    } catch (XMPPException e) {
                                        Log.debug("XMPP: Failed to load XMPP avatar: ", e);
                                    } catch (IllegalArgumentException e) {
                                        Log.debug("XMPP: Got null avatar, ignoring.");
                                    }
                                }
                            }.start();
                        }
                    }
                }
            }
        } catch (NotFoundException e) {
            Log.debug("XMPP: Received presence notification for contact that's not in the buddy manager of user " + session.getJID() + ". GTalk is known to do this occasionally: " + presence.getFrom());
        // We cannot add this buddy to the buddy manager, as that would result into an auto-accept of the contact sending the data.
        }
    }
}
Also used : PacketExtension(org.jivesoftware.smack.packet.PacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension) NotFoundException(org.jivesoftware.util.NotFoundException) XMPPException(org.jivesoftware.smack.XMPPException) VCard(org.jivesoftware.smackx.packet.VCard) Avatar(net.sf.kraken.avatars.Avatar)

Example 4 with DefaultPacketExtension

use of org.jivesoftware.smack.packet.DefaultPacketExtension in project ecf by eclipse.

the class PrivacyProvider method parseIQ.

public IQ parseIQ(XmlPullParser parser) throws Exception {
    Privacy privacy = new Privacy();
    /* privacy.addExtension(PacketParserUtils.parsePacketExtension(parser
                .getName(), parser.getNamespace(), parser)); */
    privacy.addExtension(new DefaultPacketExtension(parser.getName(), parser.getNamespace()));
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("active")) {
                String activeName = parser.getAttributeValue("", "name");
                if (activeName == null) {
                    privacy.setDeclineActiveList(true);
                } else {
                    privacy.setActiveName(activeName);
                }
            } else if (parser.getName().equals("default")) {
                String defaultName = parser.getAttributeValue("", "name");
                if (defaultName == null) {
                    privacy.setDeclineDefaultList(true);
                } else {
                    privacy.setDefaultName(defaultName);
                }
            } else if (parser.getName().equals("list")) {
                parseList(parser, privacy);
            }
        } else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("query")) {
                done = true;
            }
        }
    }
    return privacy;
}
Also used : Privacy(org.jivesoftware.smack.packet.Privacy) DefaultPacketExtension(org.jivesoftware.smack.packet.DefaultPacketExtension)

Aggregations

DefaultPacketExtension (org.jivesoftware.smack.packet.DefaultPacketExtension)4 PacketExtension (org.jivesoftware.smack.packet.PacketExtension)2 HashMap (java.util.HashMap)1 Avatar (net.sf.kraken.avatars.Avatar)1 XMPPException (org.jivesoftware.smack.XMPPException)1 Message (org.jivesoftware.smack.packet.Message)1 Privacy (org.jivesoftware.smack.packet.Privacy)1 PacketExtensionProvider (org.jivesoftware.smack.provider.PacketExtensionProvider)1 JivePropertiesExtension (org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension)1 VCard (org.jivesoftware.smackx.packet.VCard)1 PubSub (org.jivesoftware.smackx.pubsub.packet.PubSub)1 NotFoundException (org.jivesoftware.util.NotFoundException)1