//=============================================================================
ResourcesManager_cpp::
-ResourcesManager_cpp(const char *xmlFilePath) :
- _path_resources(xmlFilePath)
+ResourcesManager_cpp(const char *xmlFilePath)
{
+ _path_resources.push_back(xmlFilePath);
#if defined(_DEBUG_) || defined(_DEBUG)
cerr << "ResourcesManager_cpp constructor" << endl;
#endif
#if defined(_DEBUG_) || defined(_DEBUG)
cerr << "ResourcesManager_cpp constructor" << endl;
#endif
- _isAppliSalomeDefined = (getenv("APPLI") != 0);
- if(!getenv("KERNEL_ROOT_DIR"))
- throw ResourcesException("you must define KERNEL_ROOT_DIR environment variable!!");
- if (_isAppliSalomeDefined)
+ std::string default_file("");
+ if (getenv("APPLI") != 0)
{
- _path_resources = getenv("HOME");
- _path_resources += "/";
- _path_resources += getenv("APPLI");
- _path_resources += "/CatalogResources.xml";
+ default_file += getenv("HOME");
+ default_file += "/";
+ default_file += getenv("APPLI");
+ default_file += "/CatalogResources.xml";
+ _path_resources.push_back(default_file);
}
-
else
{
- _path_resources = getenv("KERNEL_ROOT_DIR");
- _path_resources += "/share/salome/resources/kernel/CatalogResources.xml";
+ if(!getenv("KERNEL_ROOT_DIR"))
+ throw ResourcesException("you must define KERNEL_ROOT_DIR environment variable!! -> cannot load a CatalogResources.xml");
+ default_file = getenv("KERNEL_ROOT_DIR");
+ default_file += "/share/salome/resources/kernel/CatalogResources.xml";
+ _path_resources.push_back(default_file);
}
- ParseXmlFile();
+ if (getenv("USER_CATALOG_RESOURCES_FILE") != 0)
+ {
+ std::string user_file("");
+ user_file = getenv("USER_CATALOG_RESOURCES_FILE");
+ _path_resources.push_back(user_file);
+ }
+
+ ParseXmlFiles();
#if defined(_DEBUG_) || defined(_DEBUG)
cerr << "ResourcesManager_cpp constructor end";
#endif
{
vector <std::string> vec;
- ParseXmlFile();
+ ParseXmlFiles();
const char *hostname = params.hostname.c_str();
#if defined(_DEBUG_) || defined(_DEBUG)
*/
//=============================================================================
-void ResourcesManager_cpp::WriteInXmlFile()
+void ResourcesManager_cpp::WriteInXmlFile(std::string & xml_file)
{
- const char* aFilePath = _path_resources.c_str();
-
+#if defined(_DEBUG_) || defined(_DEBUG)
+ std::cerr << "WriteInXmlFile : start" << std::endl;
+#endif
+ const char* aFilePath = xml_file.c_str();
FILE* aFile = fopen(aFilePath, "w");
if (aFile == NULL)
- {
-#if defined(_DEBUG_) || defined(_DEBUG)
- cerr << "Error opening file !" << endl;
-#endif
- return;
- }
+ {
+ std::cerr << "Error opening file in WriteInXmlFile : " << xml_file << std::endl;
+ return;
+ }
xmlDocPtr aDoc = xmlNewDoc(BAD_CAST "1.0");
xmlNewDocComment(aDoc, BAD_CAST "ResourcesCatalog");
handler->PrepareDocToXmlFile(aDoc);
delete handler;
-#if defined(_DEBUG_) || defined(_DEBUG)
int isOk = xmlSaveFile(aFilePath, aDoc);
- if (!isOk) cerr << "Error while XML file saving." << endl;
-#else
- xmlSaveFile(aFilePath, aDoc);
-#endif
+ if (!isOk)
+ std::cerr << "Error while XML file saving : " << xml_file << std::endl;
// Free the document
xmlFreeDoc(aDoc);
-
fclose(aFile);
-
#if defined(_DEBUG_) || defined(_DEBUG)
- cerr << "WRITING DONE!" << endl;
+ std::cerr << "WriteInXmlFile : WRITING DONE!" << std::endl;
#endif
}
*/
//=============================================================================
-const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFile()
+const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFiles()
{
- SALOME_ResourcesCatalog_Handler* handler =
- new SALOME_ResourcesCatalog_Handler(_resourcesList, _resourcesBatchList);
+ // Nettoyage des variables (est-ce vraiment utile ?)
+ _resourcesList.clear();
+ _resourcesBatchList.clear();
- const char* aFilePath = _path_resources.c_str();
- FILE* aFile = fopen(aFilePath, "r");
-
- if (aFile != NULL)
+ // On parse tous les fichiers
+ for(_path_resources_it = _path_resources.begin(); _path_resources_it != _path_resources.end(); ++_path_resources_it)
+ {
+ MapOfParserResourcesType _resourcesList_tmp;
+ MapOfParserResourcesType _resourcesBatchList_tmp;
+ SALOME_ResourcesCatalog_Handler* handler =
+ new SALOME_ResourcesCatalog_Handler(_resourcesList_tmp, _resourcesBatchList_tmp);
+ const char* aFilePath = (*_path_resources_it).c_str();
+ FILE* aFile = fopen(aFilePath, "r");
+
+ if (aFile != NULL)
{
xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0);
-
if (aDoc != NULL)
+ {
handler->ProcessXmlDocument(aDoc);
-#if defined(_DEBUG_) || defined(_DEBUG)
+
+ // adding new resources to the file
+ for (MapOfParserResourcesType_it i = _resourcesList_tmp.begin(); i != _resourcesList_tmp.end(); ++i)
+ {
+ MapOfParserResourcesType_it j = _resourcesList.find(i->first);
+ if (j == _resourcesList.end())
+ {
+ _resourcesList[i->first] = i->second;
+ }
+ else
+ {
+ std::cerr << "ParseXmlFiles Warning, to resource with the same name was found, taking the first declaration : " << i->first << std::endl;
+ }
+ }
+ for (MapOfParserResourcesType_it i = _resourcesBatchList_tmp.begin(); i != _resourcesBatchList_tmp.end(); ++i)
+ {
+ MapOfParserResourcesType_it j = _resourcesBatchList.find(i->first);
+ if (j == _resourcesBatchList.end())
+ {
+ _resourcesBatchList[i->first] = i->second;
+ }
+ else
+ {
+ std::cerr << "ParseXmlFiles Warning, to resource with the same name was found, taking the first declaration : " << i->first << std::endl;
+ }
+ }
+ }
else
- cerr << "ResourcesManager_cpp: could not parse file "<< aFilePath << endl;
-#endif
-
+ std::cerr << "ResourcesManager_cpp: could not parse file " << aFilePath << std::endl;
// Free the document
xmlFreeDoc(aDoc);
-
fclose(aFile);
}
-#if defined(_DEBUG_) || defined(_DEBUG)
- else
- cerr << "ResourcesManager_cpp: file "<<aFilePath<<" is not readable." << endl;
-#endif
-
- delete handler;
+ else
+ std::cerr << "ResourcesManager_cpp: file " << aFilePath << " is not readable." << std::endl;
+ delete handler;
+ }
return _resourcesList;
}