1 11 12 package org.jivesoftware.messenger.plugin.presence; 13 14 import org.jivesoftware.messenger.XMPPServer; 15 import org.jivesoftware.messenger.user.User; 16 import org.jivesoftware.messenger.user.UserNotFoundException; 17 import org.xmpp.packet.JID; 18 import org.xmpp.packet.PacketError; 19 import org.xmpp.packet.Presence; 20 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 import java.io.IOException ; 24 import java.io.PrintWriter ; 25 26 33 class XMLPresenceProvider extends PresenceInfoProvider { 34 35 public void sendInfo(HttpServletRequest request, HttpServletResponse response, 36 Presence presence) throws IOException { 37 response.setContentType("text/xml"); 38 PrintWriter out = response.getWriter(); 39 if (presence == null) { 40 JID targetJID = new JID(request.getParameter("jid")); 42 presence = new Presence(Presence.Type.unavailable); 43 XMPPServer server = XMPPServer.getInstance(); 44 try { 45 User user = server.getUserManager().getUser(targetJID.getNode()); 46 String status = server.getPresenceManager().getLastPresenceStatus(user); 47 if (status != null) { 48 presence.setStatus(status); 49 } 50 } 51 catch (UserNotFoundException e) {} 52 presence.setFrom(targetJID); 53 } 54 out.println(presence.toXML()); 55 out.flush(); 56 } 57 58 public void sendUserNotFound(HttpServletRequest request, HttpServletResponse response) 59 throws IOException { 60 response.setContentType("text/xml"); 61 PrintWriter out = response.getWriter(); 62 Presence presence = new Presence(); 64 presence.setError(PacketError.Condition.forbidden); 65 try { 66 presence.setFrom(new JID(request.getParameter("jid"))); 67 } 68 catch (Exception e) {} 69 try { 70 presence.setTo(new JID(request.getParameter("req_jid"))); 71 } 72 catch (Exception e) {} 73 out.println(presence.toXML()); 74 out.flush(); 75 } 76 } 77 | Popular Tags |