RequestLoader.cpp
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "RequestLoader.h"
namespace TREPS
{
namespace RequestManager
{
RequestLoaderClass::RequestLoaderClass(void):XMLManagerClass(), requestNode(NULL), typeStr("")
{
this->argNodeList.clear();
}
bool RequestLoaderClass::loadAndValid(const char *request_path)
{
//load xml file
if (!this->loadFile(request_path))
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot init request manager");
return false;
}
LOG4CXX_INFO(this->app->getLog()->getPtr(),"Request file loaded " << request_path);
//validation
if (!this->isValid(TREPS_REQUEST_XSD))
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot valid request file " << request_path << " with schema " << TREPS_REQUEST_XSD);
return false;
}
//get request node
this->requestNode = this->getChildFromRoot("request");
if (this->requestNode == NULL)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get request node " << request_path);
return false;
}
//get request type string
this->typeStr = this->getAttributeFromNode("type",requestNode);
if (this->typeStr.compare("") == 0)
{
LOG4CXX_ERROR(this->app->getLog()->getPtr(),"Cannot get request type " << request_path);
return false;
}
//get arg node list
this->argNodeList = this->getChildrenFromNode("arg",this->requestNode);
return true;
}
string RequestLoaderClass::getType(void)
{
return this->typeStr;
}
string RequestLoaderClass::getArgStrByName(const char *arg_name)
{
for (NodeList::iterator argNode = this->argNodeList.begin(); argNode != this->argNodeList.end(); ++argNode)
{
string crtName = this->getAttributeFromNode("name",*argNode);
if (crtName.compare(arg_name) == 0)
return this->getNodeContent(*argNode);
}
return "";
}
}
}