aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plattform_guard.h24
-rw-r--r--src/transformer_guard.cc67
-rw-r--r--src/transformer_guard.h29
-rw-r--r--src/utility.h2
4 files changed, 121 insertions, 1 deletions
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 <xalanc/Include/PlatformDefinitions.hpp>
+#include <xercesc/util/PlatformUtils.hpp>
+
+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 <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 {
+
+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 <string>
+
+#include <xalanc/XalanTransformer/XalanTransformer.hpp>
+#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp>
+
+#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 <string>
-namespace xalanc_1_11 { };
+namespace xalanc_1_11 { }
namespace xalan = xalanc_1_11;
namespace InputXSLT {