2003-10-12 06:40:08 +02:00
|
|
|
/**
|
|
|
|
*
|
2007-02-12 01:59:05 +01:00
|
|
|
* Copyright 2003-2007 Jive Software.
|
2003-10-12 06:40:08 +02:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2004-11-03 00:37:00 +01:00
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2003-10-12 06:40:08 +02:00
|
|
|
*
|
2004-11-03 00:37:00 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2003-10-12 06:40:08 +02:00
|
|
|
*
|
2004-11-03 00:37:00 +01:00
|
|
|
* 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.
|
2003-10-12 06:40:08 +02:00
|
|
|
*/
|
|
|
|
|
2014-02-15 11:35:08 +01:00
|
|
|
package org.jivesoftware.smackx.muc.packet;
|
2003-10-12 06:40:08 +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;
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jivesoftware.smack.packet.Stanza;
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
2014-07-14 19:22:02 +02:00
|
|
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2003-10-12 06:40:08 +02:00
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
2014-10-07 21:15:20 +02:00
|
|
|
import org.xmlpull.v1.XmlPullParserException;
|
2003-10-12 06:40:08 +02:00
|
|
|
|
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* A group chat invitation stanza extension, which is used to invite other
|
2003-10-12 06:40:08 +02:00
|
|
|
* users to a group chat room. To invite a user to a group chat room, address
|
|
|
|
* a new message to the user and set the room name appropriately, as in the
|
|
|
|
* following code example:
|
|
|
|
*
|
|
|
|
* <pre>
|
|
|
|
* Message message = new Message("user@chat.example.com");
|
|
|
|
* message.setBody("Join me for a group chat!");
|
|
|
|
* message.addExtension(new GroupChatInvitation("room@chat.example.com"););
|
2015-03-04 21:44:43 +01:00
|
|
|
* con.sendStanza(message);
|
2003-10-12 06:40:08 +02:00
|
|
|
* </pre>
|
|
|
|
*
|
2015-02-26 18:41:17 +01:00
|
|
|
* To listen for group chat invitations, use a StanzaExtensionFilter for the
|
2003-10-12 06:40:08 +02:00
|
|
|
* <tt>x</tt> element name and <tt>jabber:x:conference</tt> namespace, as in the
|
|
|
|
* following code example:
|
|
|
|
*
|
|
|
|
* <pre>
|
2015-02-26 18:41:17 +01:00
|
|
|
* PacketFilter filter = new StanzaExtensionFilter("x", "jabber:x:conference");
|
2018-03-31 14:17:30 +02:00
|
|
|
* // Create a stanza collector or stanza listeners using the filter...
|
2003-10-12 06:40:08 +02:00
|
|
|
* </pre>
|
|
|
|
*
|
2014-06-14 11:45:38 +02:00
|
|
|
* <b>Note</b>: this protocol is outdated now that the Multi-User Chat (MUC) XEP is available
|
|
|
|
* (<a href="http://www.xmpp.org/extensions/jep-0045.html">XEP-45</a>). However, most
|
2003-10-12 06:40:08 +02:00
|
|
|
* existing clients still use this older protocol. Once MUC support becomes more
|
|
|
|
* widespread, this API may be deprecated.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2003-10-12 06:40:08 +02:00
|
|
|
* @author Matt Tucker
|
|
|
|
*/
|
2015-02-26 18:41:17 +01:00
|
|
|
public class GroupChatInvitation implements ExtensionElement {
|
2003-10-12 06:40:08 +02:00
|
|
|
|
2003-10-23 22:21:32 +02:00
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Element name of the stanza extension.
|
2003-10-23 22:21:32 +02:00
|
|
|
*/
|
2014-07-14 19:22:02 +02:00
|
|
|
public static final String ELEMENT = "x";
|
2003-10-23 22:21:32 +02:00
|
|
|
|
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Namespace of the stanza extension.
|
2003-10-23 22:21:32 +02:00
|
|
|
*/
|
|
|
|
public static final String NAMESPACE = "jabber:x:conference";
|
|
|
|
|
2014-07-14 19:22:02 +02:00
|
|
|
private final String roomAddress;
|
2003-10-12 06:40:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new group chat invitation to the specified room address.
|
|
|
|
* GroupChat room addresses are in the form <tt>room@service</tt>,
|
2017-12-13 23:10:11 +01:00
|
|
|
* where <tt>service</tt> is the name of group chat server, such as
|
2003-10-12 06:40:08 +02:00
|
|
|
* <tt>chat.example.com</tt>.
|
|
|
|
*
|
|
|
|
* @param roomAddress the address of the group chat room.
|
|
|
|
*/
|
|
|
|
public GroupChatInvitation(String roomAddress) {
|
|
|
|
this.roomAddress = roomAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the address of the group chat room. GroupChat room addresses
|
|
|
|
* are in the form <tt>room@service</tt>, where <tt>service</tt> is
|
2017-12-13 23:10:11 +01:00
|
|
|
* the name of group chat server, such as <tt>chat.example.com</tt>.
|
2003-10-12 06:40:08 +02:00
|
|
|
*
|
|
|
|
* @return the address of the group chat room.
|
|
|
|
*/
|
|
|
|
public String getRoomAddress() {
|
|
|
|
return roomAddress;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2003-10-12 06:40:08 +02:00
|
|
|
public String getElementName() {
|
2014-07-14 19:22:02 +02:00
|
|
|
return ELEMENT;
|
2003-10-12 06:40:08 +02:00
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2003-10-12 06:40:08 +02:00
|
|
|
public String getNamespace() {
|
2003-10-23 22:21:32 +02:00
|
|
|
return NAMESPACE;
|
2003-10-12 06:40:08 +02:00
|
|
|
}
|
|
|
|
|
2014-07-14 19:22:02 +02:00
|
|
|
@Override
|
2018-04-25 14:20:18 +02:00
|
|
|
public XmlStringBuilder toXML(String enclosingNamespace) {
|
2014-07-14 19:22:02 +02:00
|
|
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
|
|
|
xml.attribute("jid", getRoomAddress());
|
|
|
|
xml.closeEmptyElement();
|
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
2014-09-16 22:14:10 +02:00
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Deprecated.
|
2014-09-16 22:14:10 +02:00
|
|
|
* @param packet
|
|
|
|
* @return the GroupChatInvitation or null
|
2015-02-05 11:17:27 +01:00
|
|
|
* @deprecated use {@link #from(Stanza)} instead
|
2014-09-16 22:14:10 +02:00
|
|
|
*/
|
|
|
|
@Deprecated
|
2015-02-05 11:17:27 +01:00
|
|
|
public static GroupChatInvitation getFrom(Stanza packet) {
|
2014-09-16 22:14:10 +02:00
|
|
|
return from(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Get the group chat invitation from the given stanza.
|
2014-09-16 22:14:10 +02:00
|
|
|
* @param packet
|
|
|
|
* @return the GroupChatInvitation or null
|
|
|
|
*/
|
2015-02-05 11:17:27 +01:00
|
|
|
public static GroupChatInvitation from(Stanza packet) {
|
2014-07-14 19:22:02 +02:00
|
|
|
return packet.getExtension(ELEMENT, NAMESPACE);
|
2003-10-12 06:40:08 +02:00
|
|
|
}
|
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
public static class Provider extends ExtensionElementProvider<GroupChatInvitation> {
|
2014-10-07 21:15:20 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public GroupChatInvitation parse(XmlPullParser parser,
|
|
|
|
int initialDepth) throws XmlPullParserException,
|
|
|
|
IOException {
|
2003-10-12 06:40:08 +02:00
|
|
|
String roomAddress = parser.getAttributeValue("", "jid");
|
|
|
|
// Advance to end of extension.
|
|
|
|
parser.next();
|
|
|
|
return new GroupChatInvitation(roomAddress);
|
|
|
|
}
|
|
|
|
}
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|