From 3383e24e396431eed7d4ab9f69ff8ffaf12d4925 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sat, 19 Apr 2014 18:31:15 +0200 Subject: Implemented transformation execution function * InputXSLT::PlattformGuard handles xerces and xalan construction and lifetime * InputXSLT::TransformerGuard instantiates PlattformGuard, configurates external functions ** offers execute method for "executing" a XSL tranformation with empty input --- src/plattform_guard.h | 24 +++++++++++++++++ src/transformer_guard.cc | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ src/transformer_guard.h | 29 +++++++++++++++++++++ src/utility.h | 2 +- 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src/plattform_guard.h create mode 100644 src/transformer_guard.cc create mode 100644 src/transformer_guard.h (limited to 'src') diff --git a/src/plattform_guard.h b/src/plattform_guard.h new file mode 100644 index 0000000..9e99fdc --- /dev/null +++ b/src/plattform_guard.h @@ -0,0 +1,24 @@ +#ifndef INPUTXSLT_SRC_PLATTFORM_GUARD_H_ +#define INPUTXSLT_SRC_PLATTFORM_GUARD_H_ + +#include +#include + +namespace xalan = xalanc_1_11; + +namespace InputXSLT { + +struct PlattformGuard { + PlattformGuard() { + xercesc::XMLPlatformUtils::Initialize(); + xalan::XalanTransformer::initialize(); + } + + ~PlattformGuard() { + xalan::XalanTransformer::terminate(); + } +}; + +} + +#endif // INPUTXSLT_SRC_PLATTFORM_GUARD_H_ diff --git a/src/transformer_guard.cc b/src/transformer_guard.cc new file mode 100644 index 0000000..73bcea2 --- /dev/null +++ b/src/transformer_guard.cc @@ -0,0 +1,67 @@ +#include "transformer_guard.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include "function/read_file.h" +#include "function/read_xml_file.h" + +namespace InputXSLT { + +TransformerGuard::TransformerGuard(): + plattform_(), + parser_(), + transformer_() { + const xalan::XalanDOMString customNamespace( + "http://ExternalFunction.xalan-c++.xml.apache.org" + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-file"), + InputXSLT::FunctionReadFile() + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-xml-file"), + InputXSLT::FunctionReadXmlFile() + ); + +} + +int TransformerGuard::execute( + const std::string& transformation, + const std::string& target +) { + xercesc::DOMDocument* inputDom( + xercesc::DOMImplementation::getImplementation()->createDocument() + ); + xalan::XercesDOMSupport domSupport(this->parser_); + + xalan::XercesDOMWrapperParsedSource parsedInput( + inputDom, + this->parser_, + domSupport, + xalan::XalanDOMString("") + ); + + xalan::XSLTInputSource transform(transformation.data()); + xalan::XSLTResultTarget output(target.data()); + + return this->transformer_.transform( + parsedInput, + transform, + output + ); +} + +} diff --git a/src/transformer_guard.h b/src/transformer_guard.h new file mode 100644 index 0000000..381fb94 --- /dev/null +++ b/src/transformer_guard.h @@ -0,0 +1,29 @@ +#ifndef INPUTXSLT_SRC_TRANSFORMER_GUARD_H_ +#define INPUTXSLT_SRC_TRANSFORMER_GUARD_H_ + +#include + +#include +#include + +#include "plattform_guard.h" + +namespace InputXSLT { + +class TransformerGuard { + public: + TransformerGuard(); + + int execute(const std::string&, const std::string&); + + private: + const PlattformGuard plattform_; + mutable xalan::XercesParserLiaison parser_; + + xalan::XalanTransformer transformer_; + +}; + +} + +#endif // INPUTXSLT_SRC_TRANSFORMER_GUARD_H_ diff --git a/src/utility.h b/src/utility.h index b841373..ee39a25 100644 --- a/src/utility.h +++ b/src/utility.h @@ -3,7 +3,7 @@ #include -namespace xalanc_1_11 { }; +namespace xalanc_1_11 { } namespace xalan = xalanc_1_11; namespace InputXSLT { -- cgit v1.2.3