aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-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
-rw-r--r--test.cc44
6 files changed, 127 insertions, 40 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index aa6310b..26ff8d1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,7 @@ add_executable(
test
test.cc
src/utility.cc
+ src/transformer_guard.cc
src/function/read_file.cc
src/function/read_xml_file.cc
)
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 {
diff --git a/test.cc b/test.cc
index cfcf632..09325f7 100644
--- a/test.cc
+++ b/test.cc
@@ -1,44 +1,10 @@
-#include <xalanc/Include/PlatformDefinitions.hpp>
-#include <xercesc/util/PlatformUtils.hpp>
-#include <xalanc/XalanTransformer/XalanTransformer.hpp>
-#include <xalanc/XSLT/XSLTInputSource.hpp>
-
-#include "function/read_file.h"
-#include "function/read_xml_file.h"
+#include "transformer_guard.h"
int main() {
- xercesc::XMLPlatformUtils::Initialize();
- xalan::XalanTransformer::initialize();
-
- const xalan::XalanDOMString customNamespace(
- "http://ExternalFunction.xalan-c++.xml.apache.org"
- );
-
- xalan::XalanTransformer transformer;
-
- transformer.installExternalFunction(
- customNamespace,
- xalan::XalanDOMString("read-file"),
- InputXSLT::FunctionReadFile()
- );
+ InputXSLT::TransformerGuard guard;
- transformer.installExternalFunction(
- customNamespace,
- xalan::XalanDOMString("read-xml-file"),
- InputXSLT::FunctionReadXmlFile()
+ return guard.execute(
+ "../dummy/transform.xsl",
+ "out.xml"
);
-
- xalan::XSLTInputSource input("../dummy/in.xml");
- xalan::XSLTInputSource tranformation("../dummy/transform.xsl");
- xalan::XSLTResultTarget output("out.xml");
-
- int result(transformer.transform(
- input,
- tranformation,
- output
- ));
-
- xalan::XalanTransformer::terminate();
-
- return result;
}