00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "mmsconfig/mmspluginparameterparser.h"
00034 #include "mmstools/tools.h"
00035
00036 #include <libxml/parser.h>
00037
00038 MMSPluginParameterParser::MMSPluginParameterParser() {
00039 }
00040
00041 MMSPluginParameterParser::~MMSPluginParameterParser() {
00042
00043 }
00044
00045 bool MMSPluginParameterParser::validate(MMSPluginData *plugin) {
00046 string parameterfile;
00047
00048 #ifdef __NOT_USED__
00049 xmlpp::Document *doc;
00050
00051 if(plugin== NULL)
00052 return false;
00053
00054 logger.writeLog("validate property");
00055
00056
00057 if(plugin->getProperties().empty()) {
00058 return true;
00059 }
00060
00061 parameterfile = plugin->getPath() + "/parameter.xml";
00062 logger.writeLog("parse file: " +plugin->getPath() + "/parameter.xml");
00063 try {
00064 parser->parse_file(parameterfile);
00065 if(parser) {
00066 doc = parser->get_document();
00067 xmlpp::Node *root = doc->get_root_node();
00068
00069 vector<MMSPropertyData *> properties = plugin->getProperties();
00070 for(vector<MMSPropertyData *>::iterator it= properties.begin();it!=properties.end();it++) {
00071 Glib::ustring query;
00072 query.append("/plugin/parameter[@name=\"");
00073 query.append((*it)->getParameter());
00074 query.append("\"]");
00075 xmlpp::NodeSet set = root->find(query);
00076 if(set.empty())
00077 throw MMSPluginParameterParserError(0,"Plugin " + plugin->getName() + " has no parameter named " + (*it)->getParameter());
00078
00079 }
00080 delete doc;
00081 return true;
00082
00083
00084 }
00085 }
00086 catch(const std::exception& ex) {
00087
00088 return false;
00089 }
00090 #endif
00091 return false;
00092 }
00093
00094 void MMSPluginParameterParser::createProperty(MMSPluginData *plugin,string name) {
00095 string parameterfile;
00096 xmlDoc *parser = NULL;
00097
00098 if(plugin== NULL)
00099 return;
00100
00101 DEBUGMSG("PLUGINPARAMETERPARSER", "CreateProperty");
00102
00103 if(plugin->getProperty(name)!=NULL) {
00104 return;
00105 }
00106
00107 LIBXML_TEST_VERSION
00108
00109 parameterfile = plugin->getPath() + "/parameter.xml";
00110 try {
00111 parser = xmlReadFile((char *)parameterfile.c_str(), NULL, 0);
00112
00113 if(parser == NULL) {
00114 throw MMSPluginParameterParserError(1,"Could not parse file:" + parameterfile);
00115 }
00116 else {
00117 xmlNode* pNode = xmlDocGetRootElement(parser);
00118
00119 string query;
00120 query.append("//plugin/parameter[@name=\"");
00121 query.append(name);
00122 query.append("\"]");
00123
00124 if(xmlStrcmp(pNode->name, (const xmlChar *) query.c_str())) {
00125 DEBUGMSG("PLUGINPARAMETERPARSER", "invalid configuration file (%s) - does not contain correct root node", parameterfile.c_str());
00126 throw MMSPluginParameterParserError(0,"Plugin " + plugin->getName() + " has no parameter named " + name);
00127 }
00128
00129
00130 MMSPropertyData *data = new MMSPropertyData();
00131 data->setParameter(name);
00132
00133 xmlChar *type;
00134 type = xmlGetProp(pNode, (const xmlChar*) "type");
00135
00136 if(type!=NULL) {
00137 if((string((char*)type) == MMSPROPERTYTYPE_STRING) || (string((char*)type) == MMSPROPERTYTYPE_INTEGER))
00138 data->setType((char *)type);
00139 else {
00140
00141 xmlFreeDoc(parser);
00142 throw MMSPluginParameterParserError(0,"the data type \"" + string((char*)type) + "\" defined in the parameter.xml of " + plugin->getName() + " is unknown.");
00143 }
00144 }
00145 xmlFree(type);
00146
00147 xmlChar *min;
00148 min = xmlGetProp(pNode, (const xmlChar*)"min");
00149 if(min!=NULL) {
00150 data->setMin(atoi((char*)min));
00151 }
00152 xmlFree(min);
00153
00154 xmlChar *max;
00155 max = xmlGetProp(pNode, (const xmlChar*)"max");
00156 if(max!=NULL) {
00157 data->setMax(atoi((char*)max));
00158 }
00159 xmlFree(max);
00160
00161
00162 xmlFreeDoc(parser);
00163
00164 data->setisSetinDb(false);
00165 vector<MMSPropertyData *> result = plugin->getProperties();
00166 result.push_back(data);
00167 plugin->setProperties(result);
00168
00169 return;
00170
00171
00172 }
00173 }
00174 catch(const std::exception& ex) {
00175 return;
00176 }
00177 }
00178
00179
00180
00181 void MMSPluginParameterParser::fillProperties(MMSPluginData *plugin) {
00182 string parameterfile;
00183 #ifdef __NOT_USED__
00184 xmlDoc *parser = NULL;
00185
00186 logger.writeLog("Fillproperies");
00187
00188 if(plugin== NULL)
00189 throw MMSPluginParameterParserError(0,"no plugin given");
00190
00191 LIBXML_TEST_VERSION
00192
00193 parameterfile = plugin->getPath() + "/parameter.xml";
00194 logger.writeLog("parse file: " +parameterfile );
00195
00196 try {
00197 parser = xmlReadFile((char *)parameterfile.c_str(), NULL, 0);
00198
00199 if(parser == NULL) {
00200 throw MMSPluginParameterParserError(1,"Could not parse file:" + parameterfile);
00201 }
00202 else {
00203 xmlNode* pNode = xmlDocGetRootElement(parser);
00204
00205 string query;
00206 query.append("/plugin/parameter");
00207
00208 if(xmlStrcmp(pNode->name, (const xmlChar *) query.c_str())) {
00209 logger.writeLog("invalid configuration file (" + parameterfile + ") - does not contain correct root node");
00210 throw MMSPluginParameterParserError(0,"Plugin " + plugin->getName() + " has no parameter named " + string((char *)pNode->name));
00211 }
00212
00213 if(myset.empty())
00214 throw MMSPluginParameterParserError(MMSPLUGINPARAMETERPARSER_ERROR_NOPARAMETERS,"Plugin has no parameters");
00215 else
00216 logger.writeLog("got " + iToStr(myset.size()) + " parameters");
00217
00218 vector<MMSPropertyData *> properties = plugin->getProperties();
00219
00220 for(unsigned int i= 0;i<myset.size();i++) {
00221 logger.writeLog("vor get_name()");
00222
00223 logger.writeLog("nach get_name()");
00224
00225 xmlpp::Attribute *attr = ((xmlpp::Element*)myset.at(i))->get_attribute("name");
00226 logger.writeLog(attr->get_name());
00227 logger.writeLog(attr->get_value());
00228
00229
00230 bool found = false;
00231 for(vector<MMSPropertyData *>::iterator props=properties.begin();props!=properties.end();props++) {
00232 if(((MMSPropertyData *)(*props))->getParameter()==attr->get_value()) {
00233 found=true;
00234 break;
00235 }
00236 }
00237
00238
00239 if(found == false) {
00240 logger.writeLog("create missing property");
00241 this->createProperty(plugin,attr->get_value());
00242 }
00243
00244 }
00245
00246 return;
00247
00248 }
00249 }
00250 catch(const std::exception& ex) {
00251 return;
00252
00253 }
00254 #endif
00255
00256 }