diff options
author | Stefan Radomski <github@mintwerk.de> | 2017-07-19 14:41:34 (GMT) |
---|---|---|
committer | Stefan Radomski <github@mintwerk.de> | 2017-07-19 14:41:34 (GMT) |
commit | aa341b878e6d4a2be8890ca5f890e46b87cf2d7d (patch) | |
tree | f35363f7ca5be90f5a4ca1d93210e96698f89d59 /src/uscxml/interpreter/BasicContentExecutor.cpp | |
parent | 9db80409b3ca048c4b404a43d2c224f374c0090a (diff) | |
download | uscxml-aa341b878e6d4a2be8890ca5f890e46b87cf2d7d.zip uscxml-aa341b878e6d4a2be8890ca5f890e46b87cf2d7d.tar.gz uscxml-aa341b878e6d4a2be8890ca5f890e46b87cf2d7d.tar.bz2 |
Beautified code
Diffstat (limited to 'src/uscxml/interpreter/BasicContentExecutor.cpp')
-rw-r--r-- | src/uscxml/interpreter/BasicContentExecutor.cpp | 160 |
1 files changed, 80 insertions, 80 deletions
diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index 9ea2b6a..87c2180 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -593,89 +593,89 @@ void BasicContentExecutor::processParams(std::multimap<std::string, Data>& param paramMap.insert(make_pair(name, d)); } } - + Data BasicContentExecutor::elementAsData(XERCESC_NS::DOMElement* element, bool asExpression) { - // element with expr - if (HAS_ATTR(element, kXMLCharExpr)) { - std::string expr = ATTR(element, kXMLCharExpr); - if (_callbacks->isLegalDataValue(expr)) { - return Data(expr, Data::INTERPRETED); - } else { - ERROR_EXECUTION_THROW2("Expression '" + expr + "' is not a legal data value", element); - } - } - - // element with external src - this ought to behave just as with child nodes below - if (HAS_ATTR(element, kXMLCharSource)) { - - // remove any old child elements - while(element->getFirstElementChild() != NULL) { - element->removeChild(element->getFirstElementChild()); - } - - std::string src = ATTR(element, kXMLCharSource); - URL url(ATTR(element, kXMLCharSource)); - if (!url.isAbsolute()) { - url = URL::resolve(url, _callbacks->getBaseURL()); - } - std::string content = url.getInContent(); - - // append as XML? - try { - std::unique_ptr<XERCESC_NS::XercesDOMParser> parser(new XERCESC_NS::XercesDOMParser()); - parser->setValidationScheme(XERCESC_NS::XercesDOMParser::Val_Always); - parser->setDoNamespaces(true); - parser->useScanner(XERCESC_NS::XMLUni::fgWFXMLScanner); - - std::unique_ptr<XERCESC_NS::ErrorHandler> errHandler(new XERCESC_NS::HandlerBase()); - parser->setErrorHandler(errHandler.get()); - - XERCESC_NS::MemBufInputSource is((XMLByte*)content.c_str(), content.size(), X("fake")); - is.setPublicId(X(url)); - - parser->parse(is); - XERCESC_NS::DOMNode* newNode = element->getOwnerDocument()->importNode(parser->getDocument()->getDocumentElement(), true); - - // we need to save the DOM somewhere .. Data::adoptedDoc was not good enough - element->appendChild(newNode); - goto SOURCE_APPEND_DONE; - } catch (...) { - } - - // append as text (are we leaking?) - XERCESC_NS::DOMText* textNode = element->getOwnerDocument()->createTextNode(X(content)); - element->appendChild(textNode); - } + // element with expr + if (HAS_ATTR(element, kXMLCharExpr)) { + std::string expr = ATTR(element, kXMLCharExpr); + if (_callbacks->isLegalDataValue(expr)) { + return Data(expr, Data::INTERPRETED); + } else { + ERROR_EXECUTION_THROW2("Expression '" + expr + "' is not a legal data value", element); + } + } + + // element with external src - this ought to behave just as with child nodes below + if (HAS_ATTR(element, kXMLCharSource)) { + + // remove any old child elements + while(element->getFirstElementChild() != NULL) { + element->removeChild(element->getFirstElementChild()); + } + + std::string src = ATTR(element, kXMLCharSource); + URL url(ATTR(element, kXMLCharSource)); + if (!url.isAbsolute()) { + url = URL::resolve(url, _callbacks->getBaseURL()); + } + std::string content = url.getInContent(); + + // append as XML? + try { + std::unique_ptr<XERCESC_NS::XercesDOMParser> parser(new XERCESC_NS::XercesDOMParser()); + parser->setValidationScheme(XERCESC_NS::XercesDOMParser::Val_Always); + parser->setDoNamespaces(true); + parser->useScanner(XERCESC_NS::XMLUni::fgWFXMLScanner); + + std::unique_ptr<XERCESC_NS::ErrorHandler> errHandler(new XERCESC_NS::HandlerBase()); + parser->setErrorHandler(errHandler.get()); + + XERCESC_NS::MemBufInputSource is((XMLByte*)content.c_str(), content.size(), X("fake")); + is.setPublicId(X(url)); + + parser->parse(is); + XERCESC_NS::DOMNode* newNode = element->getOwnerDocument()->importNode(parser->getDocument()->getDocumentElement(), true); + + // we need to save the DOM somewhere .. Data::adoptedDoc was not good enough + element->appendChild(newNode); + goto SOURCE_APPEND_DONE; + } catch (...) { + } + + // append as text (are we leaking?) + XERCESC_NS::DOMText* textNode = element->getOwnerDocument()->createTextNode(X(content)); + element->appendChild(textNode); + } SOURCE_APPEND_DONE: - if (element->hasChildNodes()) { - // XML elements e.g. for content with invoke - std::list<DOMNode*> elementChildren = DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, element); - if (elementChildren.size() > 0) { - // always return parent element, even with a single child node - return Data(static_cast<DOMNode*>(element)); - } - - // expression in text element - std::list<DOMNode*> textChildren = DOMUtils::filterChildType(DOMNode::TEXT_NODE, element); - if (textChildren.size() > 0) { - std::stringstream contentSS; - for (auto textIter = textChildren.begin(); textIter != textChildren.end(); textIter++) { - contentSS << X((*textIter)->getNodeValue()); - } - - try { - Data d = _callbacks->getAsData(contentSS.str()); - if (!d.empty()) - return d; - } catch(...) {} - - // anything else is considered verbatim - space normalize? - return Data(spaceNormalize(contentSS.str()), Data::VERBATIM); - } - } - - return Data(); + if (element->hasChildNodes()) { + // XML elements e.g. for content with invoke + std::list<DOMNode*> elementChildren = DOMUtils::filterChildType(DOMNode::ELEMENT_NODE, element); + if (elementChildren.size() > 0) { + // always return parent element, even with a single child node + return Data(static_cast<DOMNode*>(element)); + } + + // expression in text element + std::list<DOMNode*> textChildren = DOMUtils::filterChildType(DOMNode::TEXT_NODE, element); + if (textChildren.size() > 0) { + std::stringstream contentSS; + for (auto textIter = textChildren.begin(); textIter != textChildren.end(); textIter++) { + contentSS << X((*textIter)->getNodeValue()); + } + + try { + Data d = _callbacks->getAsData(contentSS.str()); + if (!d.empty()) + return d; + } catch(...) {} + + // anything else is considered verbatim - space normalize? + return Data(spaceNormalize(contentSS.str()), Data::VERBATIM); + } + } + + return Data(); } } |