Commit 9fca2bcd authored by Matt Tucker's avatar Matt Tucker Committed by matt

Added ability to get presence information as plain text (thanks Greg).

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4605 b35dd754-fafc-0310-a699-88a17e54d16e
parent 6cc412ed
...@@ -44,6 +44,11 @@ ...@@ -44,6 +44,11 @@
Presence Plugin Changelog Presence Plugin Changelog
</h1> </h1>
<p><b>1.3.1</b> -- July 19, 2006</p>
<ul>
<li>Added support for retrieving the user's presence status as plain text.
</ul>
<p><b>1.3.0</b> -- July 10, 2006</p> <p><b>1.3.0</b> -- July 10, 2006</p>
<ul> <ul>
<li>Added support for probing presence of components. <li>Added support for probing presence of components.
......
...@@ -101,9 +101,10 @@ The following parameters can be passed into the request:<p> ...@@ -101,9 +101,10 @@ The following parameters can be passed into the request:<p>
</tr> </tr>
<tr> <tr>
<td class="name">type</td><td>Optional</td><td>The type of response to return. Valid values <td class="name">type</td><td>Optional</td><td>The type of response to return. Valid values
are <b>image</b> or <b>xml</b>. If this parameter is not specified, the are <b>image</b>, <b>text</b> or <b>xml</b>. If this parameter is not specified, the
default value is <b>image</b>, which will display an image representing the default value is <b>image</b>, which will display an image representing the
user's presence. If <b>xml</b> is specified, an XML representation of the user's presence. If <b>xml</b> is specified, an XML representation of the
user's presence will be returned. If <b>text</b> is specified, the status text of the
user's presence will be returned.</td> user's presence will be returned.</td>
</tr> </tr>
<tr> <tr>
......
...@@ -45,6 +45,7 @@ public class PresenceStatusServlet extends HttpServlet { ...@@ -45,6 +45,7 @@ public class PresenceStatusServlet extends HttpServlet {
private PresencePlugin plugin; private PresencePlugin plugin;
private XMLPresenceProvider xmlProvider; private XMLPresenceProvider xmlProvider;
private ImagePresenceProvider imageProvider; private ImagePresenceProvider imageProvider;
private TextPresenceProvider textProvider;
byte available[]; byte available[];
byte away[]; byte away[];
...@@ -59,6 +60,7 @@ public class PresenceStatusServlet extends HttpServlet { ...@@ -59,6 +60,7 @@ public class PresenceStatusServlet extends HttpServlet {
(PresencePlugin) XMPPServer.getInstance().getPluginManager().getPlugin("presence"); (PresencePlugin) XMPPServer.getInstance().getPluginManager().getPlugin("presence");
xmlProvider = new XMLPresenceProvider(); xmlProvider = new XMLPresenceProvider();
imageProvider = new ImagePresenceProvider(this); imageProvider = new ImagePresenceProvider(this);
textProvider = new TextPresenceProvider();
available = loadResource("/images/user-green-16x16.gif"); available = loadResource("/images/user-green-16x16.gif");
away = loadResource("/images/user-yellow-16x16.gif"); away = loadResource("/images/user-yellow-16x16.gif");
chat = loadResource("/images/user-green-16x16.gif"); chat = loadResource("/images/user-green-16x16.gif");
...@@ -84,6 +86,9 @@ public class PresenceStatusServlet extends HttpServlet { ...@@ -84,6 +86,9 @@ public class PresenceStatusServlet extends HttpServlet {
else if ("xml".equals(type)) { else if ("xml".equals(type)) {
xmlProvider.sendInfo(request, response, presence); xmlProvider.sendInfo(request, response, presence);
} }
else if ("text".equals(type)) {
textProvider.sendInfo(request, response, presence);
}
else { else {
Log.warn("The presence servlet received an invalid request of type: " + type); Log.warn("The presence servlet received an invalid request of type: " + type);
// TODO Do something // TODO Do something
...@@ -96,6 +101,9 @@ public class PresenceStatusServlet extends HttpServlet { ...@@ -96,6 +101,9 @@ public class PresenceStatusServlet extends HttpServlet {
else if ("xml".equals(type)) { else if ("xml".equals(type)) {
xmlProvider.sendUserNotFound(request, response); xmlProvider.sendUserNotFound(request, response);
} }
else if ("text".equals(type)) {
textProvider.sendUserNotFound(request, response);
}
else { else {
Log.warn("The presence servlet received an invalid request of type: " + type); Log.warn("The presence servlet received an invalid request of type: " + type);
// TODO Do something // TODO Do something
...@@ -108,6 +116,9 @@ public class PresenceStatusServlet extends HttpServlet { ...@@ -108,6 +116,9 @@ public class PresenceStatusServlet extends HttpServlet {
else if ("xml".equals(type)) { else if ("xml".equals(type)) {
xmlProvider.sendUserNotFound(request, response); xmlProvider.sendUserNotFound(request, response);
} }
else if ("text".equals(type)) {
textProvider.sendUserNotFound(request, response);
}
else { else {
Log.warn("The presence servlet received an invalid request of type: " + type); Log.warn("The presence servlet received an invalid request of type: " + type);
// TODO Do something // TODO Do something
......
/**
* $Revision$
* $Date$
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.wildfire.plugin.presence;
import org.xmpp.packet.Presence;
import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
* The TextPresenceProvider provides the user's presence status in plain-text format.
* The returned text is the last known presence status of the user. If the user is offline
* then the unavailable presence will be recreated with the last known presence status.
*
* @author Greg Unrein
*/
class TextPresenceProvider extends PresenceInfoProvider {
public void sendInfo(HttpServletRequest request, HttpServletResponse response,
Presence presence) throws IOException {
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
if (presence == null) {
// Recreate the unavailable presence with the last known status
JID targetJID = new JID(request.getParameter("jid"));
presence = new Presence(Presence.Type.unavailable);
XMPPServer server = XMPPServer.getInstance();
try {
User user = server.getUserManager().getUser(targetJID.getNode());
String status = server.getPresenceManager().getLastPresenceStatus(user);
if (status != null) {
presence.setStatus(status);
}
}
catch (UserNotFoundException e) {}
presence.setFrom(targetJID);
}
out.println(presence.getStatus());
out.flush();
}
public void sendUserNotFound(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
// Send a forbidden presence
Presence presence = new Presence();
presence.setError(PacketError.Condition.forbidden);
try {
presence.setFrom(new JID(request.getParameter("jid")));
}
catch (Exception e) {}
try {
presence.setTo(new JID(request.getParameter("req_jid")));
}
catch (Exception e) {}
out.println(presence.getStatus());
out.flush();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment