From a02dce3c8e6086acbfe9c57c3ee4bb386bfbebc2 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 5 Jul 2014 21:55:48 +0200 Subject: Revamped implementation to support FunctionTransform XalanNode input * FunctionTransform now accepts xalan::XalanNode base xalan::XSLTInputSource instances as input parameter ** such xalan::XSLTInputSource instances were already supported for the stylesheet parameter but not for the input parameter ** e.g. it is now possible to generate a DOM inside a transformation, pass the DOM into a embedded transformation as input, modifiy the output of that transformation, pass this modified DOM into another transformation and so on... you get the point * this required a revamp of TransformationFacade ** it is now a transformation independent wrapper for xalan::XalanTransformer *** as such is was renamed to TransformerFacade ** removed error catching template factory method "try_create" as it is not needed anymore ** "std::basic_ostream&" taking "generate" member method overloads were removed ** the set of "generate" member overloads was reduced to two methods accepting xalan::XSLTInputSource and xalan::FormatterListener as parameters * the core problem first documented in 299d0f6 was solved by transforming the input parameter into a xerces DOM and wrapping this DOM inside a xalan::XercesDOMWrapperParsedSource instance * serialization of the transformation result for file / std::cout output is now performed directly by the ixslt frontend * removed 'stylesheet parameter' parameter from FunctionTransform ** the functionality provided by this is easily replicated using the now possible DOM input parameter ** this was done to simplify the interface and reduce unnecessary feature duplication * updated FunctionTransform test case accordingly * added "generate" template function to ixslt frontend ** wraps TransformerFacade and manages ist input arguments ** handles serialization to stream * this commit marks a important milestone towards the goals defined in 741a70f --- ixslt.cc | 115 ++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 41 deletions(-) (limited to 'ixslt.cc') diff --git a/ixslt.cc b/ixslt.cc index abc7e1a..048f990 100644 --- a/ixslt.cc +++ b/ixslt.cc @@ -1,3 +1,7 @@ +#include +#include +#include + #include "boost/optional.hpp" #include "boost/program_options.hpp" #include @@ -7,16 +11,18 @@ #include #include "plattform_guard.h" -#include "transformation_facade.h" +#include "transformer_facade.h" + +namespace { class WarningGuard { public: - WarningGuard(InputXSLT::TransformationFacade* transformation): - transformation_(transformation) { }; + WarningGuard(InputXSLT::TransformerFacade* transformer): + transformer_(transformer) { }; ~WarningGuard() { InputXSLT::WarningCapacitor::warning_cache_ptr warnings( - this->transformation_->getCachedWarnings() + this->transformer_->getCachedWarnings() ); for ( auto&& warning : *warnings ) { @@ -25,7 +31,7 @@ class WarningGuard { }; private: - InputXSLT::TransformationFacade* const transformation_; + InputXSLT::TransformerFacade* const transformer_; }; @@ -88,6 +94,36 @@ void handleErrors(const InputXSLT::ErrorCapacitor::error_cache& errors) { } } +template +bool generate( + InputXSLT::IncludeEntityResolver* resolver, + std::basic_ostream& target, + Arguments&&... arguments +) { + InputXSLT::TransformerFacade transformer(resolver); + WarningGuard guard(&transformer); + + try { + xalan::XalanStdOutputStream output(target); + xalan::XalanOutputStreamPrintWriter writer(output); + xalan::FormatterToXML formatter(writer); + + formatter.setDoIndent(true); + + transformer.generate( + std::forward(arguments)..., + formatter + ); + + return true; + } + catch (const InputXSLT::ErrorCapacitor::exception& exception) { + handleErrors(*exception); + + return false; + } +} + bool process(const boost::program_options::variables_map& variables) { std::vector includePath; @@ -96,51 +132,48 @@ bool process(const boost::program_options::variables_map& variables) { }; InputXSLT::PlattformGuard plattform(includePath); - InputXSLT::TransformationFacade::ptr transformation{}; - - if ( variables.count("input") ) { - transformation = InputXSLT::TransformationFacade::try_create( - handleErrors, - variables["input"].as().data(), - variables["transformation"].as().data(), - plattform.getEntityResolver() - ); - } else { - transformation = InputXSLT::TransformationFacade::try_create( - handleErrors, - variables["transformation"].as().data(), - plattform.getEntityResolver() - ); - } - if ( transformation ) { - WarningGuard guard(transformation.get()); + if ( variables.count("target") ) { + boost::filesystem::ofstream file( + variables["target"].as() + ); - try { - if ( variables.count("target") ) { - boost::filesystem::ofstream file( - variables["target"].as() + if ( file.is_open() ) { + if ( variables.count("input") ) { + return generate( + plattform.getEntityResolver(), + file, + variables["input"].as().data(), + variables["transformation"].as().data() ); - - if ( file.is_open() ) { - transformation->generate(file); - } else { - return false; - } } else { - transformation->generate(std::cout); + return generate( + plattform.getEntityResolver(), + file, + variables["transformation"].as().data() + ); } - - return true; - } - catch (const InputXSLT::ErrorCapacitor::exception& exception) { - handleErrors(*exception); - + } else { return false; } + } else { + if ( variables.count("input") ) { + return generate( + plattform.getEntityResolver(), + std::cout, + variables["input"].as().data(), + variables["transformation"].as().data() + ); + } else { + return generate( + plattform.getEntityResolver(), + std::cout, + variables["transformation"].as().data() + ); + } } +} - return false; } int main(int argc, char** argv) { -- cgit v1.2.3