Salome HOME
Issue #29 processing of "source" tags added
[modules/shaper.git] / src / Config / Config_WidgetReader.cpp
1 /*
2  * Config_WidgetReader.cpp
3  *
4  *  Created on: Apr 2, 2014
5  *      Author: sbh
6  */
7
8 #include <Config_WidgetReader.h>
9 #include <Config_Keywords.h>
10 #include <Config_Common.h>
11
12 #include <libxml/parser.h>
13 #include <libxml/tree.h>
14 #include <libxml/xpath.h>
15 #include <libxml/xmlstring.h>
16
17 #ifdef _DEBUG
18 #include <iostream>
19 #endif
20
21
22 Config_WidgetReader::Config_WidgetReader(const std::string& theXmlFile)
23     : Config_XMLReader(theXmlFile)
24
25 {
26 }
27
28 Config_WidgetReader::~Config_WidgetReader()
29 {
30 }
31
32 std::string Config_WidgetReader::featureWidgetCfg(const std::string& theFeatureName)
33 {
34   return myWidgetCache[theFeatureName];
35 }
36
37 std::string Config_WidgetReader::featureDescription(const std::string& theFeatureName)
38 {
39   return myDescriptionCache[theFeatureName];
40 }
41
42
43 void Config_WidgetReader::processNode(xmlNodePtr theNode)
44 {
45   if (isNode(theNode, NODE_FEATURE, NULL)) {
46     std::string aNodeName = getProperty(theNode, _ID);
47     myWidgetCache[aNodeName] = dumpNode(theNode);;
48     myDescriptionCache[aNodeName] = getProperty(theNode, FEATURE_TEXT);
49   }
50   //Process SOURCE nodes.
51   Config_XMLReader::processNode(theNode);
52 }
53
54 bool Config_WidgetReader::processChildren(xmlNodePtr theNode)
55 {
56   return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
57 }
58
59 std::string Config_WidgetReader::dumpNode(xmlNodePtr theNode)
60 {
61   std::string result = "";
62   if (!hasChild(theNode)) {
63     return result;
64   }
65   xmlNodePtr aChildrenNode = xmlFirstElementChild(theNode);
66   xmlBufferPtr buffer = xmlBufferCreate();
67   if (isNode(aChildrenNode, NODE_SOURCE, NULL)) {
68     Config_XMLReader aSourceReader = 
69       Config_XMLReader(getProperty(aChildrenNode, SOURCE_FILE));
70     xmlNodePtr aSourceRoot = aSourceReader.findRoot();
71     int size = xmlNodeDump(buffer, aSourceRoot->doc, aSourceRoot, 0, 1);
72   } else {
73     int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 1);
74   }
75   result = std::string((char*) (buffer->content));
76   return result;
77 }