From 47b3bb0882a838ba794f105f3dc93ec45f5e1727 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Fri, 9 May 2014 21:29:39 +0200 Subject: Added default target file and path parameters * the transformation is now provided with default parameters such as the target file and its parent directory * added appropriate test case ** default_params * test frontend now doesn't provide a "test" parameter anymore * extracted parameter setter into separate member method "setParameters" of TransformationFacade --- src/transformation_facade.cc | 28 ++++++++++++++++++++-------- src/transformation_facade.h | 2 ++ test.cc | 5 +---- test/default_params/reference.xml | 7 +++++++ test/default_params/transformation.xsl | 32 ++++++++++++++++++++++++++++++++ test/read_directory/reference.xml | 1 + 6 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 test/default_params/reference.xml create mode 100644 test/default_params/transformation.xsl diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc index 91d761d..b411b38 100644 --- a/src/transformation_facade.cc +++ b/src/transformation_facade.cc @@ -3,6 +3,8 @@ #include #include +#include "boost/filesystem.hpp" + #include #include @@ -24,11 +26,19 @@ TransformationFacade::~TransformationFacade() { } int TransformationFacade::generate(const std::string& target) { + const boost::filesystem::path targetFilePath( + boost::filesystem::absolute(target) + ); + + this->setParameters({ + { "target-file", targetFilePath.filename().string() }, + { "parent-directory", targetFilePath.parent_path().filename().string() } + }); + std::stringstream emptyStream(""); xalan::XSLTInputSource inputSource(emptyStream); xalan::XSLTResultTarget outputTarget(target.data()); - const int resultCode = this->transformer_.transform( inputSource, this->transformation_, @@ -39,6 +49,8 @@ int TransformationFacade::generate(const std::string& target) { std::cerr << this->transformer_.getLastError() << std::endl; } + this->transformer_.clearStylesheetParams(); + return resultCode; } @@ -46,18 +58,18 @@ int TransformationFacade::generate( const std::string& target, const parameter_map& parameters ) { + this->setParameters(parameters); + + return this->generate(target); +} + +void TransformationFacade::setParameters(const parameter_map& parameters) { for ( auto&& parameter : parameters ) { this->transformer_.setStylesheetParam( parameter.first.data(), - parameter.second.data() + std::string("'" + parameter.second + "'").data() ); } - - const int resultCode = this->generate(target); - - this->transformer_.clearStylesheetParams(); - - return resultCode; } } diff --git a/src/transformation_facade.h b/src/transformation_facade.h index 833016d..4dc087b 100644 --- a/src/transformation_facade.h +++ b/src/transformation_facade.h @@ -25,6 +25,8 @@ class TransformationFacade { xalan::XalanTransformer transformer_; + void setParameters(const parameter_map&); + }; } diff --git a/test.cc b/test.cc index 9b978da..68b8d92 100644 --- a/test.cc +++ b/test.cc @@ -40,10 +40,7 @@ int main(int ac, char** av) { ); return transformation.generate( - variables["target"].as(), - { - {"test", "42"} - } + variables["target"].as() ); } else { std::cout << optionDescription << std::endl; diff --git a/test/default_params/reference.xml b/test/default_params/reference.xml new file mode 100644 index 0000000..fcdbacf --- /dev/null +++ b/test/default_params/reference.xml @@ -0,0 +1,7 @@ + + + +actual.xml +default_params + + diff --git a/test/default_params/transformation.xsl b/test/default_params/transformation.xsl new file mode 100644 index 0000000..1bbddef --- /dev/null +++ b/test/default_params/transformation.xsl @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/read_directory/reference.xml b/test/read_directory/reference.xml index 7e83460..76fb84f 100644 --- a/test/read_directory/reference.xml +++ b/test/read_directory/reference.xml @@ -5,5 +5,6 @@ read_xml_file common read_file +default_params -- cgit v1.2.3