aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-10 15:51:34 +0200
committerAdrian Kummerländer2014-05-10 15:51:34 +0200
commiteb854e72efa780fd6ceb6e7457b6ac6429a54dad (patch)
treebb391243144037e7f5af139477813c8629124446
parent47b3bb0882a838ba794f105f3dc93ec45f5e1727 (diff)
downloadInputXSLT-eb854e72efa780fd6ceb6e7457b6ac6429a54dad.tar
InputXSLT-eb854e72efa780fd6ceb6e7457b6ac6429a54dad.tar.gz
InputXSLT-eb854e72efa780fd6ceb6e7457b6ac6429a54dad.tar.bz2
InputXSLT-eb854e72efa780fd6ceb6e7457b6ac6429a54dad.tar.lz
InputXSLT-eb854e72efa780fd6ceb6e7457b6ac6429a54dad.tar.xz
InputXSLT-eb854e72efa780fd6ceb6e7457b6ac6429a54dad.tar.zst
InputXSLT-eb854e72efa780fd6ceb6e7457b6ac6429a54dad.zip
Implemented StylesheetParameterGuard class
* removes responsibility for clearing parameters from the generate member methods * abstracts parameter escaping and setting and handles map conversion * marked actual generate member method as private and added StylesheetParameterGuard reference argument ** "frontend" generate member methods instantiate a StylesheetParameterGuard instance and pass it to the actual generate method ** this enables central default parameter definition while offering the possibility for custom parameters
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/support/stylesheet_parameter_guard.cc36
-rw-r--r--src/support/stylesheet_parameter_guard.h35
-rw-r--r--src/transformation_facade.cc48
-rw-r--r--src/transformation_facade.h13
5 files changed, 103 insertions, 30 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2171d0f..bb3e319 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,6 +28,7 @@ set(
src/function/read_xml_file.cc
src/function/read_directory.cc
src/support/filesystem_context.cc
+ src/support/stylesheet_parameter_guard.cc
src/support/dom/document_cache.cc
src/support/dom/document_cache_item.cc
)
diff --git a/src/support/stylesheet_parameter_guard.cc b/src/support/stylesheet_parameter_guard.cc
new file mode 100644
index 0000000..f82c2d5
--- /dev/null
+++ b/src/support/stylesheet_parameter_guard.cc
@@ -0,0 +1,36 @@
+#include "stylesheet_parameter_guard.h"
+
+namespace InputXSLT {
+
+StylesheetParameterGuard::StylesheetParameterGuard(
+ xalan::XalanTransformer& transformer
+): transformer_(transformer) { }
+
+StylesheetParameterGuard::StylesheetParameterGuard(
+ xalan::XalanTransformer& transformer,
+ const map& parameters
+): transformer_(transformer) {
+ this->set(parameters);
+}
+
+StylesheetParameterGuard::~StylesheetParameterGuard() {
+ this->transformer_.clearStylesheetParams();
+}
+
+void StylesheetParameterGuard::set(const map& parameters) {
+ for ( auto&& parameter : parameters ) {
+ this->set(parameter.first, parameter.second);
+ }
+}
+
+void StylesheetParameterGuard::set(
+ const std::string& key,
+ const std::string& value
+) {
+ this->transformer_.setStylesheetParam(
+ key.data(),
+ std::string("'" + value + "'").data()
+ );
+}
+
+}
diff --git a/src/support/stylesheet_parameter_guard.h b/src/support/stylesheet_parameter_guard.h
new file mode 100644
index 0000000..f0622ad
--- /dev/null
+++ b/src/support/stylesheet_parameter_guard.h
@@ -0,0 +1,35 @@
+#ifndef INPUTXSLT_SRC_SUPPORT_STYLESHEET_PARAMETER_GUARD_H_
+#define INPUTXSLT_SRC_SUPPORT_STYLESHEET_PARAMETER_GUARD_H_
+
+#include <xalanc/XalanTransformer/XalanTransformer.hpp>
+
+#include <string>
+#include <unordered_map>
+
+#include "common.h"
+
+namespace InputXSLT {
+
+class StylesheetParameterGuard {
+ public:
+ typedef std::unordered_map<std::string, std::string> map;
+
+ explicit StylesheetParameterGuard(xalan::XalanTransformer&);
+ StylesheetParameterGuard(
+ xalan::XalanTransformer&,
+ const map&
+ );
+
+ ~StylesheetParameterGuard();
+
+ void set(const map&);
+ void set(const std::string&, const std::string&);
+
+ private:
+ xalan::XalanTransformer& transformer_;
+
+};
+
+}
+
+#endif // INPUTXSLT_SRC_SUPPORT_STYLESHEET_PARAMETER_GUARD_H_
diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc
index b411b38..698cdb1 100644
--- a/src/transformation_facade.cc
+++ b/src/transformation_facade.cc
@@ -26,14 +26,34 @@ TransformationFacade::~TransformationFacade() {
}
int TransformationFacade::generate(const std::string& target) {
+ StylesheetParameterGuard guard(this->transformer_);
+
+ return this->generate(target, guard);
+}
+
+int TransformationFacade::generate(
+ const std::string& target,
+ const StylesheetParameterGuard::map& parameters
+) {
+ StylesheetParameterGuard guard(this->transformer_, parameters);
+
+ return this->generate(target, guard);
+}
+
+int TransformationFacade::generate(
+ const std::string& target,
+ StylesheetParameterGuard& parameters
+) {
const boost::filesystem::path targetFilePath(
boost::filesystem::absolute(target)
);
- this->setParameters({
- { "target-file", targetFilePath.filename().string() },
- { "parent-directory", targetFilePath.parent_path().filename().string() }
- });
+ parameters.set(
+ "target-file", targetFilePath.filename().string()
+ );
+ parameters.set(
+ "parent-directory", targetFilePath.parent_path().filename().string()
+ );
std::stringstream emptyStream("<dummy/>");
xalan::XSLTInputSource inputSource(emptyStream);
@@ -49,27 +69,7 @@ int TransformationFacade::generate(const std::string& target) {
std::cerr << this->transformer_.getLastError() << std::endl;
}
- this->transformer_.clearStylesheetParams();
-
return resultCode;
}
-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(),
- std::string("'" + parameter.second + "'").data()
- );
- }
-}
-
}
diff --git a/src/transformation_facade.h b/src/transformation_facade.h
index 4dc087b..3172daa 100644
--- a/src/transformation_facade.h
+++ b/src/transformation_facade.h
@@ -4,28 +4,29 @@
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <string>
-#include <unordered_map>
#include "common.h"
+#include "support/stylesheet_parameter_guard.h"
namespace InputXSLT {
class TransformationFacade {
public:
- typedef std::unordered_map<std::string, std::string> parameter_map;
-
- TransformationFacade(const std::string&);
+ explicit TransformationFacade(const std::string&);
~TransformationFacade();
int generate(const std::string&);
- int generate(const std::string&, const parameter_map&);
+ int generate(
+ const std::string&,
+ const StylesheetParameterGuard::map&
+ );
private:
const xalan::XalanCompiledStylesheet* transformation_;
xalan::XalanTransformer transformer_;
- void setParameters(const parameter_map&);
+ int generate(const std::string&, StylesheetParameterGuard&);
};