diff options
Diffstat (limited to 'src/uscxml/messages')
-rw-r--r-- | src/uscxml/messages/Event.h | 16 | ||||
-rw-r--r-- | src/uscxml/messages/MMIMessages.cpp | 66 | ||||
-rw-r--r-- | src/uscxml/messages/MMIMessages.h | 12 |
3 files changed, 41 insertions, 53 deletions
diff --git a/src/uscxml/messages/Event.h b/src/uscxml/messages/Event.h index 1aa66a1..a63c55f 100644 --- a/src/uscxml/messages/Event.h +++ b/src/uscxml/messages/Event.h @@ -204,8 +204,8 @@ public: typedef std::multimap<std::string, Data> params_t; typedef std::map<std::string, Data> namelist_t; - - static bool getParam(params_t params, const std::string& name, Data& target) { + + static bool getParam(const params_t& params, const std::string& name, Data& target) { if (params.find(name) != params.end()) { target = params.find(name)->second; return true; @@ -213,9 +213,9 @@ public: return false; } - static bool getParam(params_t params, const std::string& name, std::list<Data>& target) { + static bool getParam(const params_t& params, const std::string& name, std::list<Data>& target) { if (params.find(name) != params.end()) { - std::pair<params_t::iterator, params_t::iterator> rangeIter = params.equal_range(name); + std::pair<params_t::const_iterator, params_t::const_iterator> rangeIter = params.equal_range(name); while(rangeIter.first != rangeIter.second) { target.push_back(rangeIter.first->second); rangeIter.first++; @@ -225,7 +225,7 @@ public: return false; } - template <typename T> static bool getParam(params_t params, const std::string& name, T& target) { + template <typename T> static bool getParam(const params_t& params, const std::string& name, T& target) { if (params.find(name) != params.end()) { target = boost::lexical_cast<T>(params.find(name)->second.atom); return true; @@ -233,7 +233,7 @@ public: return false; } - static bool getParam(params_t params, const std::string& name, bool& target) { + static bool getParam(const params_t& params, const std::string& name, bool& target) { if (params.find(name) != params.end()) { target = true; if (iequals(params.find(name)->second.atom, "false")) { @@ -250,9 +250,9 @@ public: return false; } - template <typename T> static bool getParam(params_t params, const std::string& name, std::list<T>& target) { + template <typename T> static bool getParam(const params_t& params, const std::string& name, std::list<T>& target) { if (params.find(name) != params.end()) { - std::pair<params_t::iterator, params_t::iterator> rangeIter = params.equal_range(name); + std::pair<params_t::const_iterator, params_t::const_iterator> rangeIter = params.equal_range(name); while(rangeIter.first != rangeIter.second) { target.push_back(boost::lexical_cast<T>(rangeIter.first->second.atom)); rangeIter.first++; diff --git a/src/uscxml/messages/MMIMessages.cpp b/src/uscxml/messages/MMIMessages.cpp index 1c5b98a..01705ed 100644 --- a/src/uscxml/messages/MMIMessages.cpp +++ b/src/uscxml/messages/MMIMessages.cpp @@ -119,22 +119,13 @@ Arabica::DOM::Document<std::string> MMIEvent::toXML(bool encapsulateInMMI) const if (data.size() > 0) { Element<std::string> dataElem = doc.createElementNS(nameSpace, "Data"); - - // try to parse content - std::stringstream* ss = new std::stringstream(); - (*ss) << data; - std::auto_ptr<std::istream> ssPtr(ss); - Arabica::SAX::InputSource<std::string> inputSource; - inputSource.setByteStream(ssPtr); - - NameSpacingParser parser; - if(parser.parse(inputSource)) { - Node<std::string> importedNode = doc.importNode(parser.getDocument().getDocumentElement(), true); - dataElem.appendChild(importedNode); - } else { - Text<std::string> textElem = doc.createTextNode(data); - dataElem.appendChild(textElem); - } + Text<std::string> textElem = doc.createTextNode(data); + dataElem.appendChild(textElem); + msgElem.appendChild(dataElem); + } else if (dataDOM) { + Element<std::string> dataElem = doc.createElementNS(nameSpace, "Data"); + Node<std::string> importNode = doc.importNode(dataDOM, true); + dataElem.appendChild(importNode); msgElem.appendChild(dataElem); } @@ -165,28 +156,16 @@ Arabica::DOM::Document<std::string> ContentRequest::toXML(bool encapsulateInMMI) contentURLElem.setAttributeNS(nameSpace, "fetchtimeout", contentURL.fetchTimeout); contentURLElem.setAttributeNS(nameSpace, "max-age", contentURL.maxAge); msgElem.appendChild(contentURLElem); - } - - if (content.size() > 0) { - Element<std::string> contentElem = doc.createElementNS(nameSpace, "content"); - - // try to parse content - std::stringstream* ss = new std::stringstream(); - (*ss) << content; - std::auto_ptr<std::istream> ssPtr(ss); - Arabica::SAX::InputSource<std::string> inputSource; - inputSource.setByteStream(ssPtr); - - Arabica::SAX2DOM::Parser<std::string> parser; - if(parser.parse(inputSource)) { - Node<std::string> importedNode = doc.importNode(parser.getDocument().getDocumentElement(), true); - contentElem.appendChild(importedNode); - } else { - Text<std::string> textElem = doc.createTextNode(content); - contentElem.appendChild(textElem); - } + } else if (contentDOM) { + Element<std::string> contentElem = doc.createElementNS(nameSpace, "Content"); + Node<std::string> importNode = doc.importNode(contentDOM, true); + contentElem.appendChild(importNode); + msgElem.appendChild(contentElem); + } else if (content.size() > 0) { + Element<std::string> contentElem = doc.createElementNS(nameSpace, "Content"); + Text<std::string> textElem = doc.createTextNode(content); + contentElem.appendChild(textElem); msgElem.appendChild(contentElem); - } return doc; } @@ -259,12 +238,15 @@ MMIEvent MMIEvent::fromXML(Arabica::DOM::Node<std::string> node, InterpreterImpl node = node.getNextSibling(); } - if (dataElem && boost::iequals(dataElem.getLocalName(), "data")) { - std::stringstream ss; + if (dataElem && boost::iequals(dataElem.getLocalName(), "data") && dataElem.getFirstChild()) { node = dataElem.getFirstChild(); - if (node) + if (node.getNodeType() == Arabica::DOM::Node_base::ELEMENT_NODE) { + msg.dataDOM = node; + } else { + std::stringstream ss; ss << node; - msg.data = ss.str(); + msg.data = ss.str(); + } } return msg; @@ -374,6 +356,8 @@ StatusResponse StatusResponse::fromXML(Arabica::DOM::Node<std::string> node, Int msg.status = FAILURE; } else if(boost::iequals(status, "SUCCESS")) { msg.status = SUCCESS; + } else { + msg.status = INVALID; } msg.type = STATUSRESPONSE; return msg; diff --git a/src/uscxml/messages/MMIMessages.h b/src/uscxml/messages/MMIMessages.h index e4456f8..c6a2fce 100644 --- a/src/uscxml/messages/MMIMessages.h +++ b/src/uscxml/messages/MMIMessages.h @@ -62,6 +62,7 @@ public: std::string source; std::string target; std::string data; + Arabica::DOM::Node<std::string> dataDOM; std::string requestId; std::string tagName; Type type; @@ -228,6 +229,7 @@ public: InterpreterImpl* interpreter = NULL); operator Event() const; std::string content; + Arabica::DOM::Node<std::string> contentDOM; ContentURL contentURL; protected: ContentRequest() {} @@ -296,15 +298,17 @@ protected: class StatusResponse : public ContextualizedRequest { public: enum Status { - ALIVE = 0, - DEAD = 1, - SUCCESS = 2, - FAILURE = 3 + INVALID = 0, + ALIVE = 1, + DEAD = 2, + SUCCESS = 3, + FAILURE = 4 }; StatusResponse() { tagName = "StatusResponse"; type = STATUSRESPONSE; + status = INVALID; } virtual Arabica::DOM::Document<std::string> toXML(bool encapsulateInMMI = false) const; static StatusResponse fromXML(Arabica::DOM::Node<std::string> node, |