From 0afbee55e0164a4b509f87f459700839388c2524 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Thu, 14 Apr 2016 22:47:12 +0200 Subject: [PATCH] Improve the Message Correction add missing provider registration and improve a few bits here and there. SMACK-714 --- documentation/extensions/index.md | 1 + .../MessageCorrectExtension.java | 26 +++---------------- .../{ => element}/package-info.java | 4 +-- .../provider/MessageCorrectProvider.java | 2 +- .../extensions.providers | 8 ++++++ .../MessageCorrectExtensionTest.java | 5 ++-- 6 files changed, 18 insertions(+), 28 deletions(-) rename smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/{ => element}/MessageCorrectExtension.java (79%) rename smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/{ => element}/package-info.java (81%) diff --git a/documentation/extensions/index.md b/documentation/extensions/index.md index 9ddd37c92..3bb98ce32 100644 --- a/documentation/extensions/index.md +++ b/documentation/extensions/index.md @@ -66,6 +66,7 @@ Smack Extensions and currently supported XEPs of smack-extensions | Delayed Delivery | [XEP-0203](http://xmpp.org/extensions/xep-0203.html) | Extension for communicating the fact that an XML stanza has been delivered with a delay. | | XMPP Over BOSH | [XEP-0206](http://xmpp.org/extensions/xep-0206.html) | Use Bidirectional-streams Over Synchronous HTTP (BOSH) to transport XMPP stanzas. | | Attention | [XEP-0224](http://xmpp.org/extensions/xep-0224.html) | Getting attention of another user. | +| Last Message Correction | [XEP-0308](http://xmpp.org/extensions/xep-0308.html) | Provides a method for indicating that a message is a correction of the last sent message. | | [Group Chat Invitations](invitation.md) | n/a | Send invitations to other users to join a group chat room. | | [Jive Properties](properties.md) | n/a | TODO | diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/MessageCorrectExtension.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/element/MessageCorrectExtension.java similarity index 79% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/MessageCorrectExtension.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/element/MessageCorrectExtension.java index 30910d801..fe2f50adf 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/MessageCorrectExtension.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/element/MessageCorrectExtension.java @@ -14,10 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smackx.message_correct; +package org.jivesoftware.smackx.message_correct.element; import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.XmlStringBuilder; /** @@ -51,35 +52,21 @@ public class MessageCorrectExtension implements ExtensionElement { /** * The id of the message to correct. */ - private String idInitialMessage; + private final String idInitialMessage; public MessageCorrectExtension(String idInitialMessage) { - this.setIdInitialMessage(idInitialMessage); + this.idInitialMessage = StringUtils.requireNotNullOrEmpty(idInitialMessage, "idInitialMessage must not be null"); } public String getIdInitialMessage() { return idInitialMessage; } - public void setIdInitialMessage(String idInitialMessage) { - this.idInitialMessage = idInitialMessage; - } - - /* - * (non-Javadoc) - * - * @see org.jivesoftware.smack.packet.PacketExtension#getElementName() - */ @Override public String getElementName() { return ELEMENT; } - /* - * (non-Javadoc) - * - * @see org.jivesoftware.smack.packet.PacketExtension#toXML() - */ @Override public XmlStringBuilder toXML() { XmlStringBuilder xml = new XmlStringBuilder(this); @@ -88,11 +75,6 @@ public class MessageCorrectExtension implements ExtensionElement { return xml; } - /* - * (non-Javadoc) - * - * @see org.jivesoftware.smack.packet.PacketExtension#getNamespace() - */ @Override public String getNamespace() { return NAMESPACE; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/package-info.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/element/package-info.java similarity index 81% rename from smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/package-info.java rename to smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/element/package-info.java index 2070625f9..0a3ab347e 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/package-info.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/element/package-info.java @@ -16,6 +16,6 @@ */ /** - * Classes and Interfaces that implement Last Message Correction as defined in XEP-0308. + * XMPP stream elements for Last Message Correction as defined in XEP-0308. */ -package org.jivesoftware.smackx.message_correct; +package org.jivesoftware.smackx.message_correct.element; diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/provider/MessageCorrectProvider.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/provider/MessageCorrectProvider.java index 271305670..c0df1739c 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/provider/MessageCorrectProvider.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/message_correct/provider/MessageCorrectProvider.java @@ -20,7 +20,7 @@ import java.io.IOException; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.provider.ExtensionElementProvider; -import org.jivesoftware.smackx.message_correct.MessageCorrectExtension; +import org.jivesoftware.smackx.message_correct.element.MessageCorrectExtension; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; diff --git a/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers b/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers index df1330907..2257b04d0 100644 --- a/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers +++ b/smack-extensions/src/main/resources/org.jivesoftware.smack.extensions/extensions.providers @@ -507,4 +507,12 @@ http://jabber.org/protocol/geoloc org.jivesoftware.smackx.geoloc.provider.GeoLocationProvider + + + + replace + urn:xmpp:message-correct:0 + org.jivesoftware.smackx.message_correct.provider.MessageCorrectProvider + + diff --git a/smack-extensions/src/test/java/org/jivesoftware/smackx/message_correct/MessageCorrectExtensionTest.java b/smack-extensions/src/test/java/org/jivesoftware/smackx/message_correct/MessageCorrectExtensionTest.java index 97216a285..1f224facb 100644 --- a/smack-extensions/src/test/java/org/jivesoftware/smackx/message_correct/MessageCorrectExtensionTest.java +++ b/smack-extensions/src/test/java/org/jivesoftware/smackx/message_correct/MessageCorrectExtensionTest.java @@ -18,13 +18,12 @@ package org.jivesoftware.smackx.message_correct; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.util.PacketParserUtils; +import org.jivesoftware.smackx.message_correct.element.MessageCorrectExtension; import org.junit.Assert; import org.junit.Test; public class MessageCorrectExtensionTest { - private Message initialMessage; - private final String idInitialMessage = "bad1"; private final String initialMessageXml = "" @@ -38,7 +37,7 @@ public class MessageCorrectExtensionTest { @Test public void checkStanzas() throws Exception { - initialMessage = (Message) PacketParserUtils.parseStanza(initialMessageXml); + Message initialMessage = (Message) PacketParserUtils.parseStanza(initialMessageXml); MessageCorrectExtension messageCorrectExtension = new MessageCorrectExtension(idInitialMessage); Assert.assertEquals(messageCorrectExtension.toXML().toString(), messageCorrectionXml);