1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include <Config_ValidatorReader.h>
21 #include <Config_Keywords.h>
22 #include <Config_Common.h>
23 #include <Config_ValidatorMessage.h>
24 #include <Config_PropManager.h>
26 #include <Events_Loop.h>
27 #include <libxml/parser.h>
28 #include <libxml/tree.h>
36 Config_ValidatorReader::Config_ValidatorReader(const std::string& theXmlFileName, bool isXMLContent)
37 : Config_XMLReader(theXmlFileName, isXMLContent)
41 Config_ValidatorReader::~Config_ValidatorReader()
45 void Config_ValidatorReader::processNode(xmlNodePtr theNode)
47 if (isNode(theNode, NODE_VALIDATOR, NULL)) {
48 processValidator(theNode);
49 } else if (isNode(theNode, NODE_FEATURE, NULL)) {
50 storeAttribute(theNode, _ID);
51 } else if (isWidgetNode(theNode)) {
52 storeAttribute(theNode, _ID);
53 // Store widget name to restore it's id on validator/selector processing
54 myCurrentWidget = getNodeName(theNode);
56 //Process SOURCE nodes.
57 Config_XMLReader::processNode(theNode);
60 void Config_ValidatorReader::cleanup(xmlNodePtr theNode)
62 if (isNode(theNode, NODE_FEATURE, NULL)) {
63 cleanupAttribute(theNode, _ID);
64 } else if (isWidgetNode(theNode)) {
65 cleanupAttribute(NODE_XMLPARENT, _ID);
66 // Cleanup widget name when leave the widget node.
71 bool Config_ValidatorReader::processChildren(xmlNodePtr aNode)
76 void Config_ValidatorReader::processValidator(xmlNodePtr theNode)
78 Events_ID aValidatoEvent = Events_Loop::eventByName(EVENT_VALIDATOR_LOADED);
79 Events_Loop* aEvLoop = Events_Loop::loop();
80 std::shared_ptr<Config_ValidatorMessage>
81 aMessage(new Config_ValidatorMessage(aValidatoEvent, this));
82 std::string aValidatorId;
83 std::list<std::string> aParameters;
84 getParametersInfo(theNode, aValidatorId, aParameters);
85 aMessage->setValidatorId(aValidatorId);
86 aMessage->setValidatorParameters(aParameters);
87 std::string aFeatureId = restoreAttribute(NODE_FEATURE, _ID);
88 if (aFeatureId.length() == 0)
89 aFeatureId = myExtFeatureId;
90 aMessage->setFeatureId(aFeatureId);
91 // parent is attribute (widget)
92 if (!myCurrentWidget.empty()) {
93 std::string aParentId = restoreAttribute(myCurrentWidget.c_str(), _ID);
94 aMessage->setAttributeId(aParentId);
96 aEvLoop->send(aMessage);