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,
62 void Config_WidgetReader::resolveSourceNodes(xmlNodePtr theNode)
64 xmlNodePtr aNode = xmlFirstElementChild(theNode);
65 std::list<xmlNodePtr> aSourceNodes;
66 while (aNode != NULL) {
67 if (isNode(aNode, NODE_SOURCE, NULL)) {
68 Config_XMLReader aSourceReader = Config_XMLReader(getProperty(aNode, SOURCE_FILE));
69 xmlNodePtr aSourceRoot = aSourceReader.findRoot();
73 xmlNodePtr aSourceNode = xmlFirstElementChild(aSourceRoot);
74 xmlNodePtr aTargetNode = xmlDocCopyNodeList(aNode->doc, aSourceNode);
75 while (aTargetNode != NULL) {
76 xmlNodePtr aNextNode = xmlNextElementSibling(aTargetNode);
77 xmlAddPrevSibling(aNode, aTargetNode);
78 aTargetNode = aNextNode;
80 aSourceNodes.push_back(aNode);
82 aNode = xmlNextElementSibling(aNode);
84 //Remove "SOURCE" node.
85 std::list<xmlNodePtr>::iterator it = aSourceNodes.begin();
86 for (; it != aSourceNodes.end(); it++) {
92 std::string Config_WidgetReader::dumpNode(xmlNodePtr theNode)
94 std::string result = "";
95 if (!hasChild(theNode)) {
98 //Replace all "source" nodes with content;
99 resolveSourceNodes(theNode);
100 xmlBufferPtr buffer = xmlBufferCreate();
101 int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 0);
102 result = std::string((char*) (buffer->content));
103 xmlBufferFree(buffer);