2005-07-26 06:57:36 +02:00
|
|
|
/**
|
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2005-07-26 06:57:36 +02:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2005-07-26 06:57:36 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-02-15 11:35:08 +01:00
|
|
|
package org.jivesoftware.smackx.offline.packet;
|
2005-07-26 06:57:36 +02:00
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
2019-02-15 23:21:30 +01:00
|
|
|
import org.jivesoftware.smack.packet.XmlEnvironment;
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.jivesoftware.smack.xml.XmlPullParser;
|
|
|
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
2005-07-26 06:57:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* OfflineMessageInfo is an extension included in the retrieved offline messages requested by
|
2014-02-15 11:35:08 +01:00
|
|
|
* the {@link org.jivesoftware.smackx.offline.OfflineMessageManager}. This extension includes a stamp
|
2005-07-26 06:57:36 +02:00
|
|
|
* that uniquely identifies the offline message. This stamp may be used for deleting the offline
|
|
|
|
* message. The stamp may be of the form UTC timestamps but it is not required to have that format.
|
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
2015-02-26 18:41:17 +01:00
|
|
|
public class OfflineMessageInfo implements ExtensionElement {
|
2005-07-26 06:57:36 +02:00
|
|
|
|
|
|
|
private String node = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the XML element name of the extension sub-packet root element.
|
|
|
|
* Always returns "offline"
|
|
|
|
*
|
2018-03-31 14:17:30 +02:00
|
|
|
* @return the XML element name of the stanza extension.
|
2005-07-26 06:57:36 +02:00
|
|
|
*/
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2005-07-26 06:57:36 +02:00
|
|
|
public String getElementName() {
|
|
|
|
return "offline";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the XML namespace of the extension sub-packet root element.
|
|
|
|
* According the specification the namespace is always "http://jabber.org/protocol/offline"
|
|
|
|
*
|
2018-03-31 14:17:30 +02:00
|
|
|
* @return the XML namespace of the stanza extension.
|
2005-07-26 06:57:36 +02:00
|
|
|
*/
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2005-07-26 06:57:36 +02:00
|
|
|
public String getNamespace() {
|
|
|
|
return "http://jabber.org/protocol/offline";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the stamp that uniquely identifies the offline message. This stamp may
|
|
|
|
* be used for deleting the offline message. The stamp may be of the form UTC timestamps
|
|
|
|
* but it is not required to have that format.
|
|
|
|
*
|
|
|
|
* @return the stamp that uniquely identifies the offline message.
|
|
|
|
*/
|
|
|
|
public String getNode() {
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the stamp that uniquely identifies the offline message. This stamp may
|
|
|
|
* be used for deleting the offline message. The stamp may be of the form UTC timestamps
|
|
|
|
* but it is not required to have that format.
|
|
|
|
*
|
|
|
|
* @param node the stamp that uniquely identifies the offline message.
|
|
|
|
*/
|
|
|
|
public void setNode(String node) {
|
|
|
|
this.node = node;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2019-02-04 13:27:41 +01:00
|
|
|
public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
2006-07-18 07:14:33 +02:00
|
|
|
StringBuilder buf = new StringBuilder();
|
2015-07-21 08:19:15 +02:00
|
|
|
buf.append('<').append(getElementName()).append(" xmlns=\"").append(getNamespace()).append(
|
2005-07-26 06:57:36 +02:00
|
|
|
"\">");
|
|
|
|
if (getNode() != null)
|
|
|
|
buf.append("<item node=\"").append(getNode()).append("\"/>");
|
2015-07-21 08:19:15 +02:00
|
|
|
buf.append("</").append(getElementName()).append('>');
|
2005-07-26 06:57:36 +02:00
|
|
|
return buf.toString();
|
|
|
|
}
|
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
public static class Provider extends ExtensionElementProvider<OfflineMessageInfo> {
|
2005-07-26 06:57:36 +02:00
|
|
|
|
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Parses a OfflineMessageInfo stanza (extension sub-packet).
|
2005-07-26 06:57:36 +02:00
|
|
|
*
|
|
|
|
* @param parser the XML parser, positioned at the starting element of the extension.
|
|
|
|
* @return a PacketExtension.
|
2019-10-30 12:02:36 +01:00
|
|
|
* @throws IOException if an I/O error occurred.
|
|
|
|
* @throws XmlPullParserException if an error in the XML parser occurred.
|
2005-07-26 06:57:36 +02:00
|
|
|
*/
|
2014-10-07 21:15:20 +02:00
|
|
|
@Override
|
|
|
|
public OfflineMessageInfo parse(XmlPullParser parser,
|
2019-02-15 23:21:30 +01:00
|
|
|
int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException,
|
2014-10-07 21:15:20 +02:00
|
|
|
IOException {
|
2005-07-26 06:57:36 +02:00
|
|
|
OfflineMessageInfo info = new OfflineMessageInfo();
|
|
|
|
boolean done = false;
|
|
|
|
while (!done) {
|
2019-05-06 22:06:13 +02:00
|
|
|
XmlPullParser.Event eventType = parser.next();
|
|
|
|
if (eventType == XmlPullParser.Event.START_ELEMENT) {
|
2005-07-26 06:57:36 +02:00
|
|
|
if (parser.getName().equals("item"))
|
|
|
|
info.setNode(parser.getAttributeValue("", "node"));
|
2019-05-06 22:06:13 +02:00
|
|
|
} else if (eventType == XmlPullParser.Event.END_ELEMENT) {
|
2005-07-26 06:57:36 +02:00
|
|
|
if (parser.getName().equals("offline")) {
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|