1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <Config_WidgetReader.h>
22 #include <Config_Keywords.h>
23 #include <Config_Common.h>
25 #include <libxml/parser.h>
26 #include <libxml/tree.h>
27 #include <libxml/xpath.h>
28 #include <libxml/xmlstring.h>
36 Config_WidgetReader::Config_WidgetReader(const std::string& theXmlFile)
37 : Config_XMLReader(theXmlFile)
42 Config_WidgetReader::~Config_WidgetReader()
46 std::string Config_WidgetReader::featureWidgetCfg(const std::string& theFeatureName)
48 return myWidgetCache[theFeatureName];
51 std::string Config_WidgetReader::featureDescription(const std::string& theFeatureName)
53 return myDescriptionCache[theFeatureName];
56 void Config_WidgetReader::processNode(xmlNodePtr theNode)
58 if (isNode(theNode, NODE_FEATURE, NULL)) {
59 std::string aFeature = getProperty(theNode, _ID);
60 myWidgetCache[aFeature] = dumpNode(theNode);
61 myDescriptionCache[aFeature] = getProperty(theNode, FEATURE_TEXT);
63 //Process SOURCE nodes.
64 Config_XMLReader::processNode(theNode);
67 bool Config_WidgetReader::processChildren(xmlNodePtr theNode)
69 //Read all nodes recursively, source and validator nodes have no children
70 return !isNode(theNode, NODE_VALIDATOR,
74 void Config_WidgetReader::resolveSourceNodes(xmlNodePtr theNode)
76 xmlNodePtr aNode = xmlFirstElementChild(theNode);
77 std::list<xmlNodePtr> aSourceNodes;
78 while (aNode != NULL) {
79 if (isNode(aNode, NODE_SOURCE, NULL)) {
80 Config_XMLReader aSourceReader = Config_XMLReader(getProperty(aNode, SOURCE_FILE));
81 xmlNodePtr aSourceRoot = aSourceReader.findRoot();
83 xmlNodePtr aSourceNode = xmlFirstElementChild(aSourceRoot);
84 xmlNodePtr aTargetNode = xmlDocCopyNodeList(aNode->doc, aSourceNode);
85 while (aTargetNode != NULL) {
86 xmlNodePtr aNextNode = xmlNextElementSibling(aTargetNode);
87 xmlAddPrevSibling(aNode, aTargetNode);
88 aTargetNode = aNextNode;
90 aSourceNodes.push_back(aNode);
93 aNode = xmlNextElementSibling(aNode);
95 //Remove "SOURCE" node.
96 std::list<xmlNodePtr>::iterator it = aSourceNodes.begin();
97 for (; it != aSourceNodes.end(); it++) {
103 std::string Config_WidgetReader::dumpNode(xmlNodePtr theNode)
105 std::string result = "";
106 if (!hasChild(theNode)) {
107 // feature which has the next property should be dumped itself
108 std::string anOwnPanel = getProperty(theNode, PROPERTY_PANEL_ID);
109 if (!anOwnPanel.empty()) {
110 xmlBufferPtr buffer = xmlBufferCreate();
111 int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 0);
112 result = std::string((char*) (buffer->content));
113 xmlBufferFree(buffer);
117 //Replace all "source" nodes with content;
118 resolveSourceNodes(theNode);
119 xmlBufferPtr buffer = xmlBufferCreate();
120 int size = xmlNodeDump(buffer, theNode->doc, theNode, 0, 0);
121 result = std::string((char*) (buffer->content));
122 xmlBufferFree(buffer);