mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-05 20:51:07 +01:00
smack_1_5_1
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2639 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
aa32e12164
commit
7ae75258be
276 changed files with 40430 additions and 0 deletions
137
CopyOftrunk/documentation/extensions/dataforms.html
Normal file
137
CopyOftrunk/documentation/extensions/dataforms.html
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Data Forms</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="header">Data Forms</div><p>
|
||||
|
||||
Allows to exchange structured data between users and applications for common
|
||||
tasks such as registration and searching using Forms.
|
||||
|
||||
<ul>
|
||||
<li><a href="#gather">Create a Form to fill out</a></li>
|
||||
<li><a href="#fillout">Answer a Form</a></li>
|
||||
</ul>
|
||||
<b>JEP related:</b> <a href="http://www.jabber.org/jeps/jep-0004.html">JEP-4</a>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="gather">Create a Form to fill out</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
An XMPP entity may need to gather data from another XMPP entity. Therefore, the data-gathering
|
||||
entity will need to create a new Form, specify the fields that will conform the Form and finally
|
||||
send the Form to the data-providing entity.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to create a Form to fill out use the <i><b>Form</b></i>'s constructor passing the constant
|
||||
<b>Form.TYPE_FORM</b> as the parameter. The next step is to create the form fields and add them to
|
||||
the form. In order to create and customize a <i><b>FormField</b></i> use the <i><b>FormField</b></i>'s
|
||||
constructor specifying the variable name of the field as the parameter. Then use <b>setType(String type)</b>
|
||||
to set the field's type (e.g. FormField.TYPE_HIDDEN, FormField.TYPE_TEXT_SINGLE). Once we have the
|
||||
<i><b>Form</b></i> instance and the <i><b>FormFields</b></i> the last step is to send <b>addField(FormField field)</b>
|
||||
for each field that we want to add to the form.</p><p>
|
||||
|
||||
Once the form to fill out is finished we will want to send it in a message. Send <b>getDataFormToSend()</b> to
|
||||
the form and add the answer as an extension to the message to send.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to create and send a form to fill out: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Create a new form to gather data</font>
|
||||
Form formToSend = new Form(Form.TYPE_FORM);
|
||||
formToSend.setInstructions(
|
||||
"Fill out this form to report your case.\nThe case will be created automatically.");
|
||||
formToSend.setTitle("Case configurations");
|
||||
<font color="#3f7f5f">// Add a hidden variable to the form</font>
|
||||
FormField field = new FormField("hidden_var");
|
||||
field.setType(FormField.TYPE_HIDDEN);
|
||||
field.addValue("Some value for the hidden variable");
|
||||
formToSend.addField(field);
|
||||
<font color="#3f7f5f">// Add a fixed variable to the form</font>
|
||||
field = new FormField();
|
||||
field.addValue("Section 1: Case description");
|
||||
formToSend.addField(field);
|
||||
<font color="#3f7f5f">// Add a text-single variable to the form</font>
|
||||
field = new FormField("name");
|
||||
field.setLabel("Enter a name for the case");
|
||||
field.setType(FormField.TYPE_TEXT_SINGLE);
|
||||
formToSend.addField(field);
|
||||
<font color="#3f7f5f">// Add a text-multi variable to the form</font>
|
||||
field = new FormField("description");
|
||||
field.setLabel("Enter a description");
|
||||
field.setType(FormField.TYPE_TEXT_MULTI);
|
||||
formToSend.addField(field);
|
||||
|
||||
<font color="#3f7f5f">// Create a chat with "user2@host.com"</font>
|
||||
Chat chat = conn1.createChat("user2@host.com" );
|
||||
|
||||
Message msg = chat.createMessage();
|
||||
msg.setBody("To enter a case please fill out this form and send it back to me");
|
||||
<font color="#3f7f5f">// Add the form to fill out to the message to send</font>
|
||||
msg.addExtension(formToSend.getDataFormToSend());
|
||||
|
||||
<font color="#3f7f5f">// Send the message with the form to fill out</font>
|
||||
chat.sendMessage(msg);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="fillout">Answer a Form</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
Under many situations an XMPP entity could receive a form to fill out. For example, some hosts
|
||||
may require to fill out a form in order to register new users. Smack lets the data-providing entity
|
||||
to complete the form in an easy way and send it back to the data-gathering entity.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
The form to fill out contains useful information that could be used for rendering the form. But it
|
||||
cannot be used to actually complete it. Instead it's necessary to create a new form based on the original
|
||||
form whose purpose is to hold all the answers.</p><p>
|
||||
|
||||
In order to create a new <i><b>Form</b></i> to complete based on the original <i><b>Form</b></i> just send
|
||||
<b>createAnswerForm()</b> to the original <i><b>Form</b></i>. Once you have a valid form that could be actually
|
||||
completed all you have to do is send <b>setAnswer(String variable, String value)</b> to the form where variable
|
||||
is the variable of the <i><b>FormField</b></i> that you want to answer and value is the String representation
|
||||
of the answer. If the answer consist of several values you could then use <b>setAnswer(String variable, List values)</b>
|
||||
where values is a List of Strings.</p><p>
|
||||
|
||||
Once the form has been completed we will want to send it back in a message. Send <b>getDataFormToSend()</b> to
|
||||
the form and add the answer as an extension to the message to send back.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to retrieve a form to fill out, complete the form and send it back: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Get the message with the form to fill out</font>
|
||||
Message msg2 = chat2.nextMessage();
|
||||
<font color="#3f7f5f">// Retrieve the form to fill out from the message</font>
|
||||
Form formToRespond = Form.getFormFrom(msg2);
|
||||
<font color="#3f7f5f">// Obtain the form to send with the replies</font>
|
||||
Form completedForm = formToRespond.createAnswerForm();
|
||||
<font color="#3f7f5f">// Add the answers to the form</font>
|
||||
completedForm.setAnswer("name", "Credit card number invalid");
|
||||
completedForm.setAnswer(
|
||||
"description",
|
||||
"The ATM says that my credit card number is invalid. What's going on?");
|
||||
|
||||
msg2 = chat2.createMessage();
|
||||
msg2.setBody("To enter a case please fill out this form and send it back to me");
|
||||
<font color="#3f7f5f">// Add the completed form to the message to send back</font>
|
||||
msg2.addExtension(completedForm.getDataFormToSend());
|
||||
<font color="#3f7f5f">// Send the message with the completed form</font>
|
||||
chat2.sendMessage(msg2);
|
||||
</pre>
|
||||
</blockquote>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
236
CopyOftrunk/documentation/extensions/disco.html
Normal file
236
CopyOftrunk/documentation/extensions/disco.html
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Service Discovery</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="header">Service Discovery</div><p>
|
||||
|
||||
The service discovery extension allows to discover items and information about XMPP
|
||||
entities. Follow these links to learn how to use this extension.
|
||||
|
||||
<ul>
|
||||
<li><a href="#discoregister">Manage XMPP entity features</a></li>
|
||||
<li><a href="#disconodeinfo">Provide node information</a></li>
|
||||
<li><a href="#discoitems">Discover items associated with an XMPP entity</a></li>
|
||||
<li><a href="#discoinfo">Discover information about an XMPP entity</a></li>
|
||||
<li><a href="#discopublish">Publish publicly available items</a></li>
|
||||
</ul>
|
||||
<b>JEP related:</b> <a href="http://www.jabber.org/jeps/jep-0030.html">JEP-30</a>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="discoregister">Manage XMPP entity features</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
Any XMPP entity may receive a discovery request and must answer with its associated items or
|
||||
information. Therefore, your Smack client may receive a discovery request that must respond
|
||||
to (i.e., if your client supports XHTML-IM). This extension automatically responds to a
|
||||
discovery request with the information that you previously configured.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to configure the supported features by your client you should first obtain the
|
||||
ServiceDiscoveryManager associated with your XMPPConnection. To get your ServiceDiscoveryManager
|
||||
send <b>getInstanceFor(connection)</b> to the class <i><b>ServiceDiscoveryManager</b></i> where
|
||||
connection is your XMPPConnection.<br></p>
|
||||
|
||||
<p>Once you have your ServiceDiscoveryManager you will be able to manage the supported features. To
|
||||
register a new feature send <b>addFeature(feature)</b> to your <i><b>ServiceDiscoveryManager</b></i>
|
||||
where feature is a String that represents the supported feature. To remove a supported feature send
|
||||
<b>removeFeature(feature)</b> to your <i><b>ServiceDiscoveryManager</b></i> where feature is a
|
||||
String that represents the feature to remove.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to add and remove supported features: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Obtain the ServiceDiscoveryManager associated with my XMPPConnection</font>
|
||||
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
|
||||
<font color="#3f7f5f">// Register that a new feature is supported by this XMPP entity</font>
|
||||
discoManager.addFeature(namespace1);
|
||||
|
||||
<font color="#3f7f5f">// Remove the specified feature from the supported features by this XMPP entity</font>
|
||||
discoManager.removeFeature(namespace2);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="disconodeinfo">Provide node information</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
Your XMPP entity may receive a discovery request for items non-addressable as a JID such as
|
||||
the MUC rooms where you are joined. In order to answer the correct information it is necessary
|
||||
to configure the information providers associated to the items/nodes within the Smack client.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to configure the associated nodes within the Smack client you will need to create a
|
||||
NodeInformationProvider and register it with the <i><b>ServiceDiscoveryManager</b></i>. To get
|
||||
your ServiceDiscoveryManager send <b>getInstanceFor(connection)</b> to the class <i><b>ServiceDiscoveryManager</b></i>
|
||||
where connection is your XMPPConnection.<br></p>
|
||||
|
||||
<p>Once you have your ServiceDiscoveryManager you will be able to register information providers
|
||||
for the XMPP entity's nodes. To register a new node information provider send <b>setNodeInformationProvider(String node, NodeInformationProvider listener)</b>
|
||||
to your <i><b>ServiceDiscoveryManager</b></i> where node is the item non-addressable as a JID and
|
||||
listener is the <i><b>NodeInformationProvider</b></i> to register. To unregister a <i><b>NodeInformationProvider</b></i>
|
||||
send <b>removeNodeInformationProvider(String node)</b> to your <i><b>ServiceDiscoveryManager</b></i> where
|
||||
node is the item non-addressable as a JID whose information provider we want to unregister.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to register a NodeInformationProvider with a ServiceDiscoveryManager that will provide
|
||||
information concerning a node named "http://jabber.org/protocol/muc#rooms": <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Set the NodeInformationProvider that will provide information about the</font>
|
||||
<font color="#3f7f5f">// joined rooms whenever a disco request is received </font>
|
||||
ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(
|
||||
<font color="#0000FF">"http://jabber.org/protocol/muc#rooms"</font>,
|
||||
new NodeInformationProvider() {
|
||||
public Iterator getNodeItems() {
|
||||
ArrayList answer = new ArrayList();
|
||||
Iterator rooms = MultiUserChat.getJoinedRooms(connection);
|
||||
while (rooms.hasNext()) {
|
||||
answer.add(new DiscoverItems.Item((String)rooms.next()));
|
||||
}
|
||||
return answer.iterator();
|
||||
}
|
||||
});
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="discoitems">Discover items associated with an XMPP entity</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
In order to obtain information about a specific item you have to first discover the items available
|
||||
in an XMPP entity.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
<p>Once you have your ServiceDiscoveryManager you will be able to discover items associated with
|
||||
an XMPP entity. To discover the items of a given XMPP entity send <b>discoverItems(entityID)</b>
|
||||
to your <i><b>ServiceDiscoveryManager</b></i> where entityID is the ID of the entity. The message
|
||||
<b>discoverItems(entityID)</b> will answer an instance of <i><b>DiscoverItems</b></i> that contains
|
||||
the discovered items.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to discover the items associated with an online catalog service: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Obtain the ServiceDiscoveryManager associated with my XMPPConnection</font>
|
||||
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
|
||||
<font color="#3f7f5f">// Get the items of a given XMPP entity</font>
|
||||
<font color="#3f7f5f">// This example gets the items associated with online catalog service</font>
|
||||
DiscoverItems discoItems = discoManager.discoverItems("plays.shakespeare.lit");
|
||||
|
||||
<font color="#3f7f5f">// Get the discovered items of the queried XMPP entity</font>
|
||||
Iterator it = discoItems.getItems();
|
||||
<font color="#3f7f5f">// Display the items of the remote XMPP entity</font>
|
||||
while (it.hasNext()) {
|
||||
DiscoverItems.Item item = (DiscoverItems.Item) it.next();
|
||||
System.out.println(item.getEntityID());
|
||||
System.out.println(item.getNode());
|
||||
System.out.println(item.getName());
|
||||
}
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="discoinfo">Discover information about an XMPP entity</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
Once you have discovered the entity ID and name of an item, you may want to find out more
|
||||
about the item. The information desired generally is of two kinds: 1) The item's identity
|
||||
and 2) The features offered by the item.</p>
|
||||
|
||||
<p>This information helps you determine what actions are possible with regard to this
|
||||
item (registration, search, join, etc.) as well as specific feature types of interest, if
|
||||
any (e.g., for the purpose of feature negotiation).</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
<p>Once you have your ServiceDiscoveryManager you will be able to discover information associated with
|
||||
an XMPP entity. To discover the information of a given XMPP entity send <b>discoverInfo(entityID)</b>
|
||||
to your <i><b>ServiceDiscoveryManager</b></i> where entityID is the ID of the entity. The message
|
||||
<b>discoverInfo(entityID)</b> will answer an instance of <i><b>DiscoverInfo</b></i> that contains
|
||||
the discovered information.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to discover the information of a conference room: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Obtain the ServiceDiscoveryManager associated with my XMPPConnection</font>
|
||||
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
|
||||
<font color="#3f7f5f">// Get the information of a given XMPP entity</font>
|
||||
<font color="#3f7f5f">// This example gets the information of a conference room</font>
|
||||
DiscoverInfo discoInfo = discoManager.discoverInfo("balconyscene@plays.shakespeare.lit");
|
||||
|
||||
<font color="#3f7f5f">// Get the discovered identities of the remote XMPP entity</font>
|
||||
Iterator it = discoInfo.getIdentities();
|
||||
<font color="#3f7f5f">// Display the identities of the remote XMPP entity</font>
|
||||
while (it.hasNext()) {
|
||||
DiscoverInfo.Identity identity = (DiscoverInfo.Identity) it.next();
|
||||
System.out.println(identity.getName());
|
||||
System.out.println(identity.getType());
|
||||
System.out.println(identity.getCategory());
|
||||
}
|
||||
|
||||
<font color="#3f7f5f">// Check if room is password protected</font>
|
||||
discoInfo.containsFeature("muc_passwordprotected");
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="discopublish">Publish publicly available items</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
Publish your entity items to some kind of persistent storage. This enables other entities to query
|
||||
that entity using the disco#items namespace and receive a result even when the entity being queried
|
||||
is not online (or available).</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
<p>Once you have your ServiceDiscoveryManager you will be able to publish items to some kind of
|
||||
persistent storage. To publish the items of a given XMPP entity you have to first create an instance
|
||||
of <i><b>DiscoverItems</b></i> and configure it with the items to publish. Then you will have to
|
||||
send <b>publishItems(String entityID, DiscoverItems discoverItems)</b> to your <i><b>ServiceDiscoveryManager</b></i>
|
||||
where entityID is the address of the XMPP entity that will persist the items and discoverItems contains the items
|
||||
to publish.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to publish new items: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Obtain the ServiceDiscoveryManager associated with my XMPPConnection</font>
|
||||
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
|
||||
|
||||
<font color="#3f7f5f">// Create a DiscoverItems with the items to publish</font>
|
||||
DiscoverItems itemsToPublish = new DiscoverItems();
|
||||
DiscoverItems.Item itemToPublish = new DiscoverItems.Item("pubsub.shakespeare.lit");
|
||||
itemToPublish.setName("Avatar");
|
||||
itemToPublish.setNode("romeo/avatar");
|
||||
itemToPublish.setAction(DiscoverItems.Item.UPDATE_ACTION);
|
||||
itemsToPublish.addItem(itemToPublish);
|
||||
|
||||
<font color="#3f7f5f">// Publish the new items by sending them to the server</font>
|
||||
discoManager.publishItems("host", itemsToPublish);
|
||||
</pre>
|
||||
</blockquote>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
15
CopyOftrunk/documentation/extensions/index.html
Normal file
15
CopyOftrunk/documentation/extensions/index.html
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<html>
|
||||
|
||||
<head>
|
||||
<title>Smack Extensions User Manual</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<frameset cols="200,*">
|
||||
<frame src="toc.html" name="navFrame" target="mainFrame">
|
||||
<frame src="intro.html" name="mainFrame">
|
||||
</frameset>
|
||||
<noframes>
|
||||
<H2>Smack Extensions User Manual</H2>
|
||||
|
||||
<a href="toc.html">Smack Extensions User Manual</a></noframes></html>
|
||||
70
CopyOftrunk/documentation/extensions/intro.html
Normal file
70
CopyOftrunk/documentation/extensions/intro.html
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Smack Extensions User Manual</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="header">Smack Extensions Manual</div>
|
||||
<p>The XMPP protocol includes a base protocol and many optional extensions
|
||||
typically documented as "JEP's". Smack provides the org.jivesoftware.smack
|
||||
package for the core XMPP protocol, and the org.jivesoftware.smackx package for
|
||||
many of the protocol extensions.</p>
|
||||
|
||||
<p>This manual provides details about each of the "smackx" extensions, including what
|
||||
it is, how to use it, and some simple example code.<p>
|
||||
|
||||
<div class="subheader">Current Extensions</div><p>
|
||||
|
||||
<table border="0" width="85%" cellspacing="0" cellpadding="3" style="border:1px #bbb solid;">
|
||||
<tr bgcolor="#ddeeff">
|
||||
<td><b>Name</b></td><td><b>JEP #</b></td><td><b>Description</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="privatedata.html">Private Data</a></td>
|
||||
<td><a href="http://www.jabber.org/jeps/jep-0049.html">JEP-49</a></td>
|
||||
<td>Manages private data.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="xhtml.html">XHTML Messages</a></td>
|
||||
<td><a href="http://www.jabber.org/jeps/jep-0071.html">JEP-71</a></td>
|
||||
<td>Allows send and receiving formatted messages using XHTML.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="messageevents.html">Message Events</a></td>
|
||||
<td><a href="http://www.jabber.org/jeps/jep-0022.html">JEP-22</a></td>
|
||||
<td>Requests and responds to message events.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="dataforms.html">Data Forms</a></td>
|
||||
<td><a href="http://www.jabber.org/jeps/jep-0004.html">JEP-4</a></td>
|
||||
<td>Allows to gather data using Forms.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="muc.html">Multi User Chat</a></td>
|
||||
<td><a href="http://www.jabber.org/jeps/jep-0045.html">JEP-45</a></td>
|
||||
<td>Allows configuration of, participation in, and administration of individual text-based conference rooms.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="rosterexchange.html">Roster Item Exchange</a></td>
|
||||
<td><a href="http://www.jabber.org/jeps/jep-0093.html">JEP-93</a></td>
|
||||
<td>Allows roster data to be shared between users.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="time.html">Time Exchange</a></td>
|
||||
<td><a href="http://www.jabber.org/jeps/jep-0090.html">JEP-90</a></td>
|
||||
<td>Allows local time information to be shared between users.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="invitation.html">Group Chat Invitations</a></td>
|
||||
<td>N/A</td>
|
||||
<td>Send invitations to other users to join a group chat room.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="disco.html">Service Discovery</a></td>
|
||||
<td><a href="http://www.jabber.org/jeps/jep-0030.html">JEP-30</a></td>
|
||||
<td>Allows to discover services in XMPP entities.</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
60
CopyOftrunk/documentation/extensions/invitation.html
Normal file
60
CopyOftrunk/documentation/extensions/invitation.html
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Group Chat Invitations</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="header">Group Chat Invitations</div><p>
|
||||
|
||||
The group chat invitation packet extension is used to invite other
|
||||
users to a group chat room.
|
||||
|
||||
<ul>
|
||||
<li><a href="#send">Inviting Other Users</a></li>
|
||||
<li><a href="#listen">Listen for Invitations</a></li>
|
||||
</ul>
|
||||
|
||||
<p>
|
||||
<b>JEP related:</b> N/A -- this protocol is outdated now that the Multi-User Chat (MUC) JEP is available
|
||||
(<a href="http://www.jabber.org/jeps/jep-0045.html">JEP-45</a>). However, most
|
||||
existing clients still use this older protocol. Once MUC support becomes more
|
||||
widespread, this API may be deprecated.
|
||||
|
||||
<hr>
|
||||
|
||||
<p><div class="subheader"><a name="send">Inviting Other Users</a></div><p>
|
||||
|
||||
To use the GroupChatInvitation packet extension
|
||||
to invite another 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(<font color="#0000FF">"user@chat.example.com"</font>);
|
||||
message.setBody(<font color="#0000FF">"Join me for a group chat!"</font>);
|
||||
message.addExtension(new GroupChatInvitation(<font color="#0000FF">"room@chat.example.com"</font>));
|
||||
con.sendPacket(message);
|
||||
</pre>
|
||||
|
||||
The XML generated for the invitation portion of the code above would be:
|
||||
|
||||
<pre>
|
||||
<x xmlns="jabber:x:conference" jid="room@chat.example.com"/>
|
||||
</pre><p>
|
||||
|
||||
<hr>
|
||||
<div class="subheader"><a name="listen">Listening for Invitations</a></div><p>
|
||||
|
||||
To listen for group chat invitations, use a PacketExtensionFilter for the
|
||||
<tt>x</tt> element name and <tt>jabber:x:conference</tt> namespace, as in the
|
||||
following code example:
|
||||
|
||||
<pre>
|
||||
PacketFilter filter = new PacketExtensionFilter(<font color="#0000FF">"x"</font>, <font color="#0000FF">"jabber:x:conference"</font>);
|
||||
<font color="#3f7f5f">// Create a packet collector or packet listeners using the filter...</font>
|
||||
</pre>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
244
CopyOftrunk/documentation/extensions/messageevents.html
Normal file
244
CopyOftrunk/documentation/extensions/messageevents.html
Normal file
|
|
@ -0,0 +1,244 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Message Events</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="header">Message Events</div><p>
|
||||
|
||||
This extension is used to request and respond to events relating to the delivery,
|
||||
display, and composition of messages. There are three stages in this extension:<ol>
|
||||
<li>Request for event notifications,
|
||||
<li>Receive the event notification requests and send event notifications, and
|
||||
<li>Receive the event notifications.</ol>
|
||||
<p>For more information on each stage please follow these links:</p>
|
||||
<ul>
|
||||
<li><a href="#reqevnot">Requesting Event Notifications</a></li>
|
||||
<li><a href="#lstevnotreq">Reacting to Event Notification Requests</a></li>
|
||||
<li><a href="#lstevnot">Reacting to Event Notifications</a></li>
|
||||
</ul>
|
||||
<b>JEP related:</b> <a href="http://www.jabber.org/jeps/jep-0022.html">JEP-22</a>
|
||||
<hr>
|
||||
<div class="subheader"><a name="reqevnot">Requesting Event Notifications</a></div><p>
|
||||
<b>Description</b><p>
|
||||
|
||||
In order to receive event notifications for a given message you first have to specify
|
||||
which events are you interested in. Each message that you send has to request its own event
|
||||
notifications. Therefore, every message that you send as part of a chat should request its own event
|
||||
notifications.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
The class <i>MessageEventManager</i> provides an easy way for requesting event notifications. All you have to do is specify
|
||||
the message that requires the event notifications and the events that you are interested in.
|
||||
<p>Use the static method <i><b>MessageEventManager.addNotificationsRequests(Message message, boolean offline, boolean
|
||||
delivered, boolean displayed, boolean composing)</b></i> for requesting event notifications.
|
||||
</p>
|
||||
|
||||
<b>Example</b><p>
|
||||
Below you can find an example that logs in a user to the server, creates a message, adds the requests
|
||||
for notifications and sends the message.
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Connect to the server and log in</font>
|
||||
conn1 = new XMPPConnection(host);
|
||||
conn1.login(server_user1, pass1);
|
||||
|
||||
<font color="#3f7f5f">// Create a chat with user2</font>
|
||||
Chat chat1 = conn1.createChat(user2);
|
||||
|
||||
<font color="#3f7f5f">// Create a message to send</font>
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject(<font color="#0000FF">"Any subject you want"</font>);
|
||||
msg.setBody(<font color="#0000FF">"An interesting body comes here..."</font>);
|
||||
<font color="#3f7f5f">// Add to the message all the notifications requests (offline, delivered, displayed,</font>
|
||||
<font color="#3f7f5f">// composing)</font>
|
||||
MessageEventManager.addNotificationsRequests(msg, <font COLOR="#7f0055"><b>true</b></font>, <font COLOR="#7f0055"><b>true</b></font>, <font COLOR="#7f0055"><b>true</b></font>, <font COLOR="#7f0055"><b>true</b></font>);
|
||||
|
||||
<font color="#3f7f5f">// Send the message that contains the notifications request</font>
|
||||
chat1.sendMessage(msg);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="lstevnotreq">Reacting to Event Notification Requests</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
You can receive notification requests for the following events: delivered, displayed, composing and offline. You
|
||||
<b>must</b> listen for these requests and react accordingly.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
The general idea is to create a new <i>DefaultMessageEventRequestListener</i> that will listen to the event notifications
|
||||
requests and react with custom logic. Then you will have to add the listener to the
|
||||
<i>MessageEventManager</i> that works on
|
||||
the desired <i>XMPPConnection</i>.
|
||||
<p>Note that <i>DefaultMessageEventRequestListener</i> is a default implementation of the
|
||||
<i>MessageEventRequestListener</i> interface.
|
||||
The class <i>DefaultMessageEventRequestListener</i> automatically sends a delivered notification to the sender of the message
|
||||
if the sender has requested to be notified when the message is delivered. If you decide to create a new class that
|
||||
implements the <i>MessageEventRequestListener</i> interface, please remember to send the delivered notification.</p>
|
||||
<ul>
|
||||
<li>To create a new <i>MessageEventManager</i> use the <i><b>MessageEventManager(XMPPConnection)</b></i> constructor.
|
||||
</li>
|
||||
<li>To create an event notification requests listener create a subclass of <i><b>DefaultMessageEventRequestListener</b></i> or
|
||||
create a class that implements the <i><b>MessageEventRequestListener</b></i> interface.
|
||||
</li>
|
||||
<li>To add a listener to the messageEventManager use the MessageEventManager's message
|
||||
<i><b>addMessageEventRequestListener(MessageEventRequestListener)</b></i>.</li>
|
||||
</ul></p>
|
||||
|
||||
<b>Example</b><p>
|
||||
|
||||
Below you can find an example that connects two users to the server. One user will create a message, add the requests
|
||||
for notifications and will send the message to the other user. The other user will add a
|
||||
<i>DefaultMessageEventRequestListener</i>
|
||||
to a <i>MessageEventManager</i> that will listen and react to the event notification requested by the other user.
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Connect to the server and log in the users</font>
|
||||
conn1 = new XMPPConnection(host);
|
||||
conn1.login(server_user1, pass1);
|
||||
conn2 = new XMPPConnection(host);
|
||||
conn2.login(server_user2, pass2);
|
||||
|
||||
<font color="#3f7f5f">// User2 creates a MessageEventManager</font>
|
||||
MessageEventManager messageEventManager = new MessageEventManager(conn2);
|
||||
<font color="#3f7f5f">// User2 adds the listener that will react to the event notifications requests</font>
|
||||
messageEventManager.addMessageEventRequestListener(new DefaultMessageEventRequestListener() {
|
||||
public void deliveredNotificationRequested(
|
||||
String from,
|
||||
String packetID,
|
||||
MessageEventManager messageEventManager) {
|
||||
super.deliveredNotificationRequested(from, packetID, messageEventManager);
|
||||
<font color="#3f7f5f">// DefaultMessageEventRequestListener automatically responds that the message was delivered when receives this request</font>
|
||||
System.out.println(<font color="#0000FF">"Delivered Notification Requested (" + from + ", " + packetID + ")"</font>);
|
||||
}
|
||||
|
||||
public void displayedNotificationRequested(
|
||||
String from,
|
||||
String packetID,
|
||||
MessageEventManager messageEventManager) {
|
||||
super.displayedNotificationRequested(from, packetID, messageEventManager);
|
||||
<font color="#3f7f5f">// Send to the message's sender that the message was displayed</font>
|
||||
messageEventManager.sendDisplayedNotification(from, packetID);
|
||||
}
|
||||
|
||||
public void composingNotificationRequested(
|
||||
String from,
|
||||
String packetID,
|
||||
MessageEventManager messageEventManager) {
|
||||
super.composingNotificationRequested(from, packetID, messageEventManager);
|
||||
<font color="#3f7f5f">// Send to the message's sender that the message's receiver is composing a reply</font>
|
||||
messageEventManager.sendComposingNotification(from, packetID);
|
||||
}
|
||||
|
||||
public void offlineNotificationRequested(
|
||||
String from,
|
||||
String packetID,
|
||||
MessageEventManager messageEventManager) {
|
||||
super.offlineNotificationRequested(from, packetID, messageEventManager);
|
||||
<font color="#3f7f5f">// The XMPP server should take care of this request. Do nothing.</font>
|
||||
System.out.println(<font color="#0000FF">"Offline Notification Requested (" + from + ", " + packetID + ")"</font>);
|
||||
}
|
||||
});
|
||||
|
||||
<font color="#3f7f5f">// User1 creates a chat with user2</font>
|
||||
Chat chat1 = conn1.createChat(user2);
|
||||
|
||||
<font color="#3f7f5f">// User1 creates a message to send to user2</font>
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject(<font color="#0000FF">"Any subject you want"</font>);
|
||||
msg.setBody(<font color="#0000FF">"An interesting body comes here..."</font>);
|
||||
<font color="#3f7f5f">// User1 adds to the message all the notifications requests (offline, delivered, displayed,</font>
|
||||
<font color="#3f7f5f">// composing)</font>
|
||||
MessageEventManager.addNotificationsRequests(msg, <font COLOR="#7f0055"><b>true</b></font>, <font COLOR="#7f0055"><b>true</b></font>, <font COLOR="#7f0055"><b>true</b></font>, <font COLOR="#7f0055"><b>true</b></font>);
|
||||
|
||||
<font color="#3f7f5f">// User1 sends the message that contains the notifications request</font>
|
||||
chat1.sendMessage(msg);
|
||||
Thread.sleep(500);
|
||||
<font color="#3f7f5f">// User2 sends to the message's sender that the message's receiver cancelled composing a reply</font>
|
||||
messageEventManager.sendCancelledNotification(user1, msg.getPacketID());
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="lstevnot">Reacting to Event Notifications</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
Once you have requested for event notifications you will start to receive notifications of events. You can
|
||||
receive notifications of the following events: delivered, displayed, composing, offline and cancelled. You
|
||||
will probably want to react to some or all of these events.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
The general idea is to create a new <i>MessageEventNotificationListener</i> that will listen to the event notifications
|
||||
and react with custom logic. Then you will have to add the listener to the <i>MessageEventManager</i> that works on
|
||||
the desired <i>XMPPConnection</i>.
|
||||
<ul>
|
||||
<li>To create a new <i>MessageEventManager</i> use the <i><b>MessageEventManager(XMPPConnection)</b></i> constructor.
|
||||
</li>
|
||||
<li>To create an event notifications listener create a class that implements the <i><b>MessageEventNotificationListener</b></i>
|
||||
interface.
|
||||
</li>
|
||||
<li>To add a listener to the messageEventManager use the MessageEventManager's message
|
||||
<i><b>addMessageEventNotificationListener(MessageEventNotificationListener)</b></i>.</li>
|
||||
</ul></p>
|
||||
|
||||
<b>Example</b><p>
|
||||
Below you can find an example that logs in a user to the server, adds a <i>MessageEventNotificationListener</i>
|
||||
to a <i>MessageEventManager</i> that will listen and react to the event notifications, creates a message, adds
|
||||
the requests for notifications and sends the message.
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Connect to the server and log in</font>
|
||||
conn1 = new XMPPConnection(host);
|
||||
conn1.login(server_user1, pass1);
|
||||
|
||||
<font color="#3f7f5f">// Create a MessageEventManager</font>
|
||||
MessageEventManager messageEventManager = new MessageEventManager(conn1);
|
||||
<font color="#3f7f5f">// Add the listener that will react to the event notifications</font>
|
||||
messageEventManager.addMessageEventNotificationListener(new MessageEventNotificationListener() {
|
||||
public void deliveredNotification(String from, String packetID) {
|
||||
System.out.println(<font color="#0000FF">"The message has been delivered (" + from + ", " + packetID + ")"</font>);
|
||||
}
|
||||
|
||||
public void displayedNotification(String from, String packetID) {
|
||||
System.out.println(<font color="#0000FF">"The message has been displayed (" + from + ", " + packetID + ")"</font>);
|
||||
}
|
||||
|
||||
public void composingNotification(String from, String packetID) {
|
||||
System.out.println(<font color="#0000FF">"The message's receiver is composing a reply (" + from + ", " + packetID + ")"</font>);
|
||||
}
|
||||
|
||||
public void offlineNotification(String from, String packetID) {
|
||||
System.out.println(<font color="#0000FF">"The message's receiver is offline (" + from + ", " + packetID + ")"</font>);
|
||||
}
|
||||
|
||||
public void cancelledNotification(String from, String packetID) {
|
||||
System.out.println(<font color="#0000FF">"The message's receiver cancelled composing a reply (" + from + ", " + packetID + ")"</font>);
|
||||
}
|
||||
});
|
||||
|
||||
<font color="#3f7f5f">// Create a chat with user2</font>
|
||||
Chat chat1 = conn1.createChat(user2);
|
||||
|
||||
<font color="#3f7f5f">// Create a message to send</font>
|
||||
Message msg = chat1.createMessage();
|
||||
msg.setSubject(<font color="#0000FF">"Any subject you want"</font>);
|
||||
msg.setBody(<font color="#0000FF">"An interesting body comes here..."</font>);
|
||||
<font color="#3f7f5f">// Add to the message all the notifications requests (offline, delivered, displayed,</font>
|
||||
<font color="#3f7f5f">// composing)</font>
|
||||
MessageEventManager.addNotificationsRequests(msg, <font COLOR="#7f0055"><b>true</b></font>, <font COLOR="#7f0055"><b>true</b></font>, <font COLOR="#7f0055"><b>true</b></font>, <font COLOR="#7f0055"><b>true</b></font>);
|
||||
|
||||
<font color="#3f7f5f">// Send the message that contains the notifications request</font>
|
||||
chat1.sendMessage(msg);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
619
CopyOftrunk/documentation/extensions/muc.html
Normal file
619
CopyOftrunk/documentation/extensions/muc.html
Normal file
|
|
@ -0,0 +1,619 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Multi User Chat</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="header">Multi User Chat</div><p>
|
||||
|
||||
Allows configuration of, participation in, and administration of individual text-based conference rooms.<p>
|
||||
|
||||
<ul>
|
||||
<li><a href="#create">Create a new Room</a></li>
|
||||
<li><a href="#join">Join a room</a></li>
|
||||
<li><a href="#invite">Manage room invitations</a></li>
|
||||
<li><a href="#discomuc">Discover MUC support</a></li>
|
||||
<li><a href="#discojoin">Discover joined rooms</a></li>
|
||||
<li><a href="#discoroom">Discover room information</a></li>
|
||||
<li><a href="#privchat">Start a private chat</a></li>
|
||||
<li><a href="#subject">Manage changes on room subject</a></li>
|
||||
<li><a href="#role">Manage role modifications</a></li>
|
||||
<li><a href="#afiliation">Manage affiliation modifications</a></li>
|
||||
</ul>
|
||||
<b>JEP related:</b> <a href="http://www.jabber.org/jeps/jep-0045.html">JEP-45</a>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="create">Create a new Room</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
Allowed users may create new rooms. There are two types of rooms that you can create. <b>Instant rooms</b>
|
||||
which are available for immediate access and are automatically created based on some default
|
||||
configuration and <b>Reserved rooms</b> which are manually configured by the room creator before
|
||||
anyone is allowed to enter.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to create a room you will need to first create an instance of <i><b>MultiUserChat</b></i>. The
|
||||
room name passed to the constructor will be the name of the room to create. The next step is to send
|
||||
<b>create(String nickname)</b> to the <i><b>MultiUserChat</b></i> instance where nickname is the nickname
|
||||
to use when joining the room.</p><p>
|
||||
|
||||
Depending on the type of room that you want to create you will have to use different configuration forms. In
|
||||
order to create an Instant room just send <b>sendConfigurationForm(Form form)</b> where form is an empty form.
|
||||
But if you want to create a Reserved room then you should first get the room's configuration form, complete
|
||||
the form and finally send it back to the server.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to create an instant room: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Create a MultiUserChat using an XMPPConnection for a room</font>
|
||||
MultiUserChat muc = new MultiUserChat(conn1, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
|
||||
|
||||
<font color="#3f7f5f">// Create the room</font>
|
||||
muc.create(<font color="#0000FF">"testbot"</font>);
|
||||
|
||||
<font color="#3f7f5f">// Send an empty room configuration form which indicates that we want</font>
|
||||
<font color="#3f7f5f">// an instant room</font>
|
||||
muc.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
In this example we can see how to create a reserved room. The form is completed with default values: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Create a MultiUserChat using an XMPPConnection for a room</font>
|
||||
MultiUserChat muc = new MultiUserChat(conn1, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
|
||||
|
||||
<font color="#3f7f5f">// Create the room</font>
|
||||
muc.create(<font color="#0000FF">"testbot"</font>);
|
||||
|
||||
<font color="#3f7f5f">// Get the the room's configuration form</font>
|
||||
Form form = muc.getConfigurationForm();
|
||||
<font color="#3f7f5f">// Create a new form to submit based on the original form</font>
|
||||
Form submitForm = form.createAnswerForm();
|
||||
<font color="#3f7f5f">// Add default answers to the form to submit</font>
|
||||
for (Iterator fields = form.getFields(); fields.hasNext();) {
|
||||
FormField field = (FormField) fields.next();
|
||||
if (!FormField.TYPE_HIDDEN.equals(field.getType()) && field.getVariable() != null) {
|
||||
<font color="#3f7f5f">// Sets the default value as the answer</font>
|
||||
submitForm.setDefaultAnswer(field.getVariable());
|
||||
}
|
||||
}
|
||||
<font color="#3f7f5f">// Sets the new owner of the room</font>
|
||||
List owners = new ArrayList();
|
||||
owners.add(<font color="#0000FF">"johndoe@jabber.org"</font>);
|
||||
submitForm.setAnswer(<font color="#0000FF">"muc#roomconfig_roomowners"</font>, owners);
|
||||
<font color="#3f7f5f">// Send the completed form (with default values) to the server to configure the room</font>
|
||||
muc.sendConfigurationForm(submitForm);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="join">Join a room</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
Your usual first step in order to send messages to a room is to join the room. Multi User Chat allows
|
||||
to specify several parameter while joining a room. Basically you can control the amount of history to
|
||||
receive after joining the room as well as provide your nickname within the room and a password if the
|
||||
room is password protected.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to join a room you will need to first create an instance of <i><b>MultiUserChat</b></i>. The
|
||||
room name passed to the constructor will be the name of the room to join. The next step is to send
|
||||
<b>join(...)</b> to the <i><b>MultiUserChat</b></i> instance. But first you will have to decide which
|
||||
join message to send. If you want to just join the room without a password and without specifying the amount
|
||||
of history to receive then you could use <b>join(String nickname)</b> where nickname if your nickname in
|
||||
the room. In case the room requires a password in order to join you could then use
|
||||
<b>join(String nickname, String password)</b>. And finally, the most complete way to join a room is to send
|
||||
<b>join(String nickname, String password, DiscussionHistory history, long timeout)</b>
|
||||
where nickname is your nickname in the room, , password is your password to join the room, history is
|
||||
an object that specifies the amount of history to receive and timeout is the milliseconds to wait
|
||||
for a response from the server.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to join a room with a given nickname: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Create a MultiUserChat using an XMPPConnection for a room</font>
|
||||
MultiUserChat muc2 = new MultiUserChat(conn1, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
|
||||
|
||||
<font color="#3f7f5f">// User2 joins the new room</font>
|
||||
<font color="#3f7f5f">// The room service will decide the amount of history to send</font>
|
||||
muc2.join(<font color="#0000FF">"testbot2"</font>);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
In this example we can see how to join a room with a given nickname and password: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Create a MultiUserChat using an XMPPConnection for a room</font>
|
||||
MultiUserChat muc2 = new MultiUserChat(conn1, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
|
||||
|
||||
<font color="#3f7f5f">// User2 joins the new room using a password</font>
|
||||
<font color="#3f7f5f">// The room service will decide the amount of history to send</font>
|
||||
muc2.join(<font color="#0000FF">"testbot2"</font>, <font color="#0000FF">"password"</font>);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
In this example we can see how to join a room with a given nickname specifying the amount of history
|
||||
to receive: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Create a MultiUserChat using an XMPPConnection for a room</font>
|
||||
MultiUserChat muc2 = new MultiUserChat(conn1, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
|
||||
|
||||
<font color="#3f7f5f">// User2 joins the new room using a password and specifying</font>
|
||||
<font color="#3f7f5f">// the amount of history to receive. In this example we are requesting the last 5 messages.</font>
|
||||
DiscussionHistory history = new DiscussionHistory();
|
||||
history.setMaxStanzas(5);
|
||||
muc2.join(<font color="#0000FF">"testbot2"</font>, <font color="#0000FF">"password"</font>, history, SmackConfiguration.getPacketReplyTimeout());
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="invite">Manage room invitations</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
It can be useful to invite another user to a room in which one is an occupant. Depending on the
|
||||
room's type the invitee could receive a password to use to join the room and/or be added to the
|
||||
member list if the room is of type members-only. Smack allows to send room invitations and let
|
||||
potential invitees to listening for room invitations and inviters to listen for invitees'
|
||||
rejections.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to invite another user to a room you must be already joined to the room. Once you are
|
||||
joined just send <b>invite(String participant, String reason)</b> to the <i><b>MultiUserChat</b></i>
|
||||
where participant is the user to invite to the room (e.g. hecate@shakespeare.lit) and reason is
|
||||
the reason why the user is being invited.</p><p>
|
||||
|
||||
If potential invitees want to listen for room invitations then the invitee must add an <i><b>InvitationListener</b></i>
|
||||
to the <i><b>MultiUserChat</b></i> class. Since the <i><b>InvitationListener</b></i> is an <i>interface</i>,
|
||||
it is necessary to create a class that implements this <i>interface</i>. If an inviter wants to
|
||||
listen for room invitation rejections, just add an <i><b>InvitationRejectionListener</b></i>
|
||||
to the <i><b>MultiUserChat</b></i>. <i><b>InvitationRejectionListener</b></i> is also an
|
||||
interface so you will need to create a class that implements this interface.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to invite another user to the room and lister for possible rejections: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// User2 joins the room</font>
|
||||
MultiUserChat muc2 = new MultiUserChat(conn2, room);
|
||||
muc2.join(<font color="#0000FF">"testbot2"</font>);
|
||||
|
||||
<font color="#3f7f5f">// User2 listens for invitation rejections</font>
|
||||
muc2.addInvitationRejectionListener(new InvitationRejectionListener() {
|
||||
public void invitationDeclined(String invitee, String reason) {
|
||||
<font color="#3f7f5f">// Do whatever you need here...</font>
|
||||
}
|
||||
});
|
||||
|
||||
<font color="#3f7f5f">// User2 invites user3 to join to the room</font>
|
||||
muc2.invite(<font color="#0000FF">"user3@host.org/Smack"</font>, <font color="#0000FF">"Meet me in this excellent room"</font>);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
In this example we can see how to listen for room invitations and decline invitations: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// User3 listens for MUC invitations</font>
|
||||
MultiUserChat.addInvitationListener(conn3, new InvitationListener() {
|
||||
public void invitationReceived(XMPPConnection conn, String room, String inviter, String reason, String password) {
|
||||
<font color="#3f7f5f">// Reject the invitation</font>
|
||||
MultiUserChat.decline(conn, room, inviter, <font color="#0000FF">"I'm busy right now"</font>);
|
||||
}
|
||||
});
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="discomuc">Discover MUC support</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
A user may want to discover if one of the user's contacts supports the Multi-User Chat protocol.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to discover if one of the user's contacts supports MUC just send
|
||||
<b>isServiceEnabled(XMPPConnection connection, String user)</b> to the <i><b>MultiUserChat</b></i>
|
||||
class where user is a fully qualified XMPP ID, e.g. jdoe@example.com. You will receive
|
||||
a boolean indicating whether the user supports MUC or not.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to discover support of MUC: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Discover whether user3@host.org supports MUC or not</font>
|
||||
boolean supports = MultiUserChat.isServiceEnabled(conn, <font color="#0000FF">"user3@host.org/Smack"</font>);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="discojoin">Discover joined rooms</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
A user may also want to query a contact regarding which rooms the contact is in.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to get the rooms where a user is in just send
|
||||
<b>getJoinedRooms(XMPPConnection connection, String user)</b> to the <i><b>MultiUserChat</b></i>
|
||||
class where user is a fully qualified XMPP ID, e.g. jdoe@example.com. You will get an Iterator
|
||||
of Strings as an answer where each String represents a room name.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to get the rooms where a user is in: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Get the rooms where user3@host.org has joined</font>
|
||||
Iterator joinedRooms = MultiUserChat.getJoinedRooms(conn, <font color="#0000FF">"user3@host.org/Smack"</font>);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="discoroom">Discover room information</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
A user may need to discover information about a room without having to actually join the room. The server
|
||||
will provide information only for public rooms.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to discover information about a room just send <b>getRoomInfo(XMPPConnection connection, String room)</b>
|
||||
to the <i><b>MultiUserChat</b></i> class where room is the XMPP ID of the room, e.g.
|
||||
roomName@conference.myserver. You will get a RoomInfo object that contains the discovered room
|
||||
information.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to discover information about a room: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Discover information about the room roomName@conference.myserver</font>
|
||||
RoomInfo info = MultiUserChat.getRoomInfo(conn, <font color="#0000FF">"roomName@conference.myserver"</font>);
|
||||
System.out.println("Number of occupants:" + info.getOccupantsCount());
|
||||
System.out.println("Room Subject:" + info.getSubject());
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="privchat">Start a private chat</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
A room occupant may want to start a private chat with another room occupant even though they
|
||||
don't know the fully qualified XMPP ID (e.g. jdoe@example.com) of each other.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
To create a private chat with another room occupant just send <b>createPrivateChat(String participant)</b>
|
||||
to the <i><b>MultiUserChat</b></i> that you used to join the room. The parameter participant is the
|
||||
occupant unique room JID (e.g. 'darkcave@macbeth.shakespeare.lit/Paul'). You will receive
|
||||
a regular <i><b>Chat</b></i> object that you can use to chat with the other room occupant.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to start a private chat with another room occupant: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Start a private chat with another participant</font>
|
||||
Chat chat = muc2.createPrivateChat(<font color="#0000FF">"myroom@conference.jabber.org/johndoe"</font>);
|
||||
chat.sendMessage(<font color="#0000FF">"Hello there"</font>);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="subject">Manage changes on room subject</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
A common feature of multi-user chat rooms is the ability to change the subject within the room. As a
|
||||
default, only users with a role of "moderator" are allowed to change the subject in a room. Although
|
||||
some rooms may be configured to allow a mere participant or even a visitor to change the subject.</p><p>
|
||||
|
||||
Every time the room's subject is changed you may want to be notified of the modification. The new subject
|
||||
could be used to display an in-room message.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to modify the room's subject just send <b>changeSubject(String subject)</b> to the
|
||||
<i><b>MultiUserChat</b></i> that you used to join the room where subject is the new room's subject. On
|
||||
the other hand, if you want to be notified whenever the room's subject is modified you should add a
|
||||
<i><b>SubjectUpdatedListener</b></i> to the <i><b>MultiUserChat</b></i> by sending
|
||||
<b>addSubjectUpdatedListener(SubjectUpdatedListener listener)</b> to the <i><b>MultiUserChat</b></i>.
|
||||
Since the <i><b>SubjectUpdatedListener</b></i> is an <i>interface</i>, it is necessary to create a class
|
||||
that implements this <i>interface</i>.</p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to change the room's subject and react whenever the room's subject is
|
||||
modified: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// An occupant wants to be notified every time the room's subject is changed</font>
|
||||
muc3.addSubjectUpdatedListener(new SubjectUpdatedListener() {
|
||||
public void subjectUpdated(String subject, String from) {
|
||||
....
|
||||
}
|
||||
});
|
||||
|
||||
<font color="#3f7f5f">// A room's owner changes the room's subject</font>
|
||||
muc2.changeSubject(<font color="#0000FF">"New Subject"</font>);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="role">Manage role modifications</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
There are four defined roles that an occupant can have:</p>
|
||||
<ol start="" type="">
|
||||
<li>Moderator</li>
|
||||
<li>Participant</li>
|
||||
<li>Visitor</li>
|
||||
<li>None (the absence of a role)</li>
|
||||
</ol><p>
|
||||
|
||||
These roles are temporary in that they do not persist across a user's visits to the room
|
||||
and can change during the course of an occupant's visit to the room.</p><p>
|
||||
|
||||
A moderator is the most powerful occupant within the context of the room, and can to some
|
||||
extent manage other occupants' roles in the room. A participant has fewer privileges than a
|
||||
moderator, although he or she always has the right to speak. A visitor is a more restricted
|
||||
role within the context of a moderated room, since visitors are not allowed to send messages
|
||||
to all occupants.</p><p>
|
||||
|
||||
Roles are granted, revoked, and maintained based on the occupant's room nickname or full
|
||||
JID. Whenever an occupant's role is changed Smack will trigger specific events.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to grant voice (i.e. make someone a <i>participant</i>) just send the message
|
||||
<b>grantVoice(String nickname)</b> to <i><b>MultiUserChat</b></i>. Use <b>revokeVoice(String nickname)</b>
|
||||
to revoke the occupant's voice (i.e. make the occupant a <i>visitor</i>).</p><p>
|
||||
|
||||
In order to grant moderator privileges to a participant or visitor just send the message
|
||||
<b>grantModerator(String nickname)</b> to <i><b>MultiUserChat</b></i>. Use <b>revokeModerator(String nickname)</b>
|
||||
to revoke the moderator privilege from the occupant thus making the occupant a participant.</p><p>
|
||||
|
||||
Smack allows you to listen for role modification events. If you are interested in listening role modification
|
||||
events of any occupant then use the listener <b><i>ParticipantStatusListener</i></b>. But if you are interested
|
||||
in listening for your own role modification events, use the listener <b><i>UserStatusListener</i></b>. Both listeners
|
||||
should be added to the <i><b>MultiUserChat</b></i> by using
|
||||
<b>addParticipantStatusListener(ParticipantStatusListener listener)</b> or
|
||||
<b>addUserStatusListener(UserStatusListener listener)</b> respectively. These listeners include several notification
|
||||
events but you may be interested in just a few of them. Smack provides default implementations for these listeners
|
||||
avoiding you to implement all the interfaces' methods. The default implementations are <b><i>DefaultUserStatusListener</i></b>
|
||||
and <b><i>DefaultParticipantStatusListener</i></b>. Below you will find the sent messages to the listeners whenever
|
||||
an occupant's role has changed.</p><p>
|
||||
|
||||
These are the triggered events when the role has been upgraded:
|
||||
</p>
|
||||
<table border="1">
|
||||
<tr><td><b>Old</b></td><td><b>New</b></td><td><b>Events</b></td></tr>
|
||||
|
||||
<tr><td>None</td><td>Visitor</td><td>--</td></tr>
|
||||
<tr><td>Visitor</td><td>Participant</td><td>voiceGranted</td></tr>
|
||||
<tr><td>Participant</td><td>Moderator</td><td>moderatorGranted</td></tr>
|
||||
|
||||
<tr><td>None</td><td>Participant</td><td>voiceGranted</td></tr>
|
||||
<tr><td>None</td><td>Moderator</td><td>voiceGranted + moderatorGranted</td></tr>
|
||||
<tr><td>Visitor</td><td>Moderator</td><td>voiceGranted + moderatorGranted</td></tr>
|
||||
</table><p>
|
||||
|
||||
These are the triggered events when the role has been downgraded:
|
||||
</p>
|
||||
<table border="1">
|
||||
<tr><td><b>Old</b></td><td><b>New</b></td><td><b>Events</b></td></tr>
|
||||
|
||||
<tr><td>Moderator</td><td>Participant</td><td>moderatorRevoked</td></tr>
|
||||
<tr><td>Participant</td><td>Visitor</td><td>voiceRevoked</td></tr>
|
||||
<tr><td>Visitor</td><td>None</td><td>kicked</td></tr>
|
||||
|
||||
<tr><td>Moderator</td><td>Visitor</td><td>voiceRevoked + moderatorRevoked</td></tr>
|
||||
<tr><td>Moderator</td><td>None</td><td>kicked</td></tr>
|
||||
<tr><td>Participant</td><td>None</td><td>kicked</td></tr>
|
||||
</table></p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to grant voice to a visitor and listen for the notification events: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// User1 creates a room</font>
|
||||
muc = new MultiUserChat(conn1, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
|
||||
muc.create(<font color="#0000FF">"testbot"</font>);
|
||||
|
||||
<font color="#3f7f5f">// User1 (which is the room owner) configures the room as a moderated room</font>
|
||||
Form form = muc.getConfigurationForm();
|
||||
Form answerForm = form.createAnswerForm();
|
||||
answerForm.setAnswer(<font color="#0000FF">"muc#roomconfig_moderatedroom"</font>, <font color="#0000FF">"1"</font>);
|
||||
muc.sendConfigurationForm(answerForm);
|
||||
|
||||
<font color="#3f7f5f">// User2 joins the new room (as a visitor)</font>
|
||||
MultiUserChat muc2 = new MultiUserChat(conn2, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
|
||||
muc2.join(<font color="#0000FF">"testbot2"</font>);
|
||||
<font color="#3f7f5f">// User2 will listen for his own "voice" notification events</font>
|
||||
muc2.addUserStatusListener(new DefaultUserStatusListener() {
|
||||
public void voiceGranted() {
|
||||
super.voiceGranted();
|
||||
...
|
||||
}
|
||||
public void voiceRevoked() {
|
||||
super.voiceRevoked();
|
||||
...
|
||||
}
|
||||
});
|
||||
|
||||
<font color="#3f7f5f">// User3 joins the new room (as a visitor)</font>
|
||||
MultiUserChat muc3 = new MultiUserChat(conn3, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
|
||||
muc3.join(<font color="#0000FF">"testbot3"</font>);
|
||||
<font color="#3f7f5f">// User3 will lister for other occupants "voice" notification events</font>
|
||||
muc3.addParticipantStatusListener(new DefaultParticipantStatusListener() {
|
||||
public void voiceGranted(String participant) {
|
||||
super.voiceGranted(participant);
|
||||
...
|
||||
}
|
||||
|
||||
public void voiceRevoked(String participant) {
|
||||
super.voiceRevoked(participant);
|
||||
...
|
||||
}
|
||||
});
|
||||
|
||||
<font color="#3f7f5f">// The room's owner grants voice to user2</font>
|
||||
muc.grantVoice(<font color="#0000FF">"testbot2"</font>);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="afiliation">Manage affiliation modifications</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
There are five defined affiliations that a user can have in relation to a room:</p>
|
||||
<ol start="" type="">
|
||||
<li>Owner</li>
|
||||
<li>Admin</li>
|
||||
<li>Member</li>
|
||||
<li>Outcast</li>
|
||||
<li>None (the absence of an affiliation)</li>
|
||||
</ol><p>
|
||||
|
||||
These affiliations are semi-permanent in that they persist across a user's visits to the room and
|
||||
are not affected by happenings in the room. Affiliations are granted, revoked, and maintained
|
||||
based on the user's bare JID.</p><p>
|
||||
|
||||
If a user without a defined affiliation enters a room, the user's affiliation is defined as "none";
|
||||
however, this affiliation does not persist across visits.</p><p>
|
||||
|
||||
Owners and admins are by definition immune from certain actions. Specifically, an owner or admin cannot
|
||||
be kicked from a room and cannot be banned from a room. An admin must first lose his or her affiliation
|
||||
(i.e., have an affiliation of "none" or "member") before such actions could be performed
|
||||
on them.</p><p>
|
||||
|
||||
The member affiliation provides a way for a room owner or admin to specify a "whitelist" of users
|
||||
who are allowed to enter a members-only room. When a member enters a members-only room, his or her affiliation
|
||||
does not change, no matter what his or her role is. The member affiliation also provides a way for users to
|
||||
effectively register with an open room and thus be permanently associated with that room in some way (one
|
||||
result may be that the user's nickname is reserved in the room).</p><p>
|
||||
|
||||
An outcast is a user who has been banned from a room and who is not allowed to enter the room. Whenever a
|
||||
user's affiliation is changed Smack will trigger specific events.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to grant membership to a room, administrator privileges or owner priveliges just send
|
||||
<b>grantMembership(String jid)</b>, <b>grantAdmin(String jid)</b> or <b>grantOwnership(String jid)</b>
|
||||
to <i><b>MultiUserChat</b></i> respectively. Use <b>revokeMembership(String jid)</b>, <b>revokeAdmin(String jid)</b>
|
||||
or <b>revokeOwnership(String jid)</b> to revoke the membership to a room, administrator privileges or
|
||||
owner priveliges respectively.</p><p>
|
||||
|
||||
In order to ban a user from the room just send the message <b>banUser(String jid, String reason)</b> to
|
||||
<i><b>MultiUserChat</b></i>.</p><p>
|
||||
|
||||
Smack allows you to listen for affiliation modification events. If you are interested in listening affiliation modification
|
||||
events of any user then use the listener <b><i>ParticipantStatusListener</i></b>. But if you are interested
|
||||
in listening for your own affiliation modification events, use the listener <b><i>UserStatusListener</i></b>. Both listeners
|
||||
should be added to the <i><b>MultiUserChat</b></i> by using
|
||||
<b>addParticipantStatusListener(ParticipantStatusListener listener)</b> or
|
||||
<b>addUserStatusListener(UserStatusListener listener)</b> respectively. These listeners include several notification
|
||||
events but you may be interested in just a few of them. Smack provides default implementations for these listeners
|
||||
avoiding you to implement all the interfaces' methods. The default implementations are <b><i>DefaultUserStatusListener</i></b>
|
||||
and <b><i>DefaultParticipantStatusListener</i></b>. Below you will find the sent messages to the listeners whenever
|
||||
a user's affiliation has changed.</p><p>
|
||||
|
||||
These are the triggered events when the affiliation has been upgraded:
|
||||
</p>
|
||||
<table border="1">
|
||||
<tr><td><b>Old</b></td><td><b>New</b></td><td><b>Events</b></td></tr>
|
||||
|
||||
<tr><td>None</td><td>Member</td><td>membershipGranted</td></tr>
|
||||
<tr><td>Member</td><td>Admin</td><td>membershipRevoked + adminGranted</td></tr>
|
||||
<tr><td>Admin</td><td>Owner</td><td>adminRevoked + ownershipGranted</td></tr>
|
||||
|
||||
<tr><td>None</td><td>Admin</td><td>adminGranted</td></tr>
|
||||
<tr><td>None</td><td>Owner</td><td>ownershipGranted</td></tr>
|
||||
<tr><td>Member</td><td>Owner</td><td>membershipRevoked + ownershipGranted</td></tr>
|
||||
</table><p>
|
||||
|
||||
These are the triggered events when the affiliation has been downgraded:
|
||||
</p>
|
||||
<table border="1">
|
||||
<tr><td><b>Old</b></td><td><b>New</b></td><td><b>Events</b></td></tr>
|
||||
|
||||
<tr><td>Owner</td><td>Admin</td><td>ownershipRevoked + adminGranted</td></tr>
|
||||
<tr><td>Admin</td><td>Member</td><td>adminRevoked + membershipGranted</td></tr>
|
||||
<tr><td>Member</td><td>None</td><td>membershipRevoked</td></tr>
|
||||
|
||||
<tr><td>Owner</td><td>Member</td><td>ownershipRevoked + membershipGranted</td></tr>
|
||||
<tr><td>Owner</td><td>None</td><td>ownershipRevoked</td></tr>
|
||||
<tr><td>Admin</td><td>None</td><td>adminRevoked</td></tr>
|
||||
<tr><td><i>Anyone</i></td><td>Outcast</td><td>banned</td></tr>
|
||||
</table></p>
|
||||
|
||||
<b>Examples</b><p>
|
||||
|
||||
In this example we can see how to grant admin privileges to a user and listen for the notification events: <br>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// User1 creates a room</font>
|
||||
muc = new MultiUserChat(conn1, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
|
||||
muc.create(<font color="#0000FF">"testbot"</font>);
|
||||
|
||||
<font color="#3f7f5f">// User1 (which is the room owner) configures the room as a moderated room</font>
|
||||
Form form = muc.getConfigurationForm();
|
||||
Form answerForm = form.createAnswerForm();
|
||||
answerForm.setAnswer(<font color="#0000FF">"muc#roomconfig_moderatedroom"</font>, <font color="#0000FF">"1"</font>);
|
||||
muc.sendConfigurationForm(answerForm);
|
||||
|
||||
<font color="#3f7f5f">// User2 joins the new room (as a visitor)</font>
|
||||
MultiUserChat muc2 = new MultiUserChat(conn2, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
|
||||
muc2.join(<font color="#0000FF">"testbot2"</font>);
|
||||
<font color="#3f7f5f">// User2 will listen for his own admin privileges</font>
|
||||
muc2.addUserStatusListener(new DefaultUserStatusListener() {
|
||||
public void membershipRevoked() {
|
||||
super.membershipRevoked();
|
||||
...
|
||||
}
|
||||
public void adminGranted() {
|
||||
super.adminGranted();
|
||||
...
|
||||
}
|
||||
});
|
||||
|
||||
<font color="#3f7f5f">// User3 joins the new room (as a visitor)</font>
|
||||
MultiUserChat muc3 = new MultiUserChat(conn3, <font color="#0000FF">"myroom@conference.jabber.org"</font>);
|
||||
muc3.join(<font color="#0000FF">"testbot3"</font>);
|
||||
<font color="#3f7f5f">// User3 will lister for other users admin privileges</font>
|
||||
muc3.addParticipantStatusListener(new DefaultParticipantStatusListener() {
|
||||
public void membershipRevoked(String participant) {
|
||||
super.membershipRevoked(participant);
|
||||
...
|
||||
}
|
||||
public void adminGranted(String participant) {
|
||||
super.adminGranted(participant);
|
||||
...
|
||||
}
|
||||
});
|
||||
|
||||
<font color="#3f7f5f">// The room's owner grants admin privileges to user2</font>
|
||||
muc.grantAdmin(<font color="#0000FF">"user2@jabber.org"</font>);
|
||||
</pre>
|
||||
</blockquote>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
30
CopyOftrunk/documentation/extensions/privatedata.html
Normal file
30
CopyOftrunk/documentation/extensions/privatedata.html
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Private Data</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="header">Private Data</div><p>
|
||||
|
||||
Manages private data, which is a mechanism to allow users to store arbitrary XML
|
||||
data on an XMPP server. Each private data chunk is defined by a element name and
|
||||
XML namespace. Example private data:
|
||||
|
||||
<pre>
|
||||
<color xmlns="http://example.com/xmpp/color">
|
||||
<favorite>blue</blue>
|
||||
<leastFavorite>puce</leastFavorite>
|
||||
</color>
|
||||
</pre><p>
|
||||
|
||||
<b>JEP related:</b> <a href="http://www.jabber.org/jeps/jep-0049.html">JEP-49</a>
|
||||
|
||||
<hr>
|
||||
|
||||
<em>More coming soon.</em>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
179
CopyOftrunk/documentation/extensions/rosterexchange.html
Normal file
179
CopyOftrunk/documentation/extensions/rosterexchange.html
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Roster Item Exchange</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="header">Roster Item Exchange</div><p>
|
||||
This extension is used to send rosters, roster groups and roster entries from one XMPP
|
||||
Entity to another. It also provides an easy way to hook up custom logic when entries
|
||||
are received from other XMPP clients.
|
||||
<p>Follow these links to learn how to send and receive roster items:</p>
|
||||
<ul>
|
||||
<li><a href="#riesendroster">Send a complete roster</a></li>
|
||||
<li><a href="#riesendgroup">Send a roster's group</a></li>
|
||||
<li><a href="#riesendentry">Send a roster's entry</a></li>
|
||||
<li><a href="#riercventry">Receive roster entries</a></li>
|
||||
</ul>
|
||||
<b>JEP related:</b> <a href="http://www.jabber.org/jeps/jep-0093.html">JEP-93</a>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="riesendroster">Send a entire roster</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
Sometimes it is useful to send a whole roster to another user. Smack provides a
|
||||
very easy way to send a complete roster to another XMPP client.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
Create an instance of <i><b>RosterExchangeManager</b></i> and use the <b>#send(Roster, String)</b>
|
||||
message to send a roster to a given user. The first parameter is the roster to send and
|
||||
the second parameter is the id of the user that will receive the roster entries.</p>
|
||||
|
||||
<b>Example</b><p>
|
||||
|
||||
In this example we can see how user1 sends his roster to user2.
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Connect to the server and log in</font>
|
||||
conn1 = new XMPPConnection(host);
|
||||
conn1.login(server_user1, pass1);
|
||||
|
||||
<font color="#3f7f5f">// Create a new roster exchange manager on conn1</font>
|
||||
RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1);
|
||||
<font color="#3f7f5f">// Send user1's roster to user2</font>
|
||||
rosterExchangeManager.send(conn1.getRoster(), user2);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="riesendgroup">Send a roster group</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
It is also possible to send a roster group to another XMPP client. A roster group groups
|
||||
a set of roster entries under a name.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
Create an instance of <i><b>RosterExchangeManager</b></i> and use the <b>#send(RosterGroup, String)</b>
|
||||
message to send a roster group to a given user. The first parameter is the roster group to send and
|
||||
the second parameter is the id of the user that will receive the roster entries.</p>
|
||||
|
||||
<b>Example</b><p>
|
||||
|
||||
In this example we can see how user1 sends his roster groups to user2.
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Connect to the server and log in</font>
|
||||
conn1 = new XMPPConnection(host);
|
||||
conn1.login(server_user1, pass1);
|
||||
|
||||
<font color="#3f7f5f">// Create a new roster exchange manager on conn1</font>
|
||||
RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1);
|
||||
<font color="#3f7f5f">// Send user1's RosterGroups to user2</font>
|
||||
for (Iterator it = conn1.getRoster().getGroups(); it.hasNext(); )
|
||||
rosterExchangeManager.send((RosterGroup)it.next(), user2);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="riesendentry">Send a roster entry</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
Sometimes you may need to send a single roster entry to another XMPP client. Smack also lets you send
|
||||
items at this granularity level.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
Create an instance of <i><b>RosterExchangeManager</b></i> and use the <b>#send(RosterEntry, String)</b>
|
||||
message to send a roster entry to a given user. The first parameter is the roster entry to send and
|
||||
the second parameter is the id of the user that will receive the roster entries.</p>
|
||||
|
||||
<b>Example</b><p>
|
||||
|
||||
In this example we can see how user1 sends a roster entry to user2.
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Connect to the server and log in</font>
|
||||
conn1 = new XMPPConnection(host);
|
||||
conn1.login(server_user1, pass1);
|
||||
|
||||
<font color="#3f7f5f">// Create a new roster exchange manager on conn1</font>
|
||||
RosterExchangeManager rosterExchangeManager = new RosterExchangeManager(conn1);
|
||||
<font color="#3f7f5f">// Send a roster entry (any) to user2</font>
|
||||
rosterExchangeManager1.send((RosterEntry)conn1.getRoster().getEntries().next(), user2);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="riercventry">Receive roster entries</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
Since roster items are sent between XMPP clients, it is necessary to listen to possible roster entries
|
||||
receptions. Smack provides a mechanism that you can use to execute custom logic when roster entries are
|
||||
received.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
<ol>
|
||||
<li>Create a class that implements the <i><b>RosterExchangeListener</b></i> interface.</li>
|
||||
<li>Implement the method <b>entriesReceived(String, Iterator)</b> that will be called when new entries
|
||||
are received with custom logic.</li>
|
||||
<li>Add the listener to the <i>RosterExchangeManager</i> that works on the desired <i>XMPPConnection</i>.</li>
|
||||
</ol></p>
|
||||
|
||||
<b>Example</b><p>
|
||||
|
||||
In this example we can see how user1 sends a roster entry to user2 and user2 adds the received
|
||||
entries to his roster.
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Connect to the server and log in the users</font>
|
||||
conn1 = new XMPPConnection(host);
|
||||
conn1.login(server_user1, pass1);
|
||||
conn2 = new XMPPConnection(host);
|
||||
conn2.login(server_user2, pass2);
|
||||
final Roster user2_roster = conn2.getRoster();
|
||||
|
||||
<font color="#3f7f5f">// Create a RosterExchangeManager that will help user2 to listen and accept
|
||||
the entries received</font>
|
||||
RosterExchangeManager rosterExchangeManager2 = new RosterExchangeManager(conn2);
|
||||
<font color="#3f7f5f">// Create a RosterExchangeListener that will iterate over the received roster entries</font>
|
||||
RosterExchangeListener rosterExchangeListener = new RosterExchangeListener() {
|
||||
public void entriesReceived(String from, Iterator remoteRosterEntries) {
|
||||
while (remoteRosterEntries.hasNext()) {
|
||||
try {
|
||||
<font color="#3f7f5f">// Get the received entry</font>
|
||||
RemoteRosterEntry remoteRosterEntry = (RemoteRosterEntry) remoteRosterEntries.next();
|
||||
<font color="#3f7f5f">// Display the remote entry on the console</font>
|
||||
System.out.println(remoteRosterEntry);
|
||||
<font color="#3f7f5f">// Add the entry to the user2's roster</font>
|
||||
user2_roster.createEntry(
|
||||
remoteRosterEntry.getUser(),
|
||||
remoteRosterEntry.getName(),
|
||||
remoteRosterEntry.getGroupArrayNames());
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
<font color="#3f7f5f">// Add the RosterExchangeListener to the RosterExchangeManager that user2 is using</font>
|
||||
rosterExchangeManager2.addRosterListener(rosterExchangeListener);
|
||||
|
||||
<font color="#3f7f5f">// Create a RosterExchangeManager that will help user1 to send his roster</font>
|
||||
RosterExchangeManager rosterExchangeManager1 = new RosterExchangeManager(conn1);
|
||||
<font color="#3f7f5f">// Send user1's roster to user2</font>
|
||||
rosterExchangeManager1.send(conn1.getRoster(), user2);
|
||||
</pre>
|
||||
</blockquote>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
57
CopyOftrunk/documentation/extensions/style.css
Normal file
57
CopyOftrunk/documentation/extensions/style.css
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
BODY {
|
||||
font-size : 100%;
|
||||
background-color : #fff;
|
||||
}
|
||||
BODY, TD, TH {
|
||||
font-family : tahoma, arial, helvetica;
|
||||
font-size : 0.8em;
|
||||
}
|
||||
PRE, TT, CODE {
|
||||
font-family : courier new, monospaced;
|
||||
font-size : 1.0em;
|
||||
}
|
||||
A:hover {
|
||||
text-decoration : none;
|
||||
}
|
||||
LI {
|
||||
padding-bottom : 4px;
|
||||
}
|
||||
.header {
|
||||
font-size : 1.4em;
|
||||
font-weight : bold;
|
||||
width : 100%;
|
||||
border-bottom : 1px #ccc solid;
|
||||
padding-bottom : 2px;
|
||||
}
|
||||
.subheader {
|
||||
font-size: 1.1em;
|
||||
font-weight : bold;
|
||||
}
|
||||
.footer {
|
||||
font-size : 0.8em;
|
||||
color : #999;
|
||||
text-align : center;
|
||||
width : 100%;
|
||||
border-top : 1px #ccc solid;
|
||||
padding-top : 2px;
|
||||
}
|
||||
.code {
|
||||
border : 1px #ccc solid;
|
||||
padding : 0em 1.0em 0em 1.0em;
|
||||
margin : 4px 0px 4px 0px;
|
||||
}
|
||||
.nav, .nav A {
|
||||
font-family : verdana;
|
||||
font-size : 0.85em;
|
||||
color : #600;
|
||||
text-decoration : none;
|
||||
font-weight : bold;
|
||||
}
|
||||
.nav {
|
||||
width : 100%;
|
||||
border-bottom : 1px #ccc solid;
|
||||
padding : 3px 3px 5px 1px;
|
||||
}
|
||||
.nav A:hover {
|
||||
text-decoration : underline;
|
||||
}
|
||||
22
CopyOftrunk/documentation/extensions/time.html
Normal file
22
CopyOftrunk/documentation/extensions/time.html
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Time</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="header">Entity Time Exchange</div><p>
|
||||
|
||||
Supports a protocol that XMPP clients use to exchange their respective local
|
||||
times and time zones.<p>
|
||||
|
||||
<b>JEP related:</b> <a href="http://www.jabber.org/jeps/jep-0090.html">JEP-90</a>
|
||||
|
||||
<hr>
|
||||
|
||||
<em>More coming soon.</em>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
26
CopyOftrunk/documentation/extensions/toc.html
Normal file
26
CopyOftrunk/documentation/extensions/toc.html
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Smack Extensions User Manual</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
<base target="mainFrame">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<a href="intro.html">Introduction</a><p>
|
||||
|
||||
<div class="subheader">Smack Extensions</div><p>
|
||||
|
||||
<a href="privatedata.html">Private Data</a><br>
|
||||
<a href="xhtml.html">XHTML Messages</a><br>
|
||||
<a href="messageevents.html">Message Events</a><br>
|
||||
<a href="dataforms.html">Data Forms</a><br>
|
||||
<a href="muc.html">Multi User Chat</a><br>
|
||||
<a href="rosterexchange.html">Roster Item Exchange</a><br>
|
||||
<a href="time.html">Time Exchange</a><br>
|
||||
<a href="invitation.html">Group Chat Invitations</a><br>
|
||||
<a href="disco.html">Service Discovery</a><br>
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
200
CopyOftrunk/documentation/extensions/xhtml.html
Normal file
200
CopyOftrunk/documentation/extensions/xhtml.html
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>XHTML Support</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="header">XHTML Messages</div><p>
|
||||
|
||||
Provides the ability to send and receive formatted messages using XHTML.
|
||||
|
||||
<p>Follow these links to learn how to compose, send, receive and discover support for
|
||||
XHTML messages:</p>
|
||||
<ul>
|
||||
<li><a href="#xhtmlcompose">Compose an XHTML Message</a></li>
|
||||
<li><a href="#xhtmlsend">Send an XHTML Message</a></li>
|
||||
<li><a href="#xhtmlreceive">Receive an XHTML Message</a></li>
|
||||
<li><a href="#xhtmldiscover">Discover support for XHTML Messages</a></li>
|
||||
</ul>
|
||||
<b>JEP related:</b> <a href="http://www.jabber.org/jeps/jep-0071.html">JEP-71</a>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="xhtmlcompose">Compose an XHTML Message</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
The first step in order to send an XHTML message is to compose it. Smack provides a special
|
||||
class that helps to build valid XHTML messages hiding any low level complexity.
|
||||
For special situations, advanced users may decide not to use the helper class and generate
|
||||
the XHTML by themselves. Even for these situations Smack provides a well defined entry point
|
||||
in order to add the generated XHTML content to a given message.</p>
|
||||
|
||||
<p>
|
||||
Note: not all clients are able to view XHTML formatted messages. Therefore,
|
||||
it's recommended that you include a normal body in that message that is either an
|
||||
unformatted version of the text or a note that XHTML support is required
|
||||
to view the message contents.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
Create an instance of <i><b>XHTMLText</b></i> specifying the style and language of the body.
|
||||
You can add several XHTML bodies to the message but each body should be for a different language.
|
||||
Once you have an XHTMLText you can start to append tags and text to it. In order to append tags there
|
||||
are several messages that you can use. For each XHTML defined tag there is a message that you can send.
|
||||
In order to add text you can send the message <b>#append(String textToAppend)</b>.</p>
|
||||
|
||||
<p>After you have configured the XHTML text, the last step you have to do is to add the XHTML text
|
||||
to the message you want to send. If you decided to create the XHTML text by yourself, you will have to
|
||||
follow this last step too. In order to add the XHTML text to the message send the message
|
||||
<b>#addBody(Message message, String body)</b> to the <i><b>XHTMLManager</b></i> class where <i>message</i>
|
||||
is the message that will receive the XHTML body and <i>body</i> is the string to add as an XHTML body to
|
||||
the message.</b></p>
|
||||
|
||||
<b>Example</b><p>
|
||||
|
||||
In this example we can see how to compose the following XHTML message: <br>
|
||||
<font color="#0000FF"><body><p style='font-size:large'>Hey John, this is my new <span
|
||||
style='color:green'>green</span><em>!!!!</em></p></body></font>
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Create a message to send</font>
|
||||
Message msg = chat.createMessage();
|
||||
msg.setSubject(<font color="#0000FF">"Any subject you want"</font>);
|
||||
msg.setBody(<font color="#0000FF">"Hey John, this is my new green!!!!"</font>);
|
||||
|
||||
<font color="#3f7f5f">// Create an XHTMLText to send with the message</font>
|
||||
XHTMLText xhtmlText = new XHTMLText(null, null);
|
||||
xhtmlText.appendOpenParagraphTag(<font color="#0000FF">"font-size:large"</font>);
|
||||
xhtmlText.append(<font color="#0000FF">"Hey John, this is my new "</font>);
|
||||
xhtmlText.appendOpenSpanTag(<font color="#0000FF">"color:green"</font>);
|
||||
xhtmlText.append(<font color="#0000FF">"green"</font>);
|
||||
xhtmlText.appendCloseSpanTag();
|
||||
xhtmlText.appendOpenEmTag();
|
||||
xhtmlText.append(<font color="#0000FF">"!!!!"</font>);
|
||||
xhtmlText.appendCloseEmTag();
|
||||
xhtmlText.appendCloseParagraphTag();
|
||||
|
||||
<font color="#3f7f5f">// Add the XHTML text to the message</font>
|
||||
XHTMLManager.addBody(msg, xhtmlText.toString());
|
||||
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="xhtmlsend">Send an XHTML Message</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
After you have composed an XHTML message you will want to send it. Once you have added
|
||||
the XHTML content to the message you want to send you are almost done. The last step is to send
|
||||
the message as you do with any other message.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
An XHTML message is like any regular message, therefore to send the message you can follow
|
||||
the usual steps you do in order to send a message. For example, to send a message as part
|
||||
of a chat just use the message <b>#send(Message)</b> of <i><b>Chat</b></i> or you can use
|
||||
the message <b>#send(Packet)</b> of <i><b>XMPPConnection</b></i>.</p>
|
||||
|
||||
<b>Example</b><p>
|
||||
|
||||
In this example we can see how to send a message with XHTML content as part of a chat.
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Create a message to send</font>
|
||||
Message msg = chat.createMessage();
|
||||
<font color="#3f7f5f">// Obtain the XHTML text to send from somewhere</font>
|
||||
String xhtmlBody = getXHTMLTextToSend();
|
||||
|
||||
<font color="#3f7f5f">// Add the XHTML text to the message</font>
|
||||
XHTMLManager.addBody(msg, xhtmlBody);
|
||||
|
||||
<font color="#3f7f5f">// Send the message that contains the XHTML</font>
|
||||
chat.sendMessage(msg);
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="xhtmlreceive">Receive an XHTML Message</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
It is also possible to obtain the XHTML content from a received message. Remember
|
||||
that the specification defines that a message may contain several XHTML bodies
|
||||
where each body should be for a different language.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
To get the XHTML bodies of a given message just send the message <b>#getBodies(Message)</b>
|
||||
to the class <i><b>XHTMLManager</b></i>. The answer of this message will be an
|
||||
<i><b>Iterator</b></i> with the different XHTML bodies of the message or null if none.</p>
|
||||
|
||||
<b>Example</b><p>
|
||||
|
||||
In this example we can see how to create a PacketListener that obtains the XHTML bodies of any received message.
|
||||
<blockquote>
|
||||
<pre> <font color="#3f7f5f">// Create a listener for the chat and display any XHTML content</font>
|
||||
PacketListener packetListener = new PacketListener() {
|
||||
public void processPacket(Packet packet) {
|
||||
Message message = (Message) packet;
|
||||
<font color="#3f7f5f">// Obtain the XHTML bodies of the message</font>
|
||||
Iterator it = XHTMLManager.getBodies(message);
|
||||
if (it != null) {
|
||||
<font color="#3f7f5f">// Display the bodies on the console</font>
|
||||
while (it.hasNext()) {
|
||||
String body = (String) it.next();
|
||||
System.out.println(body);
|
||||
}
|
||||
}
|
||||
};
|
||||
chat.addMessageListener(packetListener);
|
||||
|
||||
</pre>
|
||||
</blockquote>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="subheader"><a name="xhtmldiscover">Discover support for XHTML Messages</a></div><p>
|
||||
|
||||
<b>Description</b><p>
|
||||
|
||||
Before you start to send XHTML messages to a user you should discover if the user supports XHTML messages.
|
||||
There are two ways to achieve the discovery, explicitly and implicitly. Explicit is when you first try
|
||||
to discover if the user supports XHTML before sending any XHTML message. Implicit is when you send
|
||||
XHTML messages without first discovering if the conversation partner's client supports XHTML and depenging on
|
||||
the answer (normal message or XHTML message) you find out if the user supports XHTML messages or not. This
|
||||
section explains how to explicitly discover for XHTML support.</p>
|
||||
|
||||
<b>Usage</b><p>
|
||||
|
||||
In order to discover if a remote user supports XHTML messages send <b>#isServiceEnabled(XMPPConnection
|
||||
connection, String userID)</b> to the class <i><b>XHTMLManager</b></i> where connection is the connection
|
||||
to use to perform the service discovery and userID is the user to check (A fully qualified xmpp ID,
|
||||
e.g. jdoe@example.com). This message will return true if the specified user handles XHTML messages.</p>
|
||||
|
||||
<b>Example</b><p>
|
||||
|
||||
In this example we can see how to discover if a remote user supports XHTML Messages.
|
||||
<blockquote>
|
||||
<pre> Message msg = chat.createMessage();
|
||||
<font color="#3f7f5f">// Include a normal body in the message</font>
|
||||
msg.setBody(getTextToSend());
|
||||
<font color="#3f7f5f">// Check if the other user supports XHTML messages</font>
|
||||
if (XHTMLManager.isServiceEnabled(connection, chat.getParticipant())) {
|
||||
<font color="#3f7f5f">// Obtain the XHTML text to send from somewhere</font>
|
||||
String xhtmlBody = getXHTMLTextToSend();
|
||||
|
||||
<font color="#3f7f5f">// Include an XHTML body in the message</font>
|
||||
XHTMLManager.addBody(msg, xhtmlBody);
|
||||
}
|
||||
|
||||
<font color="#3f7f5f">// Send the message</font>
|
||||
chat.sendMessage(msg);
|
||||
</pre>
|
||||
</blockquote>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue