31 XmlTempLoader::XmlTempLoader(
const char* szPath,
const char* szAppName)
34 strAppName = szAppName;
40 if((strPath.rfind(directorySeparator)==string::npos) ||
41 (strPath.rfind(directorySeparator)!=strPath.size()-1))
42 strPath = strPath + string(directorySeparator);
49 XmlTempLoader::XmlTempLoader(
const char* szFileName)
52 strFileName = szFileName;
56 XmlTempLoader::~XmlTempLoader() =
default;
59 bool XmlTempLoader::init()
67 if(!strFileName.empty())
69 fileNames.push_back(strFileName);
75 logger->
addError(
"No application template path is introduced.");
81 if ((dir = opendir(strPath.c_str())) ==
nullptr)
84 err<<
"Cannot access "<<strPath;
90 while((entry = readdir(dir)))
92 string name = entry->d_name;
95 string ext = name.substr(name.size()-12,12);
97 fileNames.push_back(strPath+name);
104 void XmlTempLoader::reset()
111 void XmlTempLoader::fini()
119 if(strAppName.empty())
124 if(fileNames.empty())
126 string fname = fileNames.back();
127 fileNames.pop_back();
128 app = parsXml(fname.c_str());
134 vector<string>::iterator itr;
135 for(itr=fileNames.begin(); itr<fileNames.end(); itr++)
138 if(app && (app->
name==strAppName))
147 AppTemplate* XmlTempLoader::parsXml(
const char* szFile)
150 app.tmpFileName.clear();
154 TiXmlDocument doc(szFile);
158 err<<
"Syntax error while loading "<<szFile<<
" at line "\
159 <<doc.ErrorRow()<<
": ";
160 err<<doc.ErrorDesc();
166 TiXmlElement *root = doc.RootElement();
170 err<<
"Syntax error while loading "<<szFile<<
" . ";
171 err<<
"No root element.";
181 app.tmpFileName = szFile;
184 auto* name = (TiXmlElement*) root->FirstChild(
"name");
185 if(!name || !name->GetText())
188 err<<
"Application from "<<szFile<<
" has no name.";
194 string strname = name->GetText();
195 for(
char& i : strname)