2 * Config_WidgetReader.cpp
4 * Created on: Apr 2, 2014
8 #include <Config_WidgetReader.h>
9 #include <Config_Keywords.h>
10 #include <Config_Common.h>
12 #include <libxml/parser.h>
13 #include <libxml/tree.h>
14 #include <libxml/xpath.h>
15 #include <libxml/xmlstring.h>
23 Config_WidgetReader::Config_WidgetReader(const std::string& theXmlFile)
24 : Config_XMLReader(theXmlFile)
29 Config_WidgetReader::~Config_WidgetReader()
33 std::string Config_WidgetReader::featureWidgetCfg(const std::string& theFeatureName)
35 return myWidgetCache[theFeatureName];
38 std::string Config_WidgetReader::featureDescription(const std::string& theFeatureName)
40 return myDescriptionCache[theFeatureName];
43 void Config_WidgetReader::processNode(xmlNodePtr theNode)
45 if (isNode(theNode, NODE_FEATURE, NULL)) {
46 myCurrentFeature = getProperty(theNode, _ID);
47 myWidgetCache[myCurrentFeature] = dumpNode(theNode);
48 myDescriptionCache[myCurrentFeature] = getProperty(theNode, FEATURE_TEXT);
50 //Process SOURCE nodes.
51 Config_XMLReader::processNode(theNode);
54 bool Config_WidgetReader::processChildren(xmlNodePtr theNode)
56 //Read all nodes recursively, source and validator nodes have no children
57 return !isNode(theNode, NODE_VALIDATOR, NODE_SOURCE, NULL);
60 void Config_WidgetReader::resolveSourceNodes(xmlNodePtr theNode)
62 xmlNodePtr aNode = xmlFirstElementChild(theNode);
63 std::list<xmlNodePtr> aSourceNodes;
64 while (aNode != NULL) {
65 if (isNode(aNode, NODE_SOURCE, NULL)) {
66 Config_XMLReader aSourceReader = Config_XMLReader(getProperty(aNode, SOURCE_FILE));
67 xmlNodePtr aSourceRoot = aSourceReader.findRoot();
71 xmlNodePtr aSourceNode = xmlFirstElementChild(aSourceRoot);
72 xmlNodePtr aTargetNode = xmlDocCopyNodeList(aNode->doc, aSourceNode);
73 while (aTargetNode != NULL) {
74 xmlNodePtr aNextNode = xmlNextElementSibling(aTargetNode);
75 xmlAddPrevSibling(aNode, aTargetNode);
76 aTargetNode = aNextNode;
78 aSourceNodes.push_back(aNode);
80 aNode = xmlNextElementSibling(aNode);
82 //Remove "SOURCE" node.
83 std::list<xmlNodePtr>::iterator it = aSourceNodes.begin();
84 for (; it != aSourceNodes.end(); it++) {
90 std::string Config_WidgetReader::dumpNode(xmlNodePtr theNode)
92 std::string result = "";
93 if (!hasChild(theNode)) {
96 //Replace all "source" nodes with content;
97 resolveSourceNodes(theNode);
98 xmlBufferPtr buffer = xmlBufferCreate();
99 int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 0);
100 result = std::string((char*) (buffer->content));
101 xmlBufferFree(buffer);