aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transformation_facade.cc54
-rw-r--r--src/transformation_facade.h41
-rw-r--r--test.cc15
3 files changed, 71 insertions, 39 deletions
diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc
index 41ee458..07483c1 100644
--- a/src/transformation_facade.cc
+++ b/src/transformation_facade.cc
@@ -25,49 +25,43 @@ 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
+ const std::string& targetPath,
+ StylesheetParameterGuard& parameters
) {
- StylesheetParameterGuard guard(this->transformer_, parameters);
-
- return this->generate(target, guard);
-}
+ const boost::filesystem::path targetPathHelper(
+ boost::filesystem::absolute(targetPath)
+ );
-int TransformationFacade::generate(
- const std::string& target,
- const xalan::XObjectPtr& parameter
-) {
- StylesheetParameterGuard guard(this->transformer_);
- guard.set("parameters", parameter);
+ parameters.set(
+ "target-file", targetPathHelper.filename().string()
+ );
+ parameters.set(
+ "parent-directory", targetPathHelper.parent_path().filename().string()
+ );
- return this->generate(target, guard);
+ return this->generate(
+ xalan::XSLTResultTarget(targetPath.data()),
+ parameters
+ );
}
int TransformationFacade::generate(
- const std::string& target,
+ std::basic_ostream<char>& targetStream,
StylesheetParameterGuard& parameters
) {
- const boost::filesystem::path targetFilePath(
- boost::filesystem::absolute(target)
- );
-
- parameters.set(
- "target-file", targetFilePath.filename().string()
- );
- parameters.set(
- "parent-directory", targetFilePath.parent_path().filename().string()
+ return this->generate(
+ xalan::XSLTResultTarget(targetStream),
+ parameters
);
+}
+int TransformationFacade::generate(
+ xalan::XSLTResultTarget&& outputTarget,
+ StylesheetParameterGuard&
+) {
std::stringstream emptyStream("<dummy/>");
xalan::XSLTInputSource inputSource(emptyStream);
- xalan::XSLTResultTarget outputTarget(target.data());
const int resultCode = this->transformer_.transform(
inputSource,
diff --git a/src/transformation_facade.h b/src/transformation_facade.h
index be06d07..7fb0926 100644
--- a/src/transformation_facade.h
+++ b/src/transformation_facade.h
@@ -15,9 +15,14 @@ class TransformationFacade {
explicit TransformationFacade(const std::string&);
~TransformationFacade();
- int generate(const std::string&);
- int generate(const std::string&, const StylesheetParameterGuard::map&);
- int generate(const std::string&, const xalan::XObjectPtr&);
+ template <typename Target>
+ int generate(Target&);
+
+ template <typename Target>
+ int generate(Target&, const StylesheetParameterGuard::map&);
+
+ template <typename Target>
+ int generate(Target&, const xalan::XObjectPtr&);
private:
const xalan::XalanCompiledStylesheet* transformation_;
@@ -25,9 +30,39 @@ class TransformationFacade {
xalan::XalanTransformer transformer_;
int generate(const std::string&, StylesheetParameterGuard&);
+ int generate(std::basic_ostream<char>&, StylesheetParameterGuard&);
+ int generate(xalan::XSLTResultTarget&&, StylesheetParameterGuard&);
};
+template <typename Target>
+int TransformationFacade::generate(Target& target) {
+ StylesheetParameterGuard guard(this->transformer_);
+
+ return this->generate(target, guard);
+}
+
+template <typename Target>
+int TransformationFacade::generate(
+ Target& target,
+ const StylesheetParameterGuard::map& parameters
+) {
+ StylesheetParameterGuard guard(this->transformer_, parameters);
+
+ return this->generate(target, guard);
+}
+
+template <typename Target>
+int TransformationFacade::generate(
+ Target& target,
+ const xalan::XObjectPtr& parameter
+) {
+ StylesheetParameterGuard guard(this->transformer_);
+ guard.set("parameters", parameter);
+
+ return this->generate(target, guard);
+}
+
}
#endif // INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_
diff --git a/test.cc b/test.cc
index 68b8d92..1262520 100644
--- a/test.cc
+++ b/test.cc
@@ -12,7 +12,7 @@ int main(int ac, char** av) {
optionDescription.add_options()
("transformation", boost::program_options::value<std::string>()->required(), "transformation file")
- ("target", boost::program_options::value<std::string>()->required(), "target file")
+ ("target", boost::program_options::value<std::string>(), "target file")
;
boost::program_options::variables_map variables;
@@ -31,17 +31,20 @@ int main(int ac, char** av) {
std::cerr << exception.what() << std::endl;
}
- if ( variables.count("transformation") &&
- variables.count("target") ) {
+ if ( variables.count("transformation") ) {
InputXSLT::PlattformGuard plattform;
InputXSLT::TransformationFacade transformation(
variables["transformation"].as<std::string>()
);
- return transformation.generate(
- variables["target"].as<std::string>()
- );
+ if ( variables.count("target") ) {
+ return transformation.generate(
+ variables["target"].as<std::string>()
+ );
+ } else {
+ return transformation.generate(std::cout);
+ }
} else {
std::cout << optionDescription << std::endl;