From e805000b1841691cd58930e80bd896a4f7611fd0 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Tue, 10 Jun 2014 22:27:24 +0200 Subject: Added input file support to ixslt * a single file may be passed to the XSLT processor as input ** the file is read once and stored within a xalan::XalanParsedSource to be reused by all calls to "TransformationFacade::generate" * added appropriate TranformationFacade constructor overload ** this new constructor overload which is taking a path to both the transformation and the input file is the main constructor *** the old constructor is now only a alias for this new constructor * adapted static "try_create" TransformationFacade factory method into variadic template factory method * added optional "--input" argument to ixslt ** expanded option handling accordingly --- src/transformation_facade.cc | 48 ++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'src/transformation_facade.cc') diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc index 3c94bdd..16872c7 100644 --- a/src/transformation_facade.cc +++ b/src/transformation_facade.cc @@ -9,27 +9,22 @@ namespace InputXSLT { -auto TransformationFacade::try_create( +TransformationFacade::TransformationFacade( const std::string& transformation, - IncludeEntityResolver* resolver, - const std::function& handleErrors -) -> ptr{ - try { - return ptr( - new InputXSLT::TransformationFacade(transformation, resolver) - ); - } - catch (const ErrorCapacitor::exception& exception) { - handleErrors(*exception); - - return ptr(); - } -} + IncludeEntityResolver* resolver +): + TransformationFacade( + std::string{}, + transformation, + resolver + ) { } TransformationFacade::TransformationFacade( + const std::string& input, const std::string& transformation, IncludeEntityResolver* resolver ): + input_{}, transformation_{}, transformer_(), error_multiplexer_(&transformer_), @@ -38,6 +33,20 @@ TransformationFacade::TransformationFacade( ErrorCapacitor errorCapacitor(&this->error_multiplexer_); + if ( input.empty() ) { + std::stringstream dummyStream(""); + + this->transformer_.parseSource( + xalan::XSLTInputSource(dummyStream), + this->input_ + ); + } else { + this->transformer_.parseSource( + xalan::XSLTInputSource(input.data()), + this->input_ + ); + } + this->transformer_.compileStylesheet( xalan::XSLTInputSource(transformation.data()), this->transformation_ @@ -47,6 +56,10 @@ TransformationFacade::TransformationFacade( } TransformationFacade::~TransformationFacade() { + this->transformer_.destroyParsedSource( + this->input_ + ); + this->transformer_.destroyStylesheet( this->transformation_ ); @@ -93,11 +106,8 @@ void TransformationFacade::generate( ) { ErrorCapacitor errorCapacitor(&this->error_multiplexer_); - std::stringstream emptyStream(""); - xalan::XSLTInputSource inputSource(emptyStream); - this->transformer_.transform( - inputSource, + *(this->input_), this->transformation_, outputTarget ); -- cgit v1.2.3