1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

Adding extensions documentation that was written by Gato.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2037 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2003-08-19 13:20:42 +00:00 committed by mtucker
parent c817d02351
commit cb97e13b90
7 changed files with 449 additions and 0 deletions

View file

@ -0,0 +1,15 @@
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Smack Extensions User Manual</title>
</head>
<frameset cols="26%,74%">
<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>

View file

@ -0,0 +1,16 @@
<html>
<head>
<title>Smack Extensions User Manual</title>
</head>
<body>
<h1>Smack Extensions Manual</h1>
<p>The XMPP protocol includes a base protocol and many optional extensions. 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.
</body>
</html>

View file

@ -0,0 +1,224 @@
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Message Events</title>
</head>
<body>
<h1>Message Events Support</h1>
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: 1) Request for
event notifications, 2) Receive the event notification requests and send event notifications, and
3) Receive the event notifications.
<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>
<h2><a name="reqevnot">Requesting Event Notifications</a></h2>
<h3>Description</h3>
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.
<h3>Usage</h3>
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>
<h3>Example</h3>
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>
<h2><a name="lstevnotreq">Reacting to Event Notification Requests</a></h2>
<h3>Description</h3>
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.
<h3>Usage</h3>
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>
<h3>Example</h3>
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>
<h2><a name="lstevnot">Reacting to Event Notifications</a></h2>
<h3>Description</h3>
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.
<h3>Usage</h3>
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>
<h3>Example</h3>
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>

View file

@ -0,0 +1,15 @@
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Private Data</title>
</head>
<body>
<h1>Private Data Support</h1>
Comming soon
</body>
</html>

View file

@ -0,0 +1,144 @@
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Roster Item Exchange</title>
</head>
<body>
<h1>Roster Item Exchange Support</h1>
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>
<h2><a name="riesendroster">Send a complete roster</a></h2>
<h3>Description</h3>
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.
<h3>Usage</h3>
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.
<h3>Example</h3>
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>
<h2><a name="riesendgroup">Send a roster's group</a></h2>
<h3>Description</h3>
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.
<h3>Usage</h3>
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.
<h3>Example</h3>
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>
<h2><a name="riesendentry">Send a roster's entry</a></h2>
<h3>Description</h3>
Sometimes you may need to send a single roster entry to another XMPP client. Smack also lets you send
items at this granularity level.
<h3>Usage</h3>
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.
<h3>Example</h3>
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><h2><a name="riercventry">Receive roster entries</a></h2>
<h3>Description</h3>
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.
<h3>Usage</h3>
<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>
<h3>Example</h3>
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 rosterEntries) {
for (Iterator it = rosterEntries; it.hasNext();) {
try {
<font color="#3f7f5f">// Get the received entry</font>
RosterEntry entry = (RosterEntry) it.next();
<font color="#3f7f5f">// Display the entry on the console</font>
System.out.println(entry);
<font color="#3f7f5f">// Add the entry to the user2's roster</font>
user2_roster.createEntry(entry);
}
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>

View file

@ -0,0 +1,15 @@
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Time</title>
</head>
<body>
<h1>Time Exchange Support</h1>
Comming soon
</body>
</html>

View file

@ -0,0 +1,20 @@
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Smack Extensions User Manual</title>
<base target="mainFrame">
</head>
<body>
<a href="intro.html">Introduction</a>
<h3>Smack extensions</h3>
<a href="privatedata.html">Private Data</a><br>
<a href="messageevents.html">Message Events</a><br>
<a href="rosterexchange.html">Roster Item Exchange</a><br>
<a href="time.html">Time Exchange</a><br>
</p>
</body>
</html>