aboutsummaryrefslogtreecommitdiff
path: root/src/transformer_facade.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/transformer_facade.cc')
-rw-r--r--src/transformer_facade.cc66
1 files changed, 66 insertions, 0 deletions
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 <xalanc/Include/PlatformDefinitions.hpp>
+#include <xercesc/util/PlatformUtils.hpp>
+
+#include <xalanc/XSLT/XSLTInputSource.hpp>
+#include <xalanc/XalanTransformer/XalanTransformer.hpp>
+#include <xalanc/XalanTransformer/XercesDOMWrapperParsedSource.hpp>
+#include <xalanc/XercesParserLiaison/XercesDOMSupport.hpp>
+
+#include <xercesc/dom/DOMDocument.hpp>
+#include <xercesc/dom/DOMImplementation.hpp>
+
+#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
+ );
+}
+
+}