mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 13:32:07 +01:00
Add support for XEP-0350: Data Forms Geolocation Element
Fixes SMACK-871.
This commit is contained in:
parent
fa0c16d75c
commit
c6c904cc3e
4 changed files with 55 additions and 3 deletions
|
@ -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. |
|
| 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 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. |
|
| 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. |
|
| [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 |
|
| [Jive Properties](properties.md) | n/a | n/a | TODO |
|
||||||
|
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.smack.packet.Message;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.geoloc.packet.GeoLocation;
|
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.LeafNode;
|
||||||
import org.jivesoftware.smackx.pubsub.PayloadItem;
|
import org.jivesoftware.smackx.pubsub.PayloadItem;
|
||||||
import org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException;
|
import org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException;
|
||||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||||
|
import org.jivesoftware.smackx.xdata.provider.FormFieldChildElementProviderManager;
|
||||||
|
|
||||||
import org.jxmpp.jid.Jid;
|
import org.jxmpp.jid.Jid;
|
||||||
|
|
||||||
|
@ -41,6 +43,9 @@ public final class GeoLocationManager extends Manager {
|
||||||
private static final Map<XMPPConnection, GeoLocationManager> INSTANCES = new WeakHashMap<>();
|
private static final Map<XMPPConnection, GeoLocationManager> INSTANCES = new WeakHashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
FormFieldChildElementProviderManager.addFormFieldChildElementProvider(
|
||||||
|
GeoLocationProvider.GeoLocationFormFieldChildElementProvider.INSTANCE);
|
||||||
|
|
||||||
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
XMPPConnectionRegistry.addConnectionCreationListener(new ConnectionCreationListener() {
|
||||||
@Override
|
@Override
|
||||||
public void connectionCreated(XMPPConnection connection) {
|
public void connectionCreated(XMPPConnection connection) {
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||||
import org.jivesoftware.smack.packet.Message;
|
import org.jivesoftware.smack.packet.Message;
|
||||||
import org.jivesoftware.smack.util.StringUtils;
|
import org.jivesoftware.smack.util.StringUtils;
|
||||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
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.
|
* 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>
|
* @see <a href="http://www.xmpp.org/extensions/xep-0080.html">XEP-0080</a>
|
||||||
* @author Ishan Khanna
|
* @author Ishan Khanna
|
||||||
*/
|
*/
|
||||||
public final class GeoLocation implements Serializable, ExtensionElement {
|
public final class GeoLocation implements Serializable, ExtensionElement, FormFieldChildElement {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public static final String NAMESPACE = "http://jabber.org/protocol/geoloc";
|
public static final String NAMESPACE = "http://jabber.org/protocol/geoloc";
|
||||||
|
|
||||||
public static final String ELEMENT = "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 static final Logger LOGGER = Logger.getLogger(GeoLocation.class.getName());
|
||||||
|
|
||||||
private final Double accuracy;
|
private final Double accuracy;
|
||||||
|
@ -208,6 +217,11 @@ public final class GeoLocation implements Serializable, ExtensionElement {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public QName getQName() {
|
||||||
|
return QNAME;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getElementName() {
|
public String getElementName() {
|
||||||
return ELEMENT;
|
return ELEMENT;
|
||||||
|
@ -254,10 +268,19 @@ public final class GeoLocation implements Serializable, ExtensionElement {
|
||||||
return new GeoLocation.Builder();
|
return new GeoLocation.Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isExclusiveElement() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static GeoLocation from(Message message) {
|
public static GeoLocation from(Message message) {
|
||||||
return message.getExtension(ELEMENT, NAMESPACE);
|
return message.getExtension(ELEMENT, NAMESPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static GeoLocation from(FormField formField) {
|
||||||
|
return (GeoLocation) formField.getFormFieldChildElement(QNAME);
|
||||||
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
|
|
||||||
private Double accuracy;
|
private Double accuracy;
|
||||||
|
|
|
@ -18,7 +18,10 @@ package org.jivesoftware.smackx.geoloc.provider;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
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.SmackTextParseException;
|
||||||
import org.jivesoftware.smack.parsing.SmackParsingException.SmackUriSyntaxParsingException;
|
import org.jivesoftware.smack.parsing.SmackParsingException.SmackUriSyntaxParsingException;
|
||||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
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.smack.xml.XmlPullParserException;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.geoloc.packet.GeoLocation;
|
import org.jivesoftware.smackx.geoloc.packet.GeoLocation;
|
||||||
|
import org.jivesoftware.smackx.xdata.provider.FormFieldChildElementProvider;
|
||||||
|
|
||||||
public class GeoLocationProvider extends ExtensionElementProvider<GeoLocation> {
|
public class GeoLocationProvider extends ExtensionElementProvider<GeoLocation> {
|
||||||
|
|
||||||
|
public static final GeoLocationProvider INSTANCE = new GeoLocationProvider();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeoLocation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException,
|
public GeoLocation parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException,
|
||||||
SmackTextParseException, SmackUriSyntaxParsingException {
|
SmackTextParseException, SmackUriSyntaxParsingException {
|
||||||
|
@ -130,4 +136,21 @@ public class GeoLocationProvider extends ExtensionElementProvider<GeoLocation> {
|
||||||
return builder.build();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue