1 // Copyright (C) 2014-2023 CEA, EDF
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 email : webmaster.salome@opencascade.com
20 #include <Config_WidgetReader.h>
21 #include <Config_Keywords.h>
22 #include <Config_Common.h>
24 #include <libxml/parser.h>
25 #include <libxml/tree.h>
26 #include <libxml/xpath.h>
27 #include <libxml/xmlstring.h>
35 Config_WidgetReader::Config_WidgetReader(const std::string& theXmlFile)
36 : Config_XMLReader(theXmlFile)
41 Config_WidgetReader::~Config_WidgetReader()
45 std::string Config_WidgetReader::featureWidgetCfg(const std::string& theFeatureName)
47 return myWidgetCache[theFeatureName];
50 std::string Config_WidgetReader::featureDescription(const std::string& theFeatureName)
52 return myDescriptionCache[theFeatureName];
55 void Config_WidgetReader::processNode(xmlNodePtr theNode)
57 if (isNode(theNode, NODE_FEATURE, NULL)) {
58 std::string aFeature = getProperty(theNode, _ID);
59 myWidgetCache[aFeature] = dumpNode(theNode);
60 myDescriptionCache[aFeature] = getProperty(theNode, FEATURE_TEXT);
62 //Process SOURCE nodes.
63 Config_XMLReader::processNode(theNode);
66 bool Config_WidgetReader::processChildren(xmlNodePtr theNode)
68 //Read all nodes recursively, source and validator nodes have no children
69 return !isNode(theNode, NODE_VALIDATOR,
73 void Config_WidgetReader::resolveSourceNodes(xmlNodePtr theNode)
75 xmlNodePtr aNode = xmlFirstElementChild(theNode);
76 std::list<xmlNodePtr> aSourceNodes;
77 while (aNode != NULL) {
78 if (isNode(aNode, NODE_SOURCE, NULL)) {
79 Config_XMLReader aSourceReader = Config_XMLReader(getProperty(aNode, SOURCE_FILE));
80 xmlNodePtr aSourceRoot = aSourceReader.findRoot();
82 xmlNodePtr aSourceNode = xmlFirstElementChild(aSourceRoot);
83 xmlNodePtr aTargetNode = xmlDocCopyNodeList(aNode->doc, aSourceNode);
84 while (aTargetNode != NULL) {
85 xmlNodePtr aNextNode = xmlNextElementSibling(aTargetNode);
86 xmlAddPrevSibling(aNode, aTargetNode);
87 aTargetNode = aNextNode;
89 aSourceNodes.push_back(aNode);
92 aNode = xmlNextElementSibling(aNode);
94 //Remove "SOURCE" node.
95 std::list<xmlNodePtr>::iterator it = aSourceNodes.begin();
96 for (; it != aSourceNodes.end(); it++) {
102 std::string Config_WidgetReader::dumpNode(xmlNodePtr theNode)
104 std::string result = "";
105 if (!hasChild(theNode)) {
106 // feature which has the next property should be dumped itself
107 std::string anOwnPanel = getProperty(theNode, PROPERTY_PANEL_ID);
108 if (!anOwnPanel.empty()) {
109 xmlBufferPtr buffer = xmlBufferCreate();
113 xmlNodeDump(buffer, theNode->doc, theNode, 0, 0);
114 result = std::string((char*) (buffer->content));
115 xmlBufferFree(buffer);
119 //Replace all "source" nodes with content;
120 resolveSourceNodes(theNode);
121 xmlBufferPtr buffer = xmlBufferCreate();
125 xmlNodeDump(buffer, theNode->doc, theNode, 0, 0);
126 result = std::string((char*) (buffer->content));
127 xmlBufferFree(buffer);