diff options
author | Adrian Kummerlaender | 2014-07-05 21:55:48 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2014-07-05 21:55:48 +0200 |
commit | a02dce3c8e6086acbfe9c57c3ee4bb386bfbebc2 (patch) | |
tree | 669ad392772fcc9ab4eaa9e1a410156d6d4cc616 /ixslt.cc | |
parent | f05e742b88e3ebf7401c252332022f1a2f7eb8b0 (diff) | |
download | InputXSLT-a02dce3c8e6086acbfe9c57c3ee4bb386bfbebc2.tar InputXSLT-a02dce3c8e6086acbfe9c57c3ee4bb386bfbebc2.tar.gz InputXSLT-a02dce3c8e6086acbfe9c57c3ee4bb386bfbebc2.tar.bz2 InputXSLT-a02dce3c8e6086acbfe9c57c3ee4bb386bfbebc2.tar.lz InputXSLT-a02dce3c8e6086acbfe9c57c3ee4bb386bfbebc2.tar.xz InputXSLT-a02dce3c8e6086acbfe9c57c3ee4bb386bfbebc2.tar.zst InputXSLT-a02dce3c8e6086acbfe9c57c3ee4bb386bfbebc2.zip |
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<char>&" 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
Diffstat (limited to 'ixslt.cc')
-rw-r--r-- | ixslt.cc | 115 |
1 files changed, 74 insertions, 41 deletions
@@ -1,3 +1,7 @@ +#include <xalanc/PlatformSupport/XalanOutputStreamPrintWriter.hpp> +#include <xalanc/PlatformSupport/XalanStdOutputStream.hpp> +#include <xalanc/XMLSupport/FormatterToXML.hpp> + #include "boost/optional.hpp" #include "boost/program_options.hpp" #include <boost/filesystem/fstream.hpp> @@ -7,16 +11,18 @@ #include <iostream> #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 <typename... Arguments> +bool generate( + InputXSLT::IncludeEntityResolver* resolver, + std::basic_ostream<char>& 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>(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<std::string> 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<std::string>().data(), - variables["transformation"].as<std::string>().data(), - plattform.getEntityResolver() - ); - } else { - transformation = InputXSLT::TransformationFacade::try_create( - handleErrors, - variables["transformation"].as<std::string>().data(), - plattform.getEntityResolver() - ); - } - if ( transformation ) { - WarningGuard guard(transformation.get()); + if ( variables.count("target") ) { + boost::filesystem::ofstream file( + variables["target"].as<std::string>() + ); - try { - if ( variables.count("target") ) { - boost::filesystem::ofstream file( - variables["target"].as<std::string>() + if ( file.is_open() ) { + if ( variables.count("input") ) { + return generate( + plattform.getEntityResolver(), + file, + variables["input"].as<std::string>().data(), + variables["transformation"].as<std::string>().data() ); - - if ( file.is_open() ) { - transformation->generate(file); - } else { - return false; - } } else { - transformation->generate(std::cout); + return generate( + plattform.getEntityResolver(), + file, + variables["transformation"].as<std::string>().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<std::string>().data(), + variables["transformation"].as<std::string>().data() + ); + } else { + return generate( + plattform.getEntityResolver(), + std::cout, + variables["transformation"].as<std::string>().data() + ); + } } +} - return false; } int main(int argc, char** argv) { |