From 085935ddd577b0c65b4330318b5ba20492d93126 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sat, 24 May 2014 13:59:42 +0200 Subject: Implemented ResultNodeFacade as a DOM node construction helper * wraps result node construction and appends it to root node on destruction * offers a simpler interface for common node construction patterns * simplifies result node construction in all external function implementations ** most noticeable in FunctionReadDirectory * expanded FunctionReadDirectory result nodes by name, extension, and full-path nodes --- src/support/dom/result_node_facade.cc | 61 +++++++++++++++++++++++++++++++++++ src/support/dom/result_node_facade.h | 35 ++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/support/dom/result_node_facade.cc create mode 100644 src/support/dom/result_node_facade.h (limited to 'src/support/dom') diff --git a/src/support/dom/result_node_facade.cc b/src/support/dom/result_node_facade.cc new file mode 100644 index 0000000..597448b --- /dev/null +++ b/src/support/dom/result_node_facade.cc @@ -0,0 +1,61 @@ +#include "result_node_facade.h" + +#include + +#include "support/xerces_string_guard.h" + +namespace InputXSLT { + +ResultNodeFacade::ResultNodeFacade( + xercesc::DOMDocument* document, + xercesc::DOMNode* node, + const std::string& name +): + dom_document_(document), + result_node_( + dom_document_->createElement(*XercesStringGuard(name)) + ), + root_node_(node) { } + +ResultNodeFacade::~ResultNodeFacade() { + this->root_node_->appendChild(this->result_node_); +} + +void ResultNodeFacade::setAttribute( + const std::string& name, + const std::string& value +) { + this->result_node_->setAttribute( + *XercesStringGuard(name), + *XercesStringGuard(value) + ); +} + +void ResultNodeFacade::setValueNode( + const std::string& name, + const std::string& value +) { + xercesc::DOMElement* const nameNode( + this->dom_document_->createElement(*XercesStringGuard(name)) + ); + + xercesc::DOMText* const valueNode( + this->dom_document_->createTextNode(*XercesStringGuard(value)) + ); + + nameNode->appendChild(valueNode); + + this->result_node_->appendChild(nameNode); +} + +void ResultNodeFacade::setContent(const std::string& content) { + this->result_node_->appendChild( + this->dom_document_->createTextNode(*XercesStringGuard(content)) + ); +} + +void ResultNodeFacade::setContent(xercesc::DOMNode* node) { + this->result_node_->appendChild(node); +} + +} diff --git a/src/support/dom/result_node_facade.h b/src/support/dom/result_node_facade.h new file mode 100644 index 0000000..ccdd850 --- /dev/null +++ b/src/support/dom/result_node_facade.h @@ -0,0 +1,35 @@ +#ifndef INPUTXSLT_SRC_SUPPORT_RESULT_NODE_FACADE_H_ +#define INPUTXSLT_SRC_SUPPORT_RESULT_NODE_FACADE_H_ + +#include +#include +#include + +#include + +namespace InputXSLT { + +class ResultNodeFacade { + public: + ResultNodeFacade( + xercesc::DOMDocument*, + xercesc::DOMNode*, + const std::string& + ); + ~ResultNodeFacade(); + + void setAttribute(const std::string&, const std::string&); + void setValueNode(const std::string&, const std::string&); + void setContent(const std::string&); + void setContent(xercesc::DOMNode*); + + private: + xercesc::DOMDocument* const dom_document_; + xercesc::DOMElement* const result_node_; + xercesc::DOMNode* const root_node_; + +}; + +} + +#endif // INPUTXSLT_SRC_SUPPORT_RESULT_NODE_FACADE_H_ -- cgit v1.2.3