From f05e742b88e3ebf7401c252332022f1a2f7eb8b0 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Fri, 4 Jul 2014 22:41:17 +0200 Subject: Changed FunctionTransform result type to node-set * using xalan::FormatterToXercesDOM internally ** this required changes to the TransformationFacade::generate member method overloads * TransformationFacade::generate now accepts references to xalan::FormatterListener instances ** "generate(std::basic_ostream&..." instantiates a xalan::FormatterToXML and passes it to the actual generate member method * changed ResultNodeFacade's "getNode" method into a "getResultElement" method ** xalan::FormatterToXercesDOM requires a xercesc::DOMElement instance instead of the previously available xercesc::DOMNode instance ** changed FunctionReadDirectory accordingly * adapted FunctionTransform test case accordingly --- src/function/read_directory.cc | 2 +- src/function/transform.cc | 19 +++++++++--------- src/support/dom/result_node_facade.cc | 2 +- src/support/dom/result_node_facade.h | 2 +- src/transformation_facade.cc | 38 ++++++++++++++++++++--------------- src/transformation_facade.h | 9 +++------ 6 files changed, 37 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc index 884963e..d5357e8 100644 --- a/src/function/read_directory.cc +++ b/src/function/read_directory.cc @@ -29,7 +29,7 @@ xercesc::DOMDocument* FunctionReadDirectory::constructDocument( if ( boost::filesystem::is_directory(directoryPath) ) { result.setAttribute("result", "success"); - xercesc::DOMNode* const resultNode = result.getNode(); + xercesc::DOMNode* const resultNode = result.getResultElement(); FilesystemContext::iterate( directoryPath, diff --git a/src/function/transform.cc b/src/function/transform.cc index bc71125..1d22399 100644 --- a/src/function/transform.cc +++ b/src/function/transform.cc @@ -1,11 +1,11 @@ #include "transform.h" +#include + #include #include #include -#include - #include "transformation_facade.h" #include "support/xerces_string_guard.h" #include "support/dom/result_node_facade.h" @@ -43,11 +43,11 @@ xercesc::DOMDocument* FunctionTransform::constructDocument( ) ); - xercesc::DOMNode* const rootNode( + xercesc::DOMElement* const rootElement( domDocument->getDocumentElement() ); - ResultNodeFacade result(domDocument, rootNode, "transformation"); + ResultNodeFacade result(domDocument, rootElement, "transformation"); if ( auto transformation = TransformationFacade::try_create( handleErrors(result), @@ -56,17 +56,16 @@ xercesc::DOMDocument* FunctionTransform::constructDocument( this->include_resolver_ ) ) { try { - std::stringstream targetStream; + xalan::FormatterToXercesDOM formatter( + domDocument, + result.getResultElement() + ); transformation->generate( - targetStream, + formatter, parameterObject ); - result.setContent( - targetStream.str() - ); - result.setAttribute("result", "success"); } catch (const ErrorCapacitor::exception& exception) { diff --git a/src/support/dom/result_node_facade.cc b/src/support/dom/result_node_facade.cc index eeb2cc6..570b4e1 100644 --- a/src/support/dom/result_node_facade.cc +++ b/src/support/dom/result_node_facade.cc @@ -22,7 +22,7 @@ ResultNodeFacade::~ResultNodeFacade() { this->root_node_->appendChild(this->result_node_); } -xercesc::DOMNode* ResultNodeFacade::getNode() { +xercesc::DOMElement* ResultNodeFacade::getResultElement() { return this->result_node_; } diff --git a/src/support/dom/result_node_facade.h b/src/support/dom/result_node_facade.h index bf73582..c7e831e 100644 --- a/src/support/dom/result_node_facade.h +++ b/src/support/dom/result_node_facade.h @@ -18,7 +18,7 @@ class ResultNodeFacade { ); ~ResultNodeFacade(); - xercesc::DOMNode* getNode(); + xercesc::DOMElement* getResultElement(); void setAttribute(const std::string&, const std::string&); void setValueNode(const std::string&, const std::string&); diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc index 9d248b8..4017cd0 100644 --- a/src/transformation_facade.cc +++ b/src/transformation_facade.cc @@ -2,6 +2,9 @@ #include #include +#include +#include +#include #include "support/xerces_string_guard.h" @@ -66,42 +69,45 @@ WarningCapacitor::warning_cache_ptr TransformationFacade::getCachedWarnings() { return this->warning_capacitor_.discharge(); } -void TransformationFacade::generate(std::basic_ostream& targetStream) { +void TransformationFacade::generate( + std::basic_ostream& targetStream, + const xalan::XObjectPtr& parameter +) { StylesheetParameterGuard guard(this->transformer_); + guard.set("parameters", parameter); - this->generate(targetStream, guard); + this->generate(targetStream); } -void TransformationFacade::generate( - std::basic_ostream& targetStream, - const StylesheetParameterGuard::map& parameters -) { - StylesheetParameterGuard guard(this->transformer_, parameters); +void TransformationFacade::generate(std::basic_ostream& targetStream) { + StylesheetParameterGuard guard(this->transformer_); + + xalan::XalanStdOutputStream outputStream(targetStream); + xalan::XalanOutputStreamPrintWriter outputWriter(outputStream); - this->generate(targetStream, guard); + xalan::FormatterToXML formatter(outputWriter); + formatter.setDoIndent(true); + + this->generate(formatter); } void TransformationFacade::generate( - std::basic_ostream& targetStream, + xalan::FormatterListener& formatter, const xalan::XObjectPtr& parameter ) { StylesheetParameterGuard guard(this->transformer_); guard.set("parameters", parameter); - this->generate(targetStream, guard); + this->generate(formatter); } - -void TransformationFacade::generate( - std::basic_ostream& targetStream, - StylesheetParameterGuard& -) { +void TransformationFacade::generate(xalan::FormatterListener& target) { ErrorCapacitor errorCapacitor(&this->error_multiplexer_); this->transformer_.transform( *(this->input_), this->transformation_, - targetStream + target ); errorCapacitor.discharge(); diff --git a/src/transformation_facade.h b/src/transformation_facade.h index ca57de4..e4cbc10 100644 --- a/src/transformation_facade.h +++ b/src/transformation_facade.h @@ -39,9 +39,11 @@ class TransformationFacade { ); void generate(std::basic_ostream&); - void generate(std::basic_ostream&, const StylesheetParameterGuard::map&); void generate(std::basic_ostream&, const xalan::XObjectPtr&); + void generate(xalan::FormatterListener&); + void generate(xalan::FormatterListener&, const xalan::XObjectPtr&); + WarningCapacitor::warning_cache_ptr getCachedWarnings(); private: @@ -52,11 +54,6 @@ class TransformationFacade { ErrorMultiplexer error_multiplexer_; WarningCapacitor warning_capacitor_; - void generate( - std::basic_ostream&, - StylesheetParameterGuard& - ); - }; template -- cgit v1.2.3