From 716958c6acb77f4f63cc6f99d741fe0a901a25ba Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 8 Jul 2014 14:06:47 +0200 Subject: Added ResultNodeFacade constructor overload for root nodes * the common use case of ResultNodeFacade inside external function implementations is managing the result root node ** this root node can be fetched through the xercesc::DOMDocument instance ** the new alias overload automatically fetches the root node pointer and as such doesn't require a root node parameter * changed external function implementations accordingly --- src/function/external_text_formatter.cc | 6 +----- src/function/read_directory.cc | 6 +----- src/function/read_file.cc | 6 +----- src/function/transform.cc | 6 +----- src/function/write_file.cc | 6 +----- src/support/dom/result_node_facade.cc | 14 ++++++++++++-- src/support/dom/result_node_facade.h | 2 ++ 7 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/function/external_text_formatter.cc b/src/function/external_text_formatter.cc index a86c71b..de8a296 100644 --- a/src/function/external_text_formatter.cc +++ b/src/function/external_text_formatter.cc @@ -47,10 +47,6 @@ DomDocumentCache::document_ptr FunctionExternalTextFormatter::constructDocument( DomDocumentCache::createDocument() ); - xercesc::DOMNode* const rootNode( - domDocument->getDocumentElement() - ); - boost::process::context context; context.stdout_behavior = boost::process::capture_stream(); context.stdin_behavior = boost::process::capture_stream(); @@ -71,7 +67,7 @@ DomDocumentCache::document_ptr FunctionExternalTextFormatter::constructDocument( boost::process::status status = formatterProcess.wait(); - ResultNodeFacade result(domDocument.get(), rootNode, "output"); + ResultNodeFacade result(domDocument.get(), "output"); result.setAttribute("formatter", formatterPath.filename().string()); result.setAttribute("code", std::to_string(status.exit_status())); diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc index ad82217..cbc64e0 100644 --- a/src/function/read_directory.cc +++ b/src/function/read_directory.cc @@ -11,11 +11,7 @@ DomDocumentCache::document_ptr FunctionReadDirectory::constructDocument( DomDocumentCache::createDocument() ); - xercesc::DOMNode* const rootNode( - domDocument->getDocumentElement() - ); - - ResultNodeFacade result(domDocument.get(), rootNode, "directory"); + ResultNodeFacade result(domDocument.get(), "directory"); result.setAttribute("path", directoryPath.string()); if ( boost::filesystem::is_directory(directoryPath) ) { diff --git a/src/function/read_file.cc b/src/function/read_file.cc index cb1e57f..dcd32b7 100644 --- a/src/function/read_file.cc +++ b/src/function/read_file.cc @@ -65,11 +65,7 @@ DomDocumentCache::document_ptr FunctionReadFile::constructDocument( DomDocumentCache::createDocument() ); - xercesc::DOMNode* const rootNode( - domDocument->getDocumentElement() - ); - - ResultNodeFacade result(domDocument.get(), rootNode, "file"); + ResultNodeFacade result(domDocument.get(), "file"); result.setAttribute("path", filePath.string()); if ( boost::filesystem::is_regular_file(filePath) ) { diff --git a/src/function/transform.cc b/src/function/transform.cc index c97897e..d7aae94 100644 --- a/src/function/transform.cc +++ b/src/function/transform.cc @@ -34,11 +34,7 @@ DomDocumentCache::document_ptr FunctionTransform::constructDocument( DomDocumentCache::createDocument() ); - xercesc::DOMElement* const rootElement( - domDocument->getDocumentElement() - ); - - ResultNodeFacade result(domDocument.get(), rootElement, "transformation"); + ResultNodeFacade result(domDocument.get(), "transformation"); TransformerFacade transformer(this->include_resolver_); try { diff --git a/src/function/write_file.cc b/src/function/write_file.cc index 872160b..0ad68bf 100644 --- a/src/function/write_file.cc +++ b/src/function/write_file.cc @@ -65,11 +65,7 @@ DomDocumentCache::document_ptr FunctionWriteFile::constructDocument( DomDocumentCache::createDocument() ); - xercesc::DOMNode* const rootNode( - domDocument->getDocumentElement() - ); - - ResultNodeFacade result(domDocument.get(), rootNode, "file"); + ResultNodeFacade result(domDocument.get(), "file"); result.setAttribute("path", filePath.string()); if ( contentNode != nullptr ) { diff --git a/src/support/dom/result_node_facade.cc b/src/support/dom/result_node_facade.cc index 570b4e1..c5829c5 100644 --- a/src/support/dom/result_node_facade.cc +++ b/src/support/dom/result_node_facade.cc @@ -9,8 +9,18 @@ namespace InputXSLT { ResultNodeFacade::ResultNodeFacade( xercesc::DOMDocument* document, - xercesc::DOMNode* node, - const std::string& name + const std::string& name +): + ResultNodeFacade( + document, + document->getDocumentElement(), + name + ) { } + +ResultNodeFacade::ResultNodeFacade( + xercesc::DOMDocument* document, + xercesc::DOMNode* node, + const std::string& name ): dom_document_(document), result_node_( diff --git a/src/support/dom/result_node_facade.h b/src/support/dom/result_node_facade.h index c7e831e..c743f92 100644 --- a/src/support/dom/result_node_facade.h +++ b/src/support/dom/result_node_facade.h @@ -11,11 +11,13 @@ namespace InputXSLT { class ResultNodeFacade { public: + ResultNodeFacade(xercesc::DOMDocument*, const std::string&); ResultNodeFacade( xercesc::DOMDocument*, xercesc::DOMNode*, const std::string& ); + ~ResultNodeFacade(); xercesc::DOMElement* getResultElement(); -- cgit v1.2.3