aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-06-10 22:27:24 +0200
committerAdrian Kummerländer2014-06-10 22:27:24 +0200
commite805000b1841691cd58930e80bd896a4f7611fd0 (patch)
tree35e4ff32f4aa0856b657abe789e396cb8531ff50
parent516ff636f760458c33676458fc88892faab9d376 (diff)
downloadInputXSLT-e805000b1841691cd58930e80bd896a4f7611fd0.tar
InputXSLT-e805000b1841691cd58930e80bd896a4f7611fd0.tar.gz
InputXSLT-e805000b1841691cd58930e80bd896a4f7611fd0.tar.bz2
InputXSLT-e805000b1841691cd58930e80bd896a4f7611fd0.tar.lz
InputXSLT-e805000b1841691cd58930e80bd896a4f7611fd0.tar.xz
InputXSLT-e805000b1841691cd58930e80bd896a4f7611fd0.tar.zst
InputXSLT-e805000b1841691cd58930e80bd896a4f7611fd0.zip
Added input file support to ixslt
* a single file may be passed to the XSLT processor as input ** the file is read once and stored within a xalan::XalanParsedSource to be reused by all calls to "TransformationFacade::generate" * added appropriate TranformationFacade constructor overload ** this new constructor overload which is taking a path to both the transformation and the input file is the main constructor *** the old constructor is now only a alias for this new constructor * adapted static "try_create" TransformationFacade factory method into variadic template factory method * added optional "--input" argument to ixslt ** expanded option handling accordingly
-rw-r--r--ixslt.cc27
-rw-r--r--src/function/transform.cc4
-rw-r--r--src/transformation_facade.cc48
-rw-r--r--src/transformation_facade.h32
4 files changed, 82 insertions, 29 deletions
diff --git a/ixslt.cc b/ixslt.cc
index 86b883e..2200485 100644
--- a/ixslt.cc
+++ b/ixslt.cc
@@ -43,6 +43,11 @@ boost::optional<boost::program_options::variables_map> input(
"transformation file"
)
(
+ "input",
+ boost::program_options::value<std::string>(),
+ "input file"
+ )
+ (
"target",
boost::program_options::value<std::string>(),
"target file"
@@ -90,12 +95,24 @@ bool process(const boost::program_options::variables_map& variables) {
};
InputXSLT::PlattformGuard plattform(includePath);
+ InputXSLT::TransformationFacade::ptr transformation{};
+
+ if ( variables.count("input") ) {
+ transformation = InputXSLT::TransformationFacade::try_create(
+ handleErrors,
+ variables["input"].as<std::string>(),
+ variables["transformation"].as<std::string>(),
+ plattform.getEntityResolver()
+ );
+ } else {
+ transformation = InputXSLT::TransformationFacade::try_create(
+ handleErrors,
+ variables["transformation"].as<std::string>(),
+ plattform.getEntityResolver()
+ );
+ }
- if ( auto transformation = InputXSLT::TransformationFacade::try_create(
- variables["transformation"].as<std::string>(),
- plattform.getEntityResolver(),
- handleErrors
- ) ) {
+ if ( transformation ) {
WarningGuard guard(transformation.get());
try {
diff --git a/src/function/transform.cc b/src/function/transform.cc
index 059260d..9f0e98a 100644
--- a/src/function/transform.cc
+++ b/src/function/transform.cc
@@ -54,9 +54,9 @@ xercesc::DOMDocument* FunctionTransform::constructDocument(
);
if ( auto transformation = TransformationFacade::try_create(
+ handleErrors(result),
fsContext.resolve(transformationPath).string(),
- this->include_resolver_,
- handleErrors(result)
+ this->include_resolver_
) ) {
try {
transformation->generate(
diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc
index 3c94bdd..16872c7 100644
--- a/src/transformation_facade.cc
+++ b/src/transformation_facade.cc
@@ -9,27 +9,22 @@
namespace InputXSLT {
-auto TransformationFacade::try_create(
+TransformationFacade::TransformationFacade(
const std::string& transformation,
- IncludeEntityResolver* resolver,
- const std::function<void(const ErrorCapacitor::error_cache&)>& handleErrors
-) -> ptr{
- try {
- return ptr(
- new InputXSLT::TransformationFacade(transformation, resolver)
- );
- }
- catch (const ErrorCapacitor::exception& exception) {
- handleErrors(*exception);
-
- return ptr();
- }
-}
+ IncludeEntityResolver* resolver
+):
+ TransformationFacade(
+ std::string{},
+ transformation,
+ resolver
+ ) { }
TransformationFacade::TransformationFacade(
+ const std::string& input,
const std::string& transformation,
IncludeEntityResolver* resolver
):
+ input_{},
transformation_{},
transformer_(),
error_multiplexer_(&transformer_),
@@ -38,6 +33,20 @@ TransformationFacade::TransformationFacade(
ErrorCapacitor errorCapacitor(&this->error_multiplexer_);
+ if ( input.empty() ) {
+ std::stringstream dummyStream("<dummy/>");
+
+ this->transformer_.parseSource(
+ xalan::XSLTInputSource(dummyStream),
+ this->input_
+ );
+ } else {
+ this->transformer_.parseSource(
+ xalan::XSLTInputSource(input.data()),
+ this->input_
+ );
+ }
+
this->transformer_.compileStylesheet(
xalan::XSLTInputSource(transformation.data()),
this->transformation_
@@ -47,6 +56,10 @@ TransformationFacade::TransformationFacade(
}
TransformationFacade::~TransformationFacade() {
+ this->transformer_.destroyParsedSource(
+ this->input_
+ );
+
this->transformer_.destroyStylesheet(
this->transformation_
);
@@ -93,11 +106,8 @@ void TransformationFacade::generate(
) {
ErrorCapacitor errorCapacitor(&this->error_multiplexer_);
- std::stringstream emptyStream("<dummy/>");
- xalan::XSLTInputSource inputSource(emptyStream);
-
this->transformer_.transform(
- inputSource,
+ *(this->input_),
this->transformation_,
outputTarget
);
diff --git a/src/transformation_facade.h b/src/transformation_facade.h
index f69786a..fe711bc 100644
--- a/src/transformation_facade.h
+++ b/src/transformation_facade.h
@@ -20,13 +20,19 @@ class TransformationFacade {
public:
typedef std::unique_ptr<TransformationFacade> ptr;
+ template <typename... Arguments>
static ptr try_create(
- const std::string&,
- IncludeEntityResolver*,
- const std::function<void(const ErrorCapacitor::error_cache&)>&
+ const std::function<void(const ErrorCapacitor::error_cache&)>&,
+ Arguments&&...
);
TransformationFacade(const std::string&, IncludeEntityResolver*);
+ TransformationFacade(
+ const std::string&,
+ const std::string&,
+ IncludeEntityResolver*
+ );
+
~TransformationFacade();
template <typename Target>
@@ -41,6 +47,7 @@ class TransformationFacade {
WarningCapacitor::warning_cache_ptr getCachedWarnings();
private:
+ const xalan::XalanParsedSource* input_;
const xalan::XalanCompiledStylesheet* transformation_;
xalan::XalanTransformer transformer_;
@@ -53,6 +60,25 @@ class TransformationFacade {
};
+template <typename... Arguments>
+auto TransformationFacade::try_create(
+ const std::function<void(const ErrorCapacitor::error_cache&)>& handleErrors,
+ Arguments&&... arguments
+) -> ptr {
+ try {
+ return ptr(
+ new InputXSLT::TransformationFacade(
+ std::forward<Arguments>(arguments)...
+ )
+ );
+ }
+ catch (const ErrorCapacitor::exception& exception) {
+ handleErrors(*exception);
+
+ return ptr();
+ }
+}
+
template <typename Target>
void TransformationFacade::generate(Target& target) {
StylesheetParameterGuard guard(this->transformer_);