4 * Created on: Apr 17, 2014
\r
8 #include "Config_Common.h"
\r
9 #include <Config_Keywords.h>
\r
11 #include <libxml/parser.h>
\r
12 #include <libxml/tree.h>
\r
14 #include <sstream> // for stringstream
\r
17 #include <algorithm> // for std::transform
\r\r
18 bool isElementNode(xmlNodePtr theNode)
\r
20 return theNode->type == XML_ELEMENT_NODE;
\r
23 bool isNode(xmlNodePtr theNode, const char* theNodeName, ...)
\r
25 bool result = false;
\r
26 const xmlChar* aName = theNode->name;
\r
27 if (!aName || !isElementNode(theNode)) {
\r
30 if (!xmlStrcmp(aName, (const xmlChar *) theNodeName)) {
\r
33 va_list args; // define argument list variable
\r
34 va_start(args, theNodeName); // init list; point to last defined argument
\r
36 char *anArg = va_arg (args, char*); // get next argument
\r
39 if (!xmlStrcmp(aName, (const xmlChar *) anArg)) {
\r
40 va_end(args); // cleanup the system stack
\r
44 va_end(args); // cleanup the system stack
\r
48 bool isWidgetNode(xmlNodePtr theNode)
\r
50 if(!isElementNode(theNode))
\r
52 // it's parent is "feature" or "source"
\r
53 xmlNodePtr aParentNode = theNode->parent;
\r
54 if(!isNode(aParentNode, NODE_FEATURE, NODE_SOURCE, NULL))
\r
57 //it should not be a "source" or a "validator" node
\r
58 return !isNode(theNode, NODE_SOURCE, NODE_VALIDATOR, NULL);
\r
61 bool hasChild(xmlNodePtr theNode)
\r
63 xmlNodePtr aNode = theNode->children;
\r
64 for (; aNode; aNode = aNode->next) {
\r
65 if (isElementNode(theNode)) {
\r
72 bool getValidatorInfo(xmlNodePtr theNode, std::string& outValidatorId,
\r
73 std::list<std::string>& outValidatorParameters)
\r
76 char* anIdProp = (char*) xmlGetProp(theNode, BAD_CAST _ID);
\r
77 if (!anIdProp || anIdProp[0] == 0) {
\r
80 outValidatorId = std::string(anIdProp);
\r
82 //Validator parameters:
\r
83 char* aParamProp = (char*) xmlGetProp(theNode, BAD_CAST VALIDATOR_PARAMETERS);
\r
84 if (aParamProp && aParamProp[0] != 0) {
\r
85 std::string aPropString = std::string(aParamProp);
\r
86 std::stringstream aPropStringStream(aPropString);
\r
87 char COMMA_DELIM = ',';
\r
88 std::string aValidatorParameter;
\r
89 while (std::getline(aPropStringStream, aValidatorParameter, ',')) {
\r
90 outValidatorParameters.push_back(aValidatorParameter);
\r
96 std::string library(const std::string& theLibName)
\r
98 std::string aLibName = theLibName;
\r
100 static std::string aLibExt( ".so" );
\r
101 if (aLibName.size() < 3 || aLibName.substr(0, 3) !="lib") {
\r
102 aLibName = "lib" + aLibName;
\r
105 static std::string aLibExt(".dll");
\r
107 std::string anExt = aLibName.substr(aLibName.size() - 4);
\r
108 if (anExt != aLibExt)
\r
109 aLibName += aLibExt;
\r
114 std::string getProperty(xmlNodePtr theNode, const char* thePropName)
\r
116 std::string result = "";
\r
117 char* aPropChars = (char*) xmlGetProp(theNode, BAD_CAST thePropName);
\r
118 if (!aPropChars || aPropChars[0] == 0)
\r
120 result = std::string(aPropChars);
\r
124 bool getBooleanAttribute(xmlNodePtr theNode, const char* theAttributeName, bool theDefault)
\r
126 std::string prop = getProperty(theNode, theAttributeName);
\r
127 std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
\r
128 bool result = theDefault;
\r
129 if (prop == "true" || prop == "1") {
\r
131 } else if (prop == "false" || prop == "0") {
\r