From 29a9fb20b4c8414f2590886e43ae86794a53db89 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sun, 20 Apr 2014 13:09:32 +0200 Subject: Implemented support for modifying external function base path * one expects a read-file function to work relative to the directory the transformation is located and not to the executable's location ** from the perspective of the user the transformation is the application, not the actual executable * removed PlattformGuard struct from TransformerGuard (now TransformerFacade) * TransformerFacade is instatiated with the appropriate relative working path ** i.e. it will have to be instantiated for every directory containing one or more transformations --- src/transformer_facade.cc | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/transformer_facade.cc (limited to 'src/transformer_facade.cc') diff --git a/src/transformer_facade.cc b/src/transformer_facade.cc new file mode 100644 index 0000000..be2a6a2 --- /dev/null +++ b/src/transformer_facade.cc @@ -0,0 +1,66 @@ +#include "transformer_facade.h" + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include "function/read_file.h" +#include "function/read_xml_file.h" + +namespace InputXSLT { + +TransformerFacade::TransformerFacade(const std::string& path): + parser_(), + transformer_() { + const xalan::XalanDOMString customNamespace( + "http://ExternalFunction.xalan-c++.xml.apache.org" + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-file"), + InputXSLT::FunctionReadFile(path) + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-xml-file"), + InputXSLT::FunctionReadXmlFile(path) + ); + +} + +int TransformerFacade::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 + ); +} + +} -- cgit v1.2.3