Add support for XEP-0350: Data Forms Geolocation Element

Fixes SMACK-871.
This commit is contained in:
Florian Schmaus 2019-06-12 15:49:45 +02:00
parent fa0c16d75c
commit c6c904cc3e
4 changed files with 55 additions and 3 deletions

View File

@ -74,6 +74,7 @@ Smack Extensions and currently supported XEPs of smack-extensions
| Best Practices for Resource Locking | [XEP-0296](https://xmpp.org/extensions/xep-0296.html) | n/a | Specifies best practices to be followed by Jabber/XMPP clients about when to lock into, and unlock away from, resources. |
| Last Message Correction | [XEP-0308](https://xmpp.org/extensions/xep-0308.html) | n/a | Provides a method for indicating that a message is a correction of the last sent message. |
| Last User Interaction in Presence | [XEP-0319](https://xmpp.org/extensions/xep-0319.html) | n/a | Communicate time of last user interaction via XMPP presence notifications. |
| Data Forms Geolocation Element | [XEP-0350](https://xmpp.org/extensions/xep-0350.html) | n/a | Allows to include XEP-0080 gelocation data in XEP-0004 data forms. |
| [Group Chat Invitations](invitation.md) | n/a | n/a | Send invitations to other users to join a group chat room. |
| [Jive Properties](properties.md) | n/a | n/a | TODO |

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez 2019 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -29,10 +29,12 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.geoloc.packet.GeoLocation;
import org.jivesoftware.smackx.geoloc.provider.GeoLocationProvider;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.xdata.provider.FormFieldChildElementProviderManager;
import org.jxmpp.jid.Jid;
@ -41,6 +43,9 @@ public final class GeoLocationManager extends Manager {
private static final Map<XMPPConnection, GeoLocationManager> INSTANCES = new WeakHashMap<>();
static {
FormFieldChildElementProviderManager.addFormFieldChildElementProvider(
GeoLocationProvider.GeoLocationFormFieldChildElementProvider.INSTANCE);
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
@Override
public void connectionCreated(XMPPConnection connection) {

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez, 2019 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -22,23 +22,32 @@ import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.StringUtils;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smackx.xdata.FormField;
import org.jivesoftware.smackx.xdata.FormFieldChildElement;
/**
* A GeoLocation Extension packet, which is used by the XMPP clients to exchange their respective geographic locations.
*
* @see <a href="http://www.xmpp.org/extensions/xep-0080.html">XEP-0080</a>
* @author Ishan Khanna
*/
public final class GeoLocation implements Serializable, ExtensionElement {
public final class GeoLocation implements Serializable, ExtensionElement, FormFieldChildElement {
private static final long serialVersionUID = 1L;
public static final String NAMESPACE = "http://jabber.org/protocol/geoloc";
public static final String ELEMENT = "geoloc";
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
private static final Logger LOGGER = Logger.getLogger(GeoLocation.class.getName());
private final Double accuracy;
@ -208,6 +217,11 @@ public final class GeoLocation implements Serializable, ExtensionElement {
return uri;
}
@Override
public QName getQName() {
return QNAME;
}
@Override
public String getElementName() {
return ELEMENT;
@ -254,10 +268,19 @@ public final class GeoLocation implements Serializable, ExtensionElement {
return new GeoLocation.Builder();
}
@Override
public boolean isExclusiveElement() {
return true;
}
public static GeoLocation from(Message message) {
return message.getExtension(ELEMENT, NAMESPACE);
}
public static GeoLocation from(FormField formField) {
return (GeoLocation) formField.getFormFieldChildElement(QNAME);
}
public static class Builder {
private Double accuracy;

View File

@ -18,7 +18,10 @@ package org.jivesoftware.smackx.geoloc.provider;
import java.io.IOException;
import javax.xml.namespace.QName;
import org.jivesoftware.smack.packet.XmlEnvironment;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.parsing.SmackParsingException.SmackTextParseException;
import org.jivesoftware.smack.parsing.SmackParsingException.SmackUriSyntaxParsingException;
import org.jivesoftware.smack.provider.ExtensionElementProvider;
@ -27,9 +30,12 @@ import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jivesoftware.smackx.geoloc.packet.GeoLocation;
import org.jivesoftware.smackx.xdata.provider.FormFieldChildElementProvider;
public class GeoLocationProvider extends ExtensionElementProvider<GeoLocation> {
public static final GeoLocationProvider INSTANCE = new GeoLocationProvider();
@Override
public GeoLocation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException,
SmackTextParseException, SmackUriSyntaxParsingException {
@ -130,4 +136,21 @@ public class GeoLocationProvider extends ExtensionElementProvider<GeoLocation> {
return builder.build();
}
public static class GeoLocationFormFieldChildElementProvider extends FormFieldChildElementProvider<GeoLocation> {
public static final GeoLocationFormFieldChildElementProvider INSTANCE = new GeoLocationFormFieldChildElementProvider();
@Override
public QName getQName() {
return GeoLocation.QNAME;
}
@Override
public GeoLocation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
return GeoLocationProvider.INSTANCE.parse(parser, initialDepth, xmlEnvironment);
}
}
}