Openfire插件开发者指南

Openfire Plugin Developer Guide

http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/plugin-dev-guide.html

 

1.插件结构(打包好的可发布的插件)

插件在openfireHome目录的plugins目录中,插件被以JAR或WAR文件部署时,它会被自动提取到目录。插件目录中的文件如下:

 

myplugin/

 |- plugin.xml      <- Plugin definition file

 |- readme.html     <- Optional readme file for plugin, which will be displayed to end users

 |- changelog.html  <- Optional changelog file for plugin, which will be displayed to end users

 |- logo_small.gif  <- Optional small (16x16) icon associated with the plugin (can also be a .png file)

 |- logo_large.gif  <- Optional large (32x32) icon associated with the plugin (can also be a .png file)

 |- classes/        <- Resources your plugin needs (i.e., a properties file)

 |- database/       <- Optional database schema files that your plugin needs

 |- i18n/           <- Optional i18n files to allow for internationalization of plugins.

 |- lib/            <- Libraries (JAR files) your plugin needs

 |- web             <- Resources for Admin Console integration, if any

     |- WEB-INF/

         |- web.xml           <- Generated web.xml containing compiled JSP entries

         |- web-custom.xml    <- Optional user-defined web.xml for custom servlets

     |- images/

 

 

 web 目录的存在,用于需要添加内容到Openfire管理控制台的插件。进一步的信息在后面。

 

plugin.xml文件指定Plugin的主类。样例文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<plugin>
    <!-- Main plugin class -->
    <class>org.example.ExamplePlugin</class>
 
    <!-- Plugin meta-data -->
    <name>Example Plugin</name>
    <description>This is an example plugin.</description>
    <author>Jive Software</author>
 
    <version>1.0</version>
    <date>07/01/2006</date>
    <url>http://www.igniterealtime.org/projects/openfire/plugins.jsp</url>
    <minServerVersion>3.0.0</minServerVersion>
    <licenseType>gpl</licenseType>
 
    <!-- Admin console entries -->
    <adminconsole>
        <!-- More on this below -->
    </adminconsole>
</plugin>

 

 

 在plugin.xml文件中可以被设置的元数据域:

  • name -- the name of the plugin.
  • description -- the description of the plugin.
  • author -- the author of the plugin.
  • version -- the version of the plugin.
  • date -- the date the plugin was released. The date must be in the form MM/dd/yyyy, such as 07/01/2006.
  • url -- a URL where additional information about the plugin is available.
  • minServerVersion -- the minimum version of Openfire required to run the plugin.如果服务器的版本比要求的版本低,插件不会被启动。
  • databaseKey -- if the plugin requires it's own database tables, the databaseKey element should be set with a schema key name (often the same name as the plugin).支持各种数据库的数据库模式文件应该放置在database目录中。例如,给定key ”foo”,模式文件将被命名为”foo_mysql.sql”, “foo_oracle.sql”,等。我们推荐表的前缀为”of”(openfire)以避免与数据库中其他的应用程序冲突。这个脚本应该使用key给出到ofVersion表的入口,以便模式版本信息可用被追踪,如:
    INSERT INTO ofVersion (name, version) VALUES ('foo', 0);
  • databaseVersion -- the database schema version (if a database schema is defined). 插件的数据库模式版本应该以0开始。如果未来版本的插件需要更新模式,可以通过按版本号在database/upgrade目录中创建子目录来定义这些更新。例如,目录database/upgrade/1database/upgrade/2应该包含如"foo_mysql.sql" and "foo_oracle.sql" 的脚本,包含每个版本相关数据库的修改。每个脚本应该在ofVerion表中更新版本信息,如:
    UPDATE ofVersion set version=1 where name='foo';
  • parentPlugin -- the name of the parent plugin (given as "foo" for the "foo.jar" plugin).当一个插件有父插件,将使用父插件的class loader而不是创建新的class loader.这使得插件可以更紧密的在一起工作。如果父插件不存在,孩子插件将不工作。
  • licenseType -- indicates the license agreement that the plugin is governed by. Valid values are:
    • "commercial": the plugin is released under a commercial license agreement.
    • "gpl": the plugin is released under the GNU Public License (GPL).
    • "apache": the plugin is released under the Apache license.
    • "internal": the plugin is for internal use at an organization only and will not be re-distributed.
    • "other": the plugin is released under a license agrement that doesn't fall into one of the other categories. The license agreement should be details in the plugin's Readme.

 

If the license type isnot set, it is assumed to be other.

 

Several additional files can be present inthe plugin to provide additional information to end-users (all placed in themain plugin directory):

  • readme.html -- Optional readme file for plugin, which will be displayed to end users.
  • changelog.html -- Optional changelog file for plugin, which will be displayed to end users.
  • logo_small.png -- Optional small (16x16) icon associated with the plugin. It can also be a .gif file.
  • logo_large.png -- Optional large (32x32) icon associated with the plugin. It can also be a .gif file.

 

你的插件类必须从Openfire API实现Plugin接口,并且有一个默认(无参数)构造函数。Plugin接口有初始化和销毁插件的方法:

  

package org.example;
 
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
 
import java.io.File;
 
/**
 * A sample plugin for Openfire.
 */
public class ExamplePlugin implements Plugin {
 
    public void initializePlugin(PluginManager manager, File pluginDirectory) {
        // Your code goes here
 
    }
 
    public void destroyPlugin() {
        // Your code goes here
    }
}

 

 

 一般的插件最佳实践

当为你的插件选择一个包名时,推荐选择对于你或你的组织机构来说有特色的名称,以帮助尽量避免冲突。例如,如果每个人都使用org.exmapl.PluginName, 即便PluginName不同,你也可能在这里或那里遇到类名冲突,尤其在集群工作时。

 

2.修改管理控制台(界面)


3.使用Openfire构建脚本(源码自带的脚本)

 

4.实现自己的插件

插件可以完全访问Openfire API,这给插件能完成的工作提供了巨大的灵活性。不过,有几个整合的点是最通用的:

1.      注册插件为一个Component. 组件接收所有发送到特定子域(sub-domain)的消息包,例如,test_component.example.com. 因此,发送到joe@test_component.example.com的消息包将被分发到这个组件。注意,定义为组件的子域跟DNS的子域入口没有关系。所有XMPP在socket层次的路由转发是使用主服务域(上面的例子是example.com)来完成;子域只是用于在XMPP服务器内部的路由。

2.      注册插件为一个IQHandler. IQ处理器使用特定的元素和名字空间来响应IQ消息包。下面的代码片段演示了如何注册一个IQHandler.

IQHandler myHandler = new MyIQHander();
IQRouter iqRouter = XMPPServer.getInstance().getIQRouter();
iqRouter.addHandler(myHandler);

 

 

 3.      注册插件为一个PacketInterceptor来接收所有通过系统发送的消息包,并选择性的进行过滤。例如,一个拦截器可以拒绝所有包含脏话的消息,或标记它们以供管理员审查。

4.      你可用存储永久的插件设置为Openfire属性,使用 JiveGlobals.getProperty(String)和JiveGlobals.setProperty(String, String) 方法。使你的插件成为一个数据监听器,以监听它的属性改变,可以通过实现org.jivesoftware.util.PropertyEventListener方法来完成。你可用使用PropertyEventDispatcher.addListener(PropertyEventListener)方法来注册你的插件为一个监听器。确保在插件的destroyPlugin()方法中注销你的插件监听器。

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值