Openfire plug-in Development 1

Source: Internet
Author: User

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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.