From 79d3e2bdfd441d6eba2f22af78d5bea5e488daf1 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Fri, 30 May 2014 22:19:32 +0200 Subject: Rewrote error handling based on exceptions * ErrorHandler is replaced by ErrorCapacitor ** temporarily registers itself as both the ProblemListener and ErrorHandler of a given XalanTransformer instance ** deregisters itself on destruction ** collects all problems and errors during its lifetime inside a internal std::vector instance ** if this instance is not empty it is thrown contained within a ErrorCapacitor::exception by the member method ErrorCapacitor::discharge * this enables using the same code for handling transformation compilation and generation errors and problems * updated test frontend accordingly --- src/transformation_facade.cc | 49 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'src/transformation_facade.cc') diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc index 8b9e1a2..f415cd8 100644 --- a/src/transformation_facade.cc +++ b/src/transformation_facade.cc @@ -14,16 +14,17 @@ TransformationFacade::TransformationFacade( IncludeEntityResolver* resolver ): transformation_{}, - transformer_(), - error_handler_() { + transformer_() { this->transformer_.setEntityResolver(resolver); - this->transformer_.setErrorHandler(&this->error_handler_); - this->transformer_.setProblemListener(&this->error_handler_); + + ErrorCapacitor errorCapacitor(&this->transformer_); this->transformer_.compileStylesheet( xalan::XSLTInputSource(transformation.data()), this->transformation_ ); + + errorCapacitor.discharge(); } TransformationFacade::~TransformationFacade() { @@ -32,10 +33,10 @@ TransformationFacade::~TransformationFacade() { ); } -auto TransformationFacade::generate( +void TransformationFacade::generate( const std::string& targetPath, StylesheetParameterGuard& parameters -) -> return_type { +) { const boost::filesystem::path targetPathHelper( boost::filesystem::absolute(targetPath) ); @@ -47,38 +48,38 @@ auto TransformationFacade::generate( "parent-directory", targetPathHelper.parent_path().filename().string() ); - return this->generate( + this->generate( xalan::XSLTResultTarget(targetPath.data()), parameters ); } -auto TransformationFacade::generate( +void TransformationFacade::generate( std::basic_ostream& targetStream, StylesheetParameterGuard& parameters -) -> return_type { - return this->generate( +) { + this->generate( xalan::XSLTResultTarget(targetStream), parameters ); } -auto TransformationFacade::generate( +void TransformationFacade::generate( xalan::XSLTResultTarget&& outputTarget, StylesheetParameterGuard& -) -> return_type { - if ( this->transformation_ != nullptr ) { - std::stringstream emptyStream(""); - xalan::XSLTInputSource inputSource(emptyStream); - - this->transformer_.transform( - inputSource, - this->transformation_, - outputTarget - ); - } - - return this->error_handler_.getCachedErrors(); +) { + ErrorCapacitor errorCapacitor(&this->transformer_); + + std::stringstream emptyStream(""); + xalan::XSLTInputSource inputSource(emptyStream); + + this->transformer_.transform( + inputSource, + this->transformation_, + outputTarget + ); + + errorCapacitor.discharge(); } } -- cgit v1.2.3