From 5e7b8b9558fec9d58716c46666d62a055a39f0be Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 6 Sep 2014 14:23:17 +0200 Subject: Changed system-ID of primary transformation to working directory * this change was needed so that one is able to apply transformations located in e.g. a central directory as if they where located in the working directory ** otherwise e.g. the BuildXSLT transformation would have to be copied into every project that requires it * implemented StreamInputSource wrapper for boost::filesystem::ifstream and xalan::XSLTInputSource ** this is needed because the boost::filesystem::ifstream instance has to exist as long as the xalan::XSLTInputSource it is bound to ** i.e. a simple helper function to instantiate the source and set the working directory would have not been sufficient --- ixslt.cc | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/ixslt.cc b/ixslt.cc index ff5de25..683effd 100644 --- a/ixslt.cc +++ b/ixslt.cc @@ -12,6 +12,7 @@ #include "platform_guard.h" #include "transformer_facade.h" +#include "support/xerces_string_guard.h" namespace { @@ -35,6 +36,31 @@ class WarningGuard { }; +class StreamInputSource { + public: + StreamInputSource( + const boost::filesystem::path& actualPath, + const boost::filesystem::path& contextPath + ): + file_(actualPath), + source_(file_) { + this->source_.setSystemId( + *InputXSLT::XercesStringGuard( + "file://" + contextPath.string() + ) + ); + } + + xalan::XSLTInputSource& operator*() { + return this->source_; + } + + private: + boost::filesystem::ifstream file_; + xalan::XSLTInputSource source_; + +}; + boost::optional input( int argc, char** argv @@ -133,6 +159,11 @@ bool process(const boost::program_options::variables_map& variables) { InputXSLT::PlatformGuard platform(includePath); + StreamInputSource transformationSource( + variables["transformation"].as(), + boost::filesystem::current_path() + ); + if ( variables.count("target") ) { boost::filesystem::ofstream file( variables["target"].as() @@ -144,13 +175,13 @@ bool process(const boost::program_options::variables_map& variables) { platform.getEntityResolver(), file, variables["input"].as().data(), - variables["transformation"].as().data() + *transformationSource ); } else { return generate( platform.getEntityResolver(), file, - variables["transformation"].as().data() + *transformationSource ); } } else { @@ -162,13 +193,13 @@ bool process(const boost::program_options::variables_map& variables) { platform.getEntityResolver(), std::cout, variables["input"].as().data(), - variables["transformation"].as().data() + *transformationSource ); } else { return generate( platform.getEntityResolver(), std::cout, - variables["transformation"].as().data() + *transformationSource ); } } -- cgit v1.2.3