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_FeatureReader.h>
12 #include <Events_Message.h>
13 #include <Events_Loop.h>
15 #include <libxml/parser.h>
16 #include <libxml/tree.h>
17 #include <libxml/xmlstring.h>
27 Config_FeatureReader::Config_FeatureReader(const std::string& theXmlFile,
28 const std::string& theLibraryName,
29 const char* theEventGenerated)
30 : Config_XMLReader(theXmlFile),
31 myLibraryName(theLibraryName),
32 myEventGenerated(theEventGenerated ? theEventGenerated : EVENT_FEATURE_LOADED)
36 Config_FeatureReader::~Config_FeatureReader()
40 std::list<std::string> Config_FeatureReader::features() const
45 void Config_FeatureReader::processNode(xmlNodePtr theNode)
47 Events_ID aMenuItemEvent = Events_Loop::eventByName(myEventGenerated);
48 if (isNode(theNode, NODE_FEATURE, NULL)) {
49 Events_Loop* aEvLoop = Events_Loop::loop();
50 boost::shared_ptr<Config_FeatureMessage> aMessage(
51 new Config_FeatureMessage(aMenuItemEvent, this));
52 fillFeature(theNode, aMessage);
53 myFeatures.push_back(getProperty(theNode, _ID));
54 //If a feature has xml definition for it's widget:
55 aMessage->setUseInput(hasChild(theNode));
56 aEvLoop->send(aMessage);
57 //The m_last* variables always defined before fillFeature() call. XML is a tree.
58 } else if (isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NULL)) {
59 storeAttribute(theNode, _ID);
60 storeAttribute(theNode, WORKBENCH_DOC);
62 //Process SOURCE, VALIDATOR nodes.
63 Config_XMLReader::processNode(theNode);
66 bool Config_FeatureReader::processChildren(xmlNodePtr theNode)
68 return isNode(theNode, NODE_WORKBENCH, NODE_GROUP, NODE_FEATURE, NULL);
71 void Config_FeatureReader::fillFeature(xmlNodePtr theNode,
72 const boost::shared_ptr<Config_FeatureMessage>& outFeatureMessage)
74 outFeatureMessage->setId(getProperty(theNode, _ID));
75 outFeatureMessage->setPluginLibrary(myLibraryName);
76 outFeatureMessage->setNestedFeatures(getProperty(theNode, FEATURE_NESTED));
78 bool isInternal = isInternalFeature(theNode);
79 outFeatureMessage->setInternal(isInternal);
81 //Internal feature has no visual representation.
84 outFeatureMessage->setText(getProperty(theNode, FEATURE_TEXT));
85 outFeatureMessage->setTooltip(getProperty(theNode, FEATURE_TOOLTIP));
86 outFeatureMessage->setIcon(getProperty(theNode, FEATURE_ICON));
87 outFeatureMessage->setKeysequence(getProperty(theNode, FEATURE_KEYSEQUENCE));
88 outFeatureMessage->setGroupId(restoreAttribute(NODE_GROUP, _ID));
89 outFeatureMessage->setWorkbenchId(restoreAttribute(NODE_WORKBENCH, _ID));
90 outFeatureMessage->setDocumentKind(restoreAttribute(NODE_WORKBENCH, WORKBENCH_DOC));
93 bool Config_FeatureReader::isInternalFeature(xmlNodePtr theNode)
95 std::string prop = getProperty(theNode, FEATURE_INTERNAL);
96 std::transform(prop.begin(), prop.end(), prop.begin(), ::tolower);
97 if (prop.empty() || prop == "false" || prop == "0") {
103 void Config_FeatureReader::storeAttribute(xmlNodePtr theNode,
104 const char* theNodeAttribute)
106 std::string aKey = getNodeName(theNode) + ":" + std::string(theNodeAttribute);
107 std::string aValue = getProperty(theNode, theNodeAttribute);
108 if(!aValue.empty()) {
109 myParentAttributes[aKey] = aValue;
113 std::string Config_FeatureReader::restoreAttribute(xmlNodePtr theNode,
114 const char* theNodeAttribute)
116 return restoreAttribute(getNodeName(theNode).c_str(), theNodeAttribute);
118 std::string Config_FeatureReader::restoreAttribute(const char* theNodeName,
119 const char* theNodeAttribute)
121 std::string aKey = std::string(theNodeName) + ":" + std::string(theNodeAttribute);
122 std::string result = "";
123 if(myParentAttributes.find(aKey) != myParentAttributes.end()) {
124 result = myParentAttributes[aKey];