Import openfire source code
Plug-ins are developed in the src/Plugins directory.
Overall plug-in Structure
Plugin. xml defines plug-in attributes:
<? XML version = "1.0" encoding = "UTF-8"?>
<Plugin>
<! -- Main plugin class -->
<Class> com. Roger. openfire. plugin. treestructureplugin </class>
<Name> structure </Name>
<Description> Get Roger System Structure Tree </description>
<Author> bin. Xiao </author>
<Version> 1.0.5 </version>
<Date> 3/19/2013 </date>
<Minserverversion> 3.7.0 </minserverversion>
<! -- <Databaseversion> 0 </databaseversion> --> <! -- Check the database? -->
</Plugin>
Initialize pluhin:
Public class treestructureplugin implements plugin {
Private xmppserver server;
Private treestructureservice groupservice;
Private treestructurehandler = new treestructurehandler ();
@ Override
Public void initializeplugin (pluginmanager manager, file plugindirectory ){
Server = xmppserver. getinstance ();
Server. getiqrouter (). addhandler (treestructurehandler );
Groupservice = new treestructureserviceimpl ();
}
@ Override
Public void destroyplugin (){
Server. getiqrouter (). removehandler (treestructurehandler );
Server = NULL;
Groupservice = NULL;
}
}
// Process this plug-in event
Public class treestructurehandler extends iqhandler {
Private Static final logger = loggerfactory. getlogger (treestructurehandler. Class );
Private Static final string module_name = "get tree structure ";
Private Static final string name_space = "com: Roger: Structure ";
Private iqhandlerinfo Info;
Private treestructureservice service;
Public treestructurehandler (){
Super (module_name );
Info = new iqhandlerinfo ("structure", name_space );
Service = new COM. Roger. openfire. plugin. impl. treestructureserviceimpl ();
}
@ Override
Public IQ handleiq (IQ packet) throws unauthorizedexception {
IQ result = IQ. createresultiq (packet );
Element Param = packet. getchildelement ();
// String scope = Param. elementtext ("Scope ");
// If (scope = NULL ){
//// Does not contain the scope Node
// Result. setchildelement (Param. createcopy ());
// Result. seterror (packeterror. condition. bad_request );
// Return result;
//}
String from = packet. getfrom (). tostring ();
System. Out. println (from );
List <structure> gpst = service. getuserpowergroup (from );
// List <structure> gpst = service. getgrouprootformatxml ();
Map <string, list <treeuser> usermap = service. getallcompanytreeuser ();
Buildresult (Param, gpst, usermap );
Result. setchildelement (Param. createcopy ());
Logger.info (result. toxml ());
Return result;
}
Element root = NULL;
Private element buildresult (element Param, list <structure> gpst, Map <string, list <treeuser> usermap ){
For (Structure Group: gpst ){
Root =
Param. addelement ("structurenode ")
. Addattrid ("ID", group. GETID (). tostring ())
. Addattribute ("name", group. getname ())
. Addattrid ("parent", group. getparentid (). tostring ())
. Addattribute ("type", "group ");
List <treeuser> treeuser = usermap. Get (group. GETID (). tostring ());
// Load the user
If (treeuser! = NULL ){
For (treeuser User: treeuser ){
Root. addelement ("usernode ")
. Addattriname ("jid", user. getloginname ())
. Addattribute ("name", user. GetUserName ())
. Addattribute ("companyid", user. getcompanyid () + "")
. Addattribute ("email", user. getemail ())
. Addattrisex ("sex", user. getsex ())
. Addattribute ("tel", user. gettel ())
. Addattribute ("type", "user ")
. Addattribute ("company", group. getname ());
}
}
If (group. getgrouproot (). isempty () & group. getgrouproot (). Size () = 0 ){
Continue;
} Else {
Buildresult (root, group. getgrouproot (), usermap );
}
}
Return root;
}
@ Override
Public iqhandlerinfo getinfo (){
Return Info;
}
}