2 * Config_FeatureReader.cpp
4 * Created on: Mar 20, 2014
8 #include <Config_Keywords.h>
9 #include <Config_Common.h>
10 #include <Config_FeatureMessage.h>
11 #include <Config_AttributeMessage.h>
12 #include <Config_FeatureReader.h>
13 #include <Events_Message.h>
14 #include <Events_Loop.h>
16 #include <libxml/parser.h>
17 #include <libxml/tree.h>
18 #include <libxml/xmlstring.h>
28 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile,
29 const std::string& theLibraryName,
30 const char* theEventGenerated)
31 : Config_XMLReader(theXmlFile),
32 myLibraryName(theLibraryName),
33 myEventGenerated(theEventGenerated ? theEventGenerated : Config_FeatureMessage::GUI_EVENT()),
34 myIsProcessWidgets(theEventGenerated != NULL)
38 Config_FeatureReader::~Config_FeatureReader()
42 std::list<std::string> Config_FeatureReader::features() const
47 void Config_FeatureReader::processNode(xmlNodePtr theNode)
49 Events_ID aMenuItemEvent = Events_Loop::eventByName(myEventGenerated);
50 if (isNode(theNode, NODE_FEATURE, NULL)) {
51 storeAttribute(theNode, _ID);
52 std::shared_ptr<Config_FeatureMessage> aMessage(new Config_FeatureMessage(aMenuItemEvent, this));
53 fillFeature(theNode, aMessage);
54 myFeatures.push_back(getProperty(theNode, _ID));
55 //If a feature has xml definition for it's widget:
56 aMessage->setUseInput(hasChild(theNode));
57 Events_Loop::loop()->send(aMessage);
58 //The m_last* variables always defined before fillFeature() call. XML is a tree.
59 } else if (isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL)) {
60 storeAttribute(theNode, _ID);
61 storeAttribute(theNode, WORKBENCH_DOC);
62 } else if (myIsProcessWidgets && isWidgetNode(theNode)) {
63 std::shared_ptr<Config_AttributeMessage> aMessage(new Config_AttributeMessage(aMenuItemEvent, this));
64 aMessage->setFeatureId(restoreAttribute(NODE_FEATURE, _ID));
65 std::string anAttributeID = getProperty(theNode, _ID);
66 if (!anAttributeID.empty()) {
67 aMessage->setAttributeId(anAttributeID);
68 aMessage->setObligatory(getBooleanAttribute(theNode, ATTRIBUTE_OBLIGATORY, true));
69 aMessage->setConcealment(getBooleanAttribute(theNode, ATTRIBUTE_CONCEALMENT, false));
70 Events_Loop::loop()->send(aMessage);
73 //Process SOURCE, VALIDATOR nodes.
74 Config_XMLReader::processNode(theNode);
77 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
79 bool result = isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL);
80 if(!result && myIsProcessWidgets) {
81 result = isNode(theNode, NODE_FEATURE, NULL);
86 void Config_FeatureReader::fillFeature(xmlNodePtr theNode,
87 const std::shared_ptr<Config_FeatureMessage>& outFeatureMessage)
89 outFeatureMessage->setId(getProperty(theNode, _ID));
90 outFeatureMessage->setPluginLibrary(myLibraryName);
91 outFeatureMessage->setNestedFeatures(getProperty(theNode, FEATURE_NESTED));
93 bool isInternal = getBooleanAttribute(theNode, ATTRIBUTE_INTERNAL, false);
94 outFeatureMessage->setInternal(isInternal);
96 //Internal feature has no visual representation.
99 outFeatureMessage->setText(getProperty(theNode, FEATURE_TEXT));
100 outFeatureMessage->setTooltip(getProperty(theNode, FEATURE_TOOLTIP));
101 outFeatureMessage->setIcon(getProperty(theNode, FEATURE_ICON));
102 outFeatureMessage->setKeysequence(getProperty(theNode, FEATURE_KEYSEQUENCE));
103 outFeatureMessage->setGroupId(restoreAttribute(NODE_GROUP, _ID));
104 outFeatureMessage->setWorkbenchId(restoreAttribute(NODE_WORKBENCH, _ID));
105 outFeatureMessage->setDocumentKind(restoreAttribute(NODE_WORKBENCH, WORKBENCH_DOC));
108 void Config_FeatureReader::storeAttribute(xmlNodePtr theNode,
109 const char* theNodeAttribute)
111 std::string aKey = getNodeName(theNode) + ":" + std::string(theNodeAttribute);
112 std::string aValue = getProperty(theNode, theNodeAttribute);
113 if(!aValue.empty()) {
114 myParentAttributes[aKey] = aValue;
118 std::string Config_FeatureReader::restoreAttribute(xmlNodePtr theNode,
119 const char* theNodeAttribute)
121 return restoreAttribute(getNodeName(theNode).c_str(), theNodeAttribute);
123 std::string Config_FeatureReader::restoreAttribute(const char* theNodeName,
124 const char* theNodeAttribute)
126 std::string aKey = std::string(theNodeName) + ":" + std::string(theNodeAttribute);
127 std::string result = "";
128 if(myParentAttributes.find(aKey) != myParentAttributes.end()) {
129 result = myParentAttributes[aKey];