1 11 12 package org.jivesoftware.messenger.handler; 13 14 import org.jivesoftware.messenger.disco.ServerFeaturesProvider; 15 import org.jivesoftware.messenger.*; 16 import org.jivesoftware.messenger.auth.UnauthorizedException; 17 import java.util.ArrayList ; 18 import java.util.Iterator ; 19 import org.dom4j.Element; 20 import org.xmpp.packet.IQ; 21 22 48 public class IQPrivateHandler extends IQHandler implements ServerFeaturesProvider { 49 50 private IQHandlerInfo info; 51 private PrivateStorage privateStorage = null; 52 53 public IQPrivateHandler() { 54 super("XMPP Private Storage Handler"); 55 info = new IQHandlerInfo("query", "jabber:iq:private"); 56 } 57 58 public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException { 59 IQ replyPacket = null; 60 Element child = packet.getChildElement(); 61 Element dataElement = (Element) child.elementIterator().next(); 62 63 if (dataElement != null) { 64 if (IQ.Type.get.equals(packet.getType())) { 65 replyPacket = IQ.createResultIQ(packet); 66 Element dataStored = privateStorage.get(packet.getFrom().getNode(), dataElement); 67 dataStored.setParent(null); 68 69 child.remove(dataElement); 70 child.setParent(null); 71 replyPacket.setChildElement(child); 72 child.add(dataStored); 73 } 74 else { 75 privateStorage.add(packet.getFrom().getNode(), dataElement); 76 replyPacket = IQ.createResultIQ(packet); 77 } 78 } 79 else { 80 replyPacket = IQ.createResultIQ(packet); 81 replyPacket.setChildElement("query", "jabber:iq:private"); 82 } 83 return replyPacket; 84 } 85 86 public void initialize(XMPPServer server) { 87 super.initialize(server); 88 privateStorage = server.getPrivateStorage(); 89 } 90 91 public IQHandlerInfo getInfo() { 92 return info; 93 } 94 95 public Iterator getFeatures() { 96 ArrayList features = new ArrayList (); 97 features.add("jabber:iq:private"); 98 return features.iterator(); 99 } 100 } 101 | Popular Tags |