2016-04-05 19:51:34 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2016 Fernando Ramirez
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2016-04-14 22:47:12 +02:00
|
|
|
package org.jivesoftware.smackx.message_correct.element;
|
2016-04-05 19:51:34 +02:00
|
|
|
|
2020-04-05 22:10:05 +02:00
|
|
|
import javax.xml.namespace.QName;
|
|
|
|
|
2016-04-05 19:51:34 +02:00
|
|
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
|
|
|
import org.jivesoftware.smack.packet.Message;
|
2016-04-14 22:47:12 +02:00
|
|
|
import org.jivesoftware.smack.util.StringUtils;
|
2016-04-05 19:51:34 +02:00
|
|
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An Extension that implements XEP-0308: Last Message Correction
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-04-05 19:51:34 +02:00
|
|
|
* This extension is expected to be added to message stanzas. Please refer to
|
|
|
|
* the XEP for more implementation guidelines.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2016-04-05 19:51:34 +02:00
|
|
|
* @author Fernando Ramirez, f.e.ramirez94@gmail.com
|
2017-12-25 12:51:41 +01:00
|
|
|
* @see <a href="http://xmpp.org/extensions/xep-0308.html">XEP-0308: Last
|
|
|
|
* Message Correction</a>
|
2016-04-05 19:51:34 +02:00
|
|
|
*/
|
|
|
|
public class MessageCorrectExtension implements ExtensionElement {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The XML element name of a 'message correct' extension.
|
|
|
|
*/
|
|
|
|
public static final String ELEMENT = "replace";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The namespace that qualifies the XML element of a 'message correct'
|
|
|
|
* extension.
|
|
|
|
*/
|
|
|
|
public static final String NAMESPACE = "urn:xmpp:message-correct:0";
|
|
|
|
|
2020-04-05 22:10:05 +02:00
|
|
|
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
|
|
|
|
2016-04-05 19:51:34 +02:00
|
|
|
/**
|
|
|
|
* The id tag of a 'message correct' extension.
|
|
|
|
*/
|
|
|
|
public static final String ID_TAG = "id";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The id of the message to correct.
|
|
|
|
*/
|
2016-04-14 22:47:12 +02:00
|
|
|
private final String idInitialMessage;
|
2016-04-05 19:51:34 +02:00
|
|
|
|
|
|
|
public MessageCorrectExtension(String idInitialMessage) {
|
2018-07-17 15:10:39 +02:00
|
|
|
this.idInitialMessage = StringUtils.requireNotNullNorEmpty(idInitialMessage, "idInitialMessage must not be null");
|
2016-04-05 19:51:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getIdInitialMessage() {
|
|
|
|
return idInitialMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getElementName() {
|
|
|
|
return ELEMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-04 13:27:41 +01:00
|
|
|
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
2016-04-05 19:51:34 +02:00
|
|
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
|
|
|
xml.attribute(ID_TAG, getIdInitialMessage());
|
|
|
|
xml.closeEmptyElement();
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getNamespace() {
|
|
|
|
return NAMESPACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static MessageCorrectExtension from(Message message) {
|
2020-04-05 22:10:05 +02:00
|
|
|
return message.getExtension(MessageCorrectExtension.class);
|
2016-04-05 19:51:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|