From a31fc1169edb33126242eb035dc038cbdea407e8 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Thu, 24 Apr 2014 20:14:14 +0200 Subject: Changed TransformerFacade into TransformationFacade for single XSLTs * contains a single, compiled transformation as specified by its construction argument * uses the transformation's location as the FilesystemContext * allows generation of output documents using _generate_ member method --- src/transformation_facade.cc | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/transformation_facade.cc (limited to 'src/transformation_facade.cc') diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc new file mode 100644 index 0000000..58bdb52 --- /dev/null +++ b/src/transformation_facade.cc @@ -0,0 +1,65 @@ +#include "transformation_facade.h" + +#include +#include + +#include + +#include "function/read_file.h" +#include "function/read_xml_file.h" +#include "function/read_directory.h" + + +namespace InputXSLT { + +TransformationFacade::TransformationFacade(const std::string& transformation): + fs_context_(boost::filesystem::path(transformation).parent_path().string()), + transformation_{}, + transformer_() { + const xalan::XalanDOMString customNamespace( + "http://ExternalFunction.xalan-c++.xml.apache.org" + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-file"), + InputXSLT::FunctionReadFile(this->fs_context_) + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-xml-file"), + InputXSLT::FunctionReadXmlFile(this->fs_context_) + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-directory"), + InputXSLT::FunctionReadDirectory(this->fs_context_) + ); + + this->transformer_.compileStylesheet( + xalan::XSLTInputSource(transformation.data()), + this->transformation_ + ); +} + +TransformationFacade::~TransformationFacade() { + this->transformer_.destroyStylesheet( + this->transformation_ + ); +} + +int TransformationFacade::generate(const std::string& target) { + std::stringstream emptyStream(""); + xalan::XSLTInputSource inputSource(emptyStream); + xalan::XSLTResultTarget outputTarget(target.data()); + + return this->transformer_.transform( + inputSource, + this->transformation_, + outputTarget + ); +} + +} -- cgit v1.2.3