aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-09 21:29:39 +0200
committerAdrian Kummerländer2014-05-09 21:29:39 +0200
commit47b3bb0882a838ba794f105f3dc93ec45f5e1727 (patch)
tree170a570d09d791932e7c7d0e4b3ceb5e5c40d586 /src
parente83bbb457c98a0b77ca04e2832d7d0601912acd7 (diff)
downloadInputXSLT-47b3bb0882a838ba794f105f3dc93ec45f5e1727.tar
InputXSLT-47b3bb0882a838ba794f105f3dc93ec45f5e1727.tar.gz
InputXSLT-47b3bb0882a838ba794f105f3dc93ec45f5e1727.tar.bz2
InputXSLT-47b3bb0882a838ba794f105f3dc93ec45f5e1727.tar.lz
InputXSLT-47b3bb0882a838ba794f105f3dc93ec45f5e1727.tar.xz
InputXSLT-47b3bb0882a838ba794f105f3dc93ec45f5e1727.tar.zst
InputXSLT-47b3bb0882a838ba794f105f3dc93ec45f5e1727.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/transformation_facade.cc28
-rw-r--r--src/transformation_facade.h2
2 files changed, 22 insertions, 8 deletions
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 <xalanc/XSLT/XSLTInputSource.hpp>
#include <xalanc/XalanTransformer/XalanCompiledStylesheet.hpp>
+#include "boost/filesystem.hpp"
+
#include <sstream>
#include <iostream>
@@ -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("<dummy/>");
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&);
+
};
}