#include <cstring>
#include <string>
#include <utility>
+#include <functional>
#include <libxml/tree.h>
#include <libxml/xmlschemas.h>
#include "mdss.h"
MODES_NAMESPACE_USE;
+
ModeXMLParser::ModeXMLParser(const std::string &modeFile, RuleManager &rMgr)
: ModeParser(rMgr), XMLParser(modeFile), isParsedModeAttr(false)
{
Mode ModeXMLParser::getMode()
{
- iterateElement(getRoot());
+ iterateElement(getRoot(), std::bind(&ModeXMLParser::parseElement, this, std::placeholders::_1));
return mode;
}
}
}
+void ModeXMLParser::validateAction(xmlNodePtr node)
+{
+ char *actionTypeProp = (char*)xmlGetProp(node, ModesXMLTag::TYPE);
+ if (actionTypeProp && MDS_EQUAL == strcmp(actionTypeProp, "async")) {
+ char *stopOnErrProp = (char*)xmlGetProp(node, ModesXMLTag::STOP_ON_ERR);
+ if (stopOnErrProp && MDS_EQUAL == strcmp(stopOnErrProp, "true")) {
+ xmlFree(stopOnErrProp);
+ xmlFree(actionTypeProp);
+ ERR("Can NOT support stopOnErr in async");
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
+ xmlFree(stopOnErrProp);
+ }
+ xmlFree(actionTypeProp);
+}
+
void ModeXMLParser::validateMode(const std::string &xsd)
{
try {
validate(xsd);
+ iterateElement(getRoot(), std::bind(&ModeXMLParser::validateElement, this, std::placeholders::_1));
} catch (ModesEx &e) {
ERR("validate() Fail(%s)", e.what());
throw ModesEx(ModesEx::INVALID_ARG);
}
}
-void ModeXMLParser::iterateElement(xmlNodePtr node)
+void ModeXMLParser::iterateElement(xmlNodePtr node, std::function<void(xmlNodePtr)> func)
{
xmlNode *cur = NULL;
for (cur = node; cur; cur = cur->next) {
if (xmlIsBlankNode(cur))
continue;
- parseElement(cur);
- iterateElement(cur->children);
+ func(cur);
+ iterateElement(cur->children, func);
}
}
+void ModeXMLParser::validateElement(xmlNodePtr node)
+{
+ if (MDS_EQUAL == xmlStrcmp(node->name, ModesXMLTag::ACTION))
+ validateAction(node);
+}
+
void ModeXMLParser::parseElement(xmlNodePtr node)
{
if (MDS_EQUAL == xmlStrcmp(node->name, ModesXMLTag::MODE)) {
#include <libxml/tree.h>
#include <utility>
+#include <functional>
#include "mdss.h"
#include "ModeParser.h"
#include "XMLParser.h"
void validateMode(const std::string &xsd) override;
private:
- void iterateElement(xmlNodePtr node);
- void parseElement(xmlNodePtr node);
void parseMode(xmlNodePtr node);
std::string extractModeName(xmlNodePtr node);
Mode::ModeType extractModeType(xmlNodePtr node);
void parseUndo(xmlNodePtr node);
Action *parseActionInfo(xmlNodePtr node);
void parseModeAttr();
+ void validateAction(xmlNodePtr node);
+ void validateElement(xmlNodePtr node);
+ void parseElement(xmlNodePtr node);
+ void iterateElement(xmlNodePtr node, std::function<void(xmlNodePtr)> func);
Mode mode;
std::string filePath;