diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bindings/swig/php/uscxmlNativePHP.php | 4 | ||||
-rw-r--r-- | src/uscxml/Interpreter.cpp | 72 | ||||
-rw-r--r-- | src/uscxml/Message.cpp | 5 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp | 37 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h | 29 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp | 25 |
6 files changed, 54 insertions, 118 deletions
diff --git a/src/bindings/swig/php/uscxmlNativePHP.php b/src/bindings/swig/php/uscxmlNativePHP.php index c15f979..eb66b3d 100644 --- a/src/bindings/swig/php/uscxmlNativePHP.php +++ b/src/bindings/swig/php/uscxmlNativePHP.php @@ -769,6 +769,10 @@ class Interpreter { return $r; } + static function spaceNormalize($text) { + return Interpreter_spaceNormalize($text); + } + function isInitial($state) { return Interpreter_isInitial($this->_cPtr,$state); } diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 7fe5cc1..b314d1a 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -471,78 +471,6 @@ void InterpreterImpl::processContentElement(const Arabica::DOM::Node<std::string } else { LOG(ERROR) << "content element does not specify any content."; } - -#if 0 - try { - std::string contentToProcess; - if (HAS_ATTR(content, "expr")) { - if (_dataModel) { - /// this is out of spec - contentToProcess = ATTR(content, "expr"); - // sendReq.data.atom = contentValue; - // sendReq.data.type = Data::VERBATIM; - } else { - LOG(ERROR) << "content element has expr attribute but no datamodel is specified."; - } - } else if (content.hasChildNodes()) { - bool presentAsDom = false; - Node<std::string> contentChild = content.getFirstChild(); - while(contentChild) { - if (contentChild.getNodeType() == Node_base::TEXT_NODE) { - std::string trimmed = contentChild.getNodeValue(); - boost::trim(trimmed); - if (trimmed.length() > 0) - break; - } - if (contentChild.getNodeType() == Node_base::ELEMENT_NODE) { - presentAsDom = true; - break; - } - contentChild = contentChild.getNextSibling(); - } - - if (contentChild && presentAsDom) { - // use the whole dom - DOMImplementation<std::string> domFactory = Arabica::SimpleDOM::DOMImplementation<std::string>::getDOMImplementation(); - dom = domFactory.createDocument(contentChild.getNamespaceURI(), "", 0); - Node<std::string> newNode = dom.importNode(contentChild, true); - dom.appendChild(newNode); - } else if (contentChild) { - contentToProcess = contentChild.getNodeValue(); - } else { - LOG(ERROR) << "content element has neither text nor element children."; - } - } else { - LOG(ERROR) << "content element does not specify any content."; - } - if (contentToProcess.size() > 0) { - /// try to interpret as JSON - std::string trimmedContent = contentToProcess; - boost::trim(trimmedContent); - if (trimmedContent.find_first_of("{[") == 0) { - data = Data::fromJSON(contentToProcess); - if (data) - return; - } - /// create space normalized string - std::istringstream iss(contentToProcess); - std::stringstream content; - std::string seperator; - do { - std::string token; - iss >> token; - if (token.length() > 0) { - content << seperator << token; - seperator = " "; - } - } while (iss); - text = content.str(); - } - } catch (Event e) { - e.name = "error.execution"; - receiveInternal(e); - } -#endif } void InterpreterImpl::processDOMorText(const Arabica::DOM::Node<std::string>& node, diff --git a/src/uscxml/Message.cpp b/src/uscxml/Message.cpp index 0898cc7..c3f4281 100644 --- a/src/uscxml/Message.cpp +++ b/src/uscxml/Message.cpp @@ -188,13 +188,16 @@ Data Data::fromJSON(const std::string& jsonString) { if (trimmed.length() == 0) return data; + if (trimmed.find_first_of("{[") != 0) + return data; + jsmn_parser p; jsmntok_t* t = NULL; // we do not know the number of tokens beforehand, start with something sensible and increase int rv; - int frac = 16; // this will get decreased to 16 to first iteration for 1/16 length/token ratio + int frac = 16; // length/token ratio do { jsmn_init(&p); diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp index f3af4b6..fcd606d 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp @@ -134,38 +134,25 @@ std::string SWIDataModel::evalAsString(const std::string& expr) { return std::string(compound); } -void SWIDataModel::assign(const std::string& location, +void SWIDataModel::assign(const Arabica::DOM::Element<std::string>& assignElem, const Arabica::DOM::Document<std::string>& doc, - const Arabica::DOM::Element<std::string>& assignElem) { - + const std::string& content) { + std::string expr = content; + if (HAS_ATTR(assignElem, "expr")) { + expr = ATTR(assignElem, "expr"); + } + if (expr.length() > 0) + eval(expr); } -void SWIDataModel::assign(const std::string& location, - const std::string& expr, - const Arabica::DOM::Element<std::string>& assignElem) { - eval(expr); -} -void SWIDataModel::assign(const std::string& location, - const Data& data, - const Arabica::DOM::Element<std::string>& assignElem) { +void SWIDataModel::assign(const std::string& location, const Data& data) { eval(data.atom); } -void SWIDataModel::init(const std::string& location, +void SWIDataModel::init(const Arabica::DOM::Element<std::string>& dataElem, const Arabica::DOM::Document<std::string>& doc, - const Arabica::DOM::Element<std::string>& dataElem) { - -} -void SWIDataModel::init(const std::string& location, - const std::string& expr, - const Arabica::DOM::Element<std::string>& dataElem) { - -} -void SWIDataModel::init(const std::string& location, - const Data& data, - const Arabica::DOM::Element<std::string>& dataElem) { - -} + const std::string& content) {} +void SWIDataModel::init(const std::string& location, const Data& data) {} bool SWIDataModel::isDeclared(const std::string& expr) { return true; diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h index 5d95476..a278db8 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h @@ -36,6 +36,16 @@ public: virtual void pushContext(); virtual void popContext(); + virtual void assign(const Arabica::DOM::Element<std::string>& assignElem, + const Arabica::DOM::Document<std::string>& doc, + const std::string& content); + virtual void assign(const std::string& location, const Data& data); + + virtual void init(const Arabica::DOM::Element<std::string>& dataElem, + const Arabica::DOM::Document<std::string>& doc, + const std::string& content); + virtual void init(const std::string& location, const Data& data); + virtual void eval(const std::string& expr); virtual bool isDeclared(const std::string& expr); @@ -44,25 +54,6 @@ public: virtual std::string evalAsString(const std::string& expr); virtual bool evalAsBool(const std::string& expr); - virtual void assign(const std::string& location, - const Arabica::DOM::Document<std::string>& doc, - const Arabica::DOM::Element<std::string>& assignElem); - virtual void assign(const std::string& location, - const std::string& expr, - const Arabica::DOM::Element<std::string>& assignElem); - virtual void assign(const std::string& location, - const Data& data, - const Arabica::DOM::Element<std::string>& assignElem); - - virtual void init(const std::string& location, - const Arabica::DOM::Document<std::string>& doc, - const Arabica::DOM::Element<std::string>& dataElem); - virtual void init(const std::string& location, - const std::string& expr, - const Arabica::DOM::Element<std::string>& dataElem); - virtual void init(const std::string& location, - const Data& data, - const Arabica::DOM::Element<std::string>& dataElem); protected: Event _event; diff --git a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp index eef8e51..0c649f5 100644 --- a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp +++ b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp @@ -187,7 +187,30 @@ bool XPathDataModel::evalAsBool(const std::string& expr) { std::string XPathDataModel::evalAsString(const std::string& expr) { XPathValue<std::string> result = _xpath.evaluate_expr(expr, _doc); - return result.asString(); + switch (result.type()) { + case STRING: + return result.asString(); + break; + case BOOL: + return (result.asBool() ? "true" : "false"); + break; + case NUMBER: + return toStr(result.asNumber()); + break; + case NODE_SET: { + NodeSet<std::string> nodeSet = result.asNodeSet(); + std::stringstream ss; + for (int i = 0; i < nodeSet.size(); i++) { + ss << nodeSet[i] << std::endl; + } + return ss.str(); + break; + } + case ANY: + throw Event("error.execution", Event::PLATFORM); + break; + } + return "undefined"; } double XPathDataModel::evalAsNumber(const std::string& expr) { |