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;
}
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;
}
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.
}
}
}
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;
}
Aggregations