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, ATTR_OBLIGATORY, true));
69 aMessage->setConcealment(getBooleanAttribute(theNode, ATTR_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 theFeatureNode,
87 const std::shared_ptr<Config_FeatureMessage>& outFeatureMessage)
89 outFeatureMessage->setId(getProperty(theFeatureNode, _ID));
90 outFeatureMessage->setPluginLibrary(myLibraryName);
91 outFeatureMessage->setNestedFeatures(getProperty(theFeatureNode, FEATURE_NESTED));
93 bool isInternal = getBooleanAttribute(theFeatureNode, ATTR_INTERNAL, false);
94 outFeatureMessage->setInternal(isInternal);
96 //Internal feature has no visual representation.
99 outFeatureMessage->setText(getProperty(theFeatureNode, FEATURE_TEXT));
100 outFeatureMessage->setTooltip(getProperty(theFeatureNode, FEATURE_TOOLTIP));
101 outFeatureMessage->setIcon(getProperty(theFeatureNode, FEATURE_ICON));
102 outFeatureMessage->setKeysequence(getProperty(theFeatureNode, FEATURE_KEYSEQUENCE));
103 outFeatureMessage->setGroupId(restoreAttribute(NODE_GROUP, _ID));
104 outFeatureMessage->setWorkbenchId(restoreAttribute(NODE_WORKBENCH, _ID));
105 // Get document kind of a feature, if empty set workbench's kind (might be empty too)
106 std::string aDocKind = getProperty(theFeatureNode, FEATURE_DOC);
107 if(aDocKind.empty()) {
108 aDocKind = restoreAttribute(NODE_WORKBENCH, WORKBENCH_DOC);
110 outFeatureMessage->setDocumentKind(aDocKind);
113 void Config_FeatureReader::storeAttribute(xmlNodePtr theNode,
114 const char* theNodeAttribute)
116 std::string aKey = getNodeName(theNode) + ":" + std::string(theNodeAttribute);
117 std::string aValue = getProperty(theNode, theNodeAttribute);
118 if(!aValue.empty()) {
119 myParentAttributes[aKey] = aValue;
123 std::string Config_FeatureReader::restoreAttribute(xmlNodePtr theNode,
124 const char* theNodeAttribute)
126 return restoreAttribute(getNodeName(theNode).c_str(), theNodeAttribute);
128 std::string Config_FeatureReader::restoreAttribute(const char* theNodeName,
129 const char* theNodeAttribute)
131 std::string aKey = std::string(theNodeName) + ":" + std::string(theNodeAttribute);
132 std::string result = "";
133 if(myParentAttributes.find(aKey) != myParentAttributes.end()) {
134 result = myParentAttributes[aKey];