原文地址:http://314858770.iteye.com/blog/908249
开发openfire插件开发流程:http://phoenixtoday.blogbus.com/logs/20285574.html
openfire插件开发指南:http://www.blogjava.net/jyleon/articles/254197.html
openfire插件开发4种方式:http://haidao.blog.51cto.com/59111/307620
openfire插件开发记录:http://blog.csdn.net/jxiaobing/article/details/667938
8
openfire源码构建指导(E文):http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/source-build.html
android openfire 插件开发:http://www.cnmsdn.com/html/201106/1308830174ID10035.html
Java代码package test.plugin; import org.dom4j.Element; import org.jivesoftware.openfire.IQHandlerInfo; import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.handler.IQHandler; import org.xmpp.packet.IQ; public class BroadcastsIQ extends IQHandler { private IQHandlerInfo info; public BroadcastsIQ() { super("用户广播模块"); info = new IQHandlerInfo("b", "com:message:broadcasts"); } @Override public IQHandlerInfo getInfo() { return info; } @Override public IQ handleIQ(IQ packet) throws UnauthorizedException { Element iq = packet.getElement(); Element b = iq.element("b"); String text = b.getText(); XMPPServer.getInstance().getSessionManager().sendServerMessage(null, text);//广播信息 return null; } }
package test.plugin; import java.io.File; import java.util.List; import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.container.Plugin; import org.jivesoftware.openfire.container.PluginManager; import org.jivesoftware.openfire.handler.IQHandler; public class MyPlugin implements Plugin { private IQHandler iQHandler; @Override public void destroyPlugin() { XMPPServer.getInstance().getIQRouter().removeHandler(iQHandler); System.out.println("插件停止成功"); } @Override public void initializePlugin(PluginManager manager, File pluginDirectory) { iQHandler = new BroadcastsIQ(); XMPPServer.getInstance().getIQRouter().addHandler(iQHandler); System.out.println("插件运行成功"); } }
<?xml version="1.0" encoding="UTF-8"?> <plugin> <class>test.plugin.MyPlugin</class> <name>Broadcasts messages</name> <description>This is an Broadcasts messages plugin.</description> <author>me</author> <version>1.0</version> <date>01/01/2011/date> <url>none</url> <minServerVersion>3.0.0</minServerVersion> <licenseType>gpl</licenseType> <adminconsole> </adminconsole> </plugin>
package test.xmpp; import org.jivesoftware.smack.packet.IQ; public class Broadcasts extends IQ { private String body; public String getElementName() { return "b"; } public String getNamespace() { return "com:message:broadcasts"; } public void setBody(String body) { this.body = body; } public String getBody() { return body; } @Override public String getChildElementXML() { if(getBody() == null){ throw new RuntimeException("Broadcasts body is empty"); } StringBuilder sb = new StringBuilder(); sb.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\">").append(getBody()).append("</").append(getElementName()).append(">"); return sb.toString(); } }
Broadcasts b = new Broadcasts(); b.setBody("测试广播内容"); b.setType(IQ.Type.SET); conn.sendPacket(b);