1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * Config_WidgetReader.cpp
6 * Created on: Apr 2, 2014
10 #include <Config_WidgetReader.h>
11 #include <Config_Keywords.h>
12 #include <Config_Common.h>
14 #include <libxml/parser.h>
15 #include <libxml/tree.h>
16 #include <libxml/xpath.h>
17 #include <libxml/xmlstring.h>
25 Config_WidgetReader::Config_WidgetReader(const std::string& theXmlFile)
26 : Config_XMLReader(theXmlFile)
31 Config_WidgetReader::~Config_WidgetReader()
35 std::string Config_WidgetReader::featureWidgetCfg(const std::string& theFeatureName)
37 return myWidgetCache[theFeatureName];
40 std::string Config_WidgetReader::featureDescription(const std::string& theFeatureName)
42 return myDescriptionCache[theFeatureName];
45 void Config_WidgetReader::processNode(xmlNodePtr theNode)
47 if (isNode(theNode, NODE_FEATURE, NULL)) {
48 std::string aFeature = getProperty(theNode, _ID);
49 myWidgetCache[aFeature] = dumpNode(theNode);
50 myDescriptionCache[aFeature] = getProperty(theNode, FEATURE_TEXT);
52 //Process SOURCE nodes.
53 Config_XMLReader::processNode(theNode);
56 bool Config_WidgetReader::processChildren(xmlNodePtr theNode)
58 //Read all nodes recursively, source and validator nodes have no children
59 return !isNode(theNode, NODE_VALIDATOR,
63 void Config_WidgetReader::resolveSourceNodes(xmlNodePtr theNode)
65 xmlNodePtr aNode = xmlFirstElementChild(theNode);
66 std::list<xmlNodePtr> aSourceNodes;
67 while (aNode != NULL) {
68 if (isNode(aNode, NODE_SOURCE, NULL)) {
69 Config_XMLReader aSourceReader = Config_XMLReader(getProperty(aNode, SOURCE_FILE));
70 xmlNodePtr aSourceRoot = aSourceReader.findRoot();
72 xmlNodePtr aSourceNode = xmlFirstElementChild(aSourceRoot);
73 xmlNodePtr aTargetNode = xmlDocCopyNodeList(aNode->doc, aSourceNode);
74 while (aTargetNode != NULL) {
75 xmlNodePtr aNextNode = xmlNextElementSibling(aTargetNode);
76 xmlAddPrevSibling(aNode, aTargetNode);
77 aTargetNode = aNextNode;
79 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)) {
96 // feature which has the next property should be dumped itself
97 std::string anOwnPanel = getProperty(theNode, PROPERTY_PANEL_ID);
98 if (!anOwnPanel.empty()) {
99 xmlBufferPtr buffer = xmlBufferCreate();
100 int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 0);
101 result = std::string((char*) (buffer->content));
102 xmlBufferFree(buffer);
106 //Replace all "source" nodes with content;
107 resolveSourceNodes(theNode);
108 xmlBufferPtr buffer = xmlBufferCreate();
109 int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 0);
110 result = std::string((char*) (buffer->content));
111 xmlBufferFree(buffer);