aboutsummaryrefslogtreecommitdiff
path: root/src/support
diff options
context:
space:
mode:
Diffstat (limited to 'src/support')
-rw-r--r--src/support/dom_document_guard.cc45
-rw-r--r--src/support/dom_document_guard.h36
2 files changed, 81 insertions, 0 deletions
diff --git a/src/support/dom_document_guard.cc b/src/support/dom_document_guard.cc
new file mode 100644
index 0000000..a83345f
--- /dev/null
+++ b/src/support/dom_document_guard.cc
@@ -0,0 +1,45 @@
+#include "support/dom_document_guard.h"
+
+#include <xercesc/dom/DOMImplementation.hpp>
+#include <xercesc/util/XMLString.hpp>
+
+namespace InputXSLT {
+
+DomDocumentGuard::DomDocumentGuard(const std::string& rootNode):
+ parser_(),
+ dom_support_(parser_),
+ root_node_name_(
+ xercesc::XMLString::transcode(rootNode.data())
+ ),
+ document_(
+ xercesc::DOMImplementation::getImplementation()->createDocument(
+ nullptr,
+ root_node_name_,
+ nullptr
+ )
+ ),
+ parsed_source_() { }
+
+DomDocumentGuard::~DomDocumentGuard() {
+ xercesc::XMLString::release(&this->root_node_name_);
+
+ this->document_->release();
+}
+
+xercesc::DOMDocument* DomDocumentGuard::operator->() {
+ return this->document_;
+}
+
+xalan::XalanDocument* DomDocumentGuard::finalize() {
+ this->parsed_source_.reset(
+ new xalan::XercesDOMWrapperParsedSource(
+ document_,
+ parser_,
+ dom_support_
+ )
+ );
+
+ return this->parsed_source_->getDocument();
+}
+
+}
diff --git a/src/support/dom_document_guard.h b/src/support/dom_document_guard.h
new file mode 100644
index 0000000..decca01
--- /dev/null
+++ b/src/support/dom_document_guard.h
@@ -0,0 +1,36 @@
+#ifndef INPUTXSLT_SRC_SUPPORT_DOM_DOCUMENT_GUARD_H_
+#define INPUTXSLT_SRC_SUPPORT_DOM_DOCUMENT_GUARD_H_
+
+#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp>
+#include <xalanc/XercesParserLiaison/XercesDOMSupport.hpp>
+#include <xalanc/XalanTransformer/XercesDOMWrapperParsedSource.hpp>
+
+#include <xercesc/dom/DOMDocument.hpp>
+
+#include <string>
+#include <memory>
+
+#include "common.h"
+
+namespace InputXSLT {
+
+class DomDocumentGuard {
+ public:
+ DomDocumentGuard(const std::string&);
+ ~DomDocumentGuard();
+
+ xercesc::DOMDocument* operator->();
+ xalan::XalanDocument* finalize();
+
+ private:
+ xalan::XercesParserLiaison parser_;
+ xalan::XercesDOMSupport dom_support_;
+ XMLCh* root_node_name_;
+ xercesc::DOMDocument* const document_;
+ std::unique_ptr<xalan::XercesDOMWrapperParsedSource> parsed_source_;
+
+};
+
+}
+
+#endif // INPUTXSLT_SRC_SUPPORT_DOM_DOCUMENT_GUARD_H_