有很多类型的插件,让我们大致来讲一下。
Igniterealtime插件指南
您想定义一个全新的IQ Stanza来管理UserCustomParam。比方说:
<iq from="user1@myserver" to="myserver" type="get"> <usercustomparam xmls:"com.records.iq" retrive="favouritecolor"></iq>
您必须:
步骤1: 定义一个添加新处理程序的插件(实现插件的类)
MyCustomHandler colorshandler;IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();iqRouter.addHandler(colorshandler);
步骤2: 根据需要实现MyCustomHandler(在数据库上读取,在数据库上写入,读取服务器端等等)。
public class MyCustomHandler extends IQHandler { public static final String NAMESPACE_TICKET_IQ = "com.records.iq"; public static final String TAG_TICKET_IQ = "usercustomparam ";现在,您的服务器已准备就绪,可以管理您的自定义IQ请求。
是时候去客户端了:
第三步: 向您的ProviderManager注册一个IQProvider
ProviderManager.addIQProvider("usercustomparam ","com.records.iq", new IQUserCustomParamProvider());步骤4: 根据需要实现IQUserCustomParamProvider
public class IQUserCustomParamProvider extends IQProvider<IQUserCustomParam>
到Provider中,您将解析来自服务器的传入IQ,并创建一个IQUserCustomParam,其实例参数如下
String favouriteColor
步骤5: 您需要实现IQUserCustomParam
public class IQUserCustomParam extends IQ private final static String childElementName = "usercustomparam"; private final static String childElementNamespace = "com.records.iq";public IQUserCustomParam (String color) { this(childElementName , childElementNamespace ); this.setType(IQ.Type.result); this.setFavouriteColor(color); }步骤6 :现在完成设置,但是您还没有定义何时从服务器接收IQUserCustomParam。所以你需要一个StanzaFilter
public class IQUserCustomParamFilter implements StanzaFilter
步骤7 :您还没有定义IQUserCustomParam来自服务器时的处理方法。所以你需要一个StanzaListner
public class IQUserCustomParamListner implements StanzaListener
步骤8: 最后,您必须在连接上注册组合过滤器/侦听器:
AbstractXMPPConnection connection = ...;connection.addAsyncStanzaListener(new PersonalConfigListner(this), new IQMUCConfigTicketFIlter();
如果有帮助,请不要忘记接受答案!



