1 11 12 package org.jivesoftware.messenger.handler; 13 14 import org.jivesoftware.messenger.disco.ServerFeaturesProvider; 15 import org.jivesoftware.messenger.IQHandlerInfo; 16 import org.jivesoftware.messenger.PacketException; 17 import org.jivesoftware.admin.AdminConsole; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import org.dom4j.DocumentHelper; 22 import org.dom4j.Element; 23 import org.dom4j.QName; 24 import org.xmpp.packet.IQ; 25 26 33 public class IQVersionHandler extends IQHandler implements ServerFeaturesProvider { 34 35 private static Element bodyElement; 36 private IQHandlerInfo info; 37 38 public IQVersionHandler() { 39 super("XMPP Server Version Handler"); 40 info = new IQHandlerInfo("query", "jabber:iq:version"); 41 if (bodyElement == null) { 42 bodyElement = DocumentHelper.createElement(QName.get("query", "jabber:iq:version")); 43 bodyElement.addElement("name").setText(AdminConsole.getAppName()); 44 bodyElement.addElement("os").setText("Java 5"); 45 bodyElement.addElement("version"); 46 } 47 } 48 49 public IQ handleIQ(IQ packet) throws PacketException { 50 Element answerElement = bodyElement.createCopy(); 52 answerElement.element("name").setText(AdminConsole.getAppName()); 53 answerElement.element("version").setText(AdminConsole.getVersionString()); 54 IQ result = IQ.createResultIQ(packet); 55 result.setChildElement(answerElement); 56 return result; 57 } 58 59 public IQHandlerInfo getInfo() { 60 return info; 61 } 62 63 public Iterator getFeatures() { 64 ArrayList features = new ArrayList (); 65 features.add("jabber:iq:version"); 66 return features.iterator(); 67 } 68 } | Popular Tags |