4 * Created on: Apr 1, 2014
8 #include <Config_WidgetAPI.h>
9 #include <Config_Keywords.h>
10 #include <Config_Common.h>
12 #include <libxml/parser.h>
13 #include <libxml/tree.h>
18 Config_WidgetAPI::Config_WidgetAPI(std::string theRawXml)
20 myDoc = xmlParseDoc(BAD_CAST theRawXml.c_str());
21 myCurrentNode = xmlDocGetRootElement(myDoc);
24 Config_WidgetAPI::~Config_WidgetAPI()
29 bool Config_WidgetAPI::toNextWidget()
31 //Skip all non-element node, stop if next node is null
32 xmlNodePtr aNextNode = myCurrentNode;
34 aNextNode = aNextNode->next;
35 } while (aNextNode && !isElementNode(aNextNode));
41 myCurrentNode = aNextNode;
45 bool Config_WidgetAPI::toChildWidget()
47 if (myCurrentNode && hasChild(myCurrentNode)) {
48 myCurrentNode = myCurrentNode->children;
49 while (!isElementNode(myCurrentNode)) {
50 myCurrentNode = myCurrentNode->next;
57 bool Config_WidgetAPI::toParentWidget()
60 myCurrentNode = myCurrentNode->parent;
62 return myCurrentNode != NULL;
65 std::string Config_WidgetAPI::widgetType() const
67 std::string result = "";
69 result = std::string((char *) myCurrentNode->name);
74 bool Config_WidgetAPI::isContainerWidget() const
76 return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP,
80 bool Config_WidgetAPI::isPagedWidget() const
82 return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH,
86 std::string Config_WidgetAPI::getProperty(const char* thePropName) const
88 std::string result = "";
89 char* aPropChars = (char*) xmlGetProp(myCurrentNode, BAD_CAST thePropName);
90 if (!aPropChars || aPropChars[0] == 0)
92 result = std::string(aPropChars);
96 bool Config_WidgetAPI::getBooleanAttribute(const char* theAttributeName, bool theDefault) const
98 std::string prop = getProperty(theAttributeName);
99 std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
100 bool result = theDefault;
101 if (prop == "true" || prop == "1") {
103 } else if (prop == "false" || prop == "0") {
109 std::string Config_WidgetAPI::widgetId() const
111 return getProperty(_ID);
114 std::string Config_WidgetAPI::widgetIcon() const
116 return getProperty(ANY_WDG_ICON);
119 std::string Config_WidgetAPI::widgetLabel() const
121 return getProperty(ANY_WDG_LABEL);
124 std::string Config_WidgetAPI::widgetTooltip() const
126 return getProperty(ANY_WDG_TOOLTIP);