10 #include <json/reader.h>
11 #include <json/value.h>
24 for (
int iModule = 0; iModule <
m_vModules.size(); ++iModule) {
35 bool bOk = reader.parse(plugins, root,
false);
37 LOG(
DEBUG) << reader.getFormatedErrorMessages();
42 Json::Value::Members mbrs = modules.getMemberNames();
47 for (
int iMod = 0; iMod < mbrs.size(); ++iMod) {
48 LOG(
DEBUG) <<
"WsModulesLoader::load Loading module " << mbrs[iMod] <<
" debug mode = " << bDebug;
50 Json::Value::Members attributes = module.getMemberNames();
51 for (
int iAtt = 0; iAtt < attributes.size(); ++iAtt) {
52 if ( attributes[iAtt] ==
"soName" ) {
53 std::string soName = module.get(attributes[iAtt],
"").asString();
55 boost::replace_first(soName,
".so",
"d.so");
58 void* hndl = dlopen(soName.c_str(), RTLD_LAZY);
60 LOG(
ERROR) <<
"WsModulesLoader::load dlopen error soName = " << soName <<
" error = " << dlerror();
63 LOG(
DEBUG) <<
"WsModulesLoader::load Loading module " << soName;
73 for (
int iAtt2 = 0; iAtt2 < attributes.size(); ++iAtt2) {
74 if ( attributes[iAtt2] ==
"moduleName" ) {
75 std::string moduleName = module.get(attributes[iAtt2],
"").asString();
78 if ( attributes[iAtt2] ==
"fileName" ) {
79 std::string fileName = module.get(attributes[iAtt2],
"").asString();
82 if ( attributes[iAtt2] ==
"extension" || attributes[iAtt2] ==
"extensions" ) {
83 std::string extensions = module.get(attributes[iAtt2],
"").asString();
86 if ( attributes[iAtt2] ==
"prefix" ) {
87 std::string prefix = module.get(attributes[iAtt2],
"").asString();
90 if ( attributes[iAtt2] ==
"hideImages" ) {
91 std::string hideImages = module.get(attributes[iAtt2],
"false").asString();
94 if ( attributes[iAtt2] ==
"options" ) {
96 Json::Value::Members optAttrs = options.getMemberNames();
97 for (
int iOpt = 0; iOpt < optAttrs.size(); ++iOpt) {
99 LOG(
DEBUG) <<
"WsModuleLoader::load options " << optAttrs[iOpt] <<
" value = " << val.asString();
100 if ( val.type() == Json::nullValue )
continue;
101 if ( val.type() == Json::intValue )
102 pModule->
setOption(optAttrs[iOpt], val.asInt());
103 if ( val.type() == Json::uintValue )
104 pModule->
setOption(optAttrs[iOpt], val.asUInt());
105 if ( val.type() == Json::realValue )
106 pModule->
setOption(optAttrs[iOpt], val.asDouble());
107 if ( val.type() == Json::stringValue )
108 pModule->
setOption(optAttrs[iOpt], val.asString());
109 if ( val.type() == Json::booleanValue )
110 pModule->
setOption(optAttrs[iOpt], val.asBool());
114 if ( module[
"loadOnStartup"] != Json::Value::null && module[
"loadOnStartup"].asBool()) {
120 LOG(
DEBUG) <<
"WsModuleLoader::load running Module else clause " << module[
"loadOnStartup"].asString();
136 for (
int iModule = 0; iModule <
modules().size(); ++iModule) {
138 if ( curModule->
moduleName() != moduleName )
continue;
147 if ( remP ==
"" ) remP =
"/";
154 std::string sRes(path);
157 if ( path.compare(0, searchPath.size(), searchPath ) == 0 )
return "";
158 if ( path.compare(0, 5,
"/Logo" ) == 0 )
return sRes.assign(path, 5, path.size() - 5);
159 if ( path.compare(0, 8,
"/SiteMap" ) == 0 )
return sRes.assign(path, 8, path.size() - 8);
160 if ( path.compare(0, 5,
"/Edit" ) == 0 )
return sRes.assign(path, 5, path.size() - 5);
161 if ( path.compare(0, 11,
"/FileUpload" ) == 0 )
return sRes.assign(path, 11, path.size() - 11);
162 if ( path.compare(0, 10,
"/FolderNew" ) == 0 )
return sRes.assign(path, 10, path.size() - 10);
163 if ( path.compare(0, 13,
"/FolderDelete" ) == 0 )
return sRes.assign(path, 13, path.size() - 13);
164 if ( path.compare(0, 11,
"/FolderEdit" ) == 0 )
return sRes.assign(path, 11, path.size() - 11);
165 for (
int iModule = 0; iModule <
modules().size(); ++iModule) {
167 if ( curModule->
prefix().size() < 1 )
continue;
168 if ( path.compare(0, curModule->
prefix().size(), curModule->
prefix() ) == 0)
176 std::string sRes(path);
177 for (
int iModule = 0; iModule <
modules().size(); ++iModule) {
180 if ( sRes != path )
break;
std::string pathWithoutPrefix(const std::string &path)
const std::vector< WsModuleLoader * > & modules()
void setLoaded()
Some modules can be loaded on startup, no more actions is required by the content widget...
std::vector< WsModuleLoader * > m_vModules
std::string checkPath(const std::string &path)
std::string pathWithoutPrefix(const std::string &path)
return the relative path without the prefix : example pathWithoutPrefix("/SiteMap/Test") return "/Tes...
const std::string PluginsPropertiesPath
void setFileName(const std::string &fileName)
Set/Get the file name that trigger the module : exemple "Staff List".
void setHideImages(const bool bHide)
Set/Get the flag to specified if the images is hided.
virtual std::string checkPath(const std::string ¤tPath)
Return the currentPath, or another path when some action is required for the currentPath example /New...
virtual Wt::WWidget * createContents(Wt::WContainerWidget *parent=0) const =0
Create the contents.
std::string removePrefix(const std::string &path)
const std::string & moduleName() const
WsModule *(* pf_wsModule)()
Example of the main function extern "C" { WsModule* buildModule() { return new WsModule(); } }...
void setOption(const std::string &attribute, boost::any value)
Set an options if previously set, update the value.
void setPrefix(const std::string &prefix)
Set/Get prefix for a virtual path, like "/SiteMap".
void setModuleName(const std::string &name)
Set/Get the module name.
const std::string & prefix() const
std::string get(const std::string §ion, const std::string &id, const std::string &def)
void setSoName(const std::string &soName)
Set/Get the module so name or path ex. libgd.so or /usr/lib/libgd.so.
static WsLayoutProperties * instance()
Get the singleton instance.
const WsModule * module(const std::string &moduleName)
void setExtensions(const std::string &extensions)
Set/Get the file extension managed by the module : exemple .ods|.odp.