aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/function/transform.cc72
-rw-r--r--src/function/transform.h6
-rw-r--r--src/support/stylesheet_parameter_guard.cc46
-rw-r--r--src/support/stylesheet_parameter_guard.h37
-rw-r--r--src/transformation_facade.cc116
-rw-r--r--src/transformation_facade.h80
-rw-r--r--src/transformer_facade.cc129
-rw-r--r--src/transformer_facade.h46
8 files changed, 210 insertions, 322 deletions
diff --git a/src/function/transform.cc b/src/function/transform.cc
index 1d22399..e53b55f 100644
--- a/src/function/transform.cc
+++ b/src/function/transform.cc
@@ -6,7 +6,7 @@
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMElement.hpp>
-#include "transformation_facade.h"
+#include "transformer_facade.h"
#include "support/xerces_string_guard.h"
#include "support/dom/result_node_facade.h"
#include "support/error/error_capacitor.h"
@@ -15,15 +15,15 @@ namespace {
using InputXSLT::ErrorCapacitor;
-inline std::function<void(const ErrorCapacitor::error_cache&)> handleErrors(
- InputXSLT::ResultNodeFacade& result) {
- return [&result](const ErrorCapacitor::error_cache& errors) {
- result.setAttribute("result", "error");
+inline void handleErrors(
+ InputXSLT::ResultNodeFacade& result,
+ const ErrorCapacitor::error_cache& errors
+) {
+ result.setAttribute("result", "error");
- for ( auto&& error : errors ) {
- result.setValueNode("error", error);
- }
- };
+ for ( auto&& error : errors ) {
+ result.setValueNode("error", error);
+ }
}
}
@@ -32,8 +32,7 @@ namespace InputXSLT {
xercesc::DOMDocument* FunctionTransform::constructDocument(
xalan::XSLTInputSource inputSource,
- xalan::XSLTInputSource transformationSource,
- xalan::XObjectPtr parameterObject
+ xalan::XSLTInputSource transformationSource
) {
xercesc::DOMDocument* const domDocument(
xercesc::DOMImplementation::getImplementation()->createDocument(
@@ -48,37 +47,32 @@ xercesc::DOMDocument* FunctionTransform::constructDocument(
);
ResultNodeFacade result(domDocument, rootElement, "transformation");
+ TransformerFacade transformer(this->include_resolver_);
- if ( auto transformation = TransformationFacade::try_create(
- handleErrors(result),
- inputSource,
- transformationSource,
- this->include_resolver_
- ) ) {
- try {
- xalan::FormatterToXercesDOM formatter(
- domDocument,
- result.getResultElement()
- );
-
- transformation->generate(
- formatter,
- parameterObject
- );
-
- result.setAttribute("result", "success");
- }
- catch (const ErrorCapacitor::exception& exception) {
- handleErrors(result)(*exception);
- }
-
- WarningCapacitor::warning_cache_ptr warnings(
- transformation->getCachedWarnings()
+ try {
+ xalan::FormatterToXercesDOM targetFormatter(
+ domDocument,
+ result.getResultElement()
);
- for ( auto&& warning : *warnings ) {
- result.setValueNode("warning", warning);
- }
+ transformer.generate(
+ inputSource,
+ transformationSource,
+ targetFormatter
+ );
+
+ result.setAttribute("result", "success");
+ }
+ catch (const ErrorCapacitor::exception& exception) {
+ handleErrors(result, *exception);
+ }
+
+ WarningCapacitor::warning_cache_ptr warnings(
+ transformer.getCachedWarnings()
+ );
+
+ for ( auto&& warning : *warnings ) {
+ result.setValueNode("warning", warning);
}
return domDocument;
diff --git a/src/function/transform.h b/src/function/transform.h
index 234a1d0..b8e733d 100644
--- a/src/function/transform.h
+++ b/src/function/transform.h
@@ -10,8 +10,7 @@ namespace InputXSLT {
class FunctionTransform : public FunctionBase<
FunctionTransform,
xalan::XSLTInputSource,
- xalan::XSLTInputSource,
- xalan::XObjectPtr
+ xalan::XSLTInputSource
> {
public:
using FunctionBase::FunctionBase;
@@ -21,8 +20,7 @@ class FunctionTransform : public FunctionBase<
xercesc::DOMDocument* constructDocument(
xalan::XSLTInputSource,
- xalan::XSLTInputSource,
- xalan::XObjectPtr
+ xalan::XSLTInputSource
);
};
diff --git a/src/support/stylesheet_parameter_guard.cc b/src/support/stylesheet_parameter_guard.cc
deleted file mode 100644
index 399bccb..0000000
--- a/src/support/stylesheet_parameter_guard.cc
+++ /dev/null
@@ -1,46 +0,0 @@
-#include "stylesheet_parameter_guard.h"
-
-namespace InputXSLT {
-
-StylesheetParameterGuard::StylesheetParameterGuard(
- xalan::XalanTransformer& transformer
-): transformer_(transformer) { }
-
-StylesheetParameterGuard::StylesheetParameterGuard(
- xalan::XalanTransformer& transformer,
- const map& parameters
-): transformer_(transformer) {
- this->set(parameters);
-}
-
-StylesheetParameterGuard::~StylesheetParameterGuard() {
- this->transformer_.clearStylesheetParams();
-}
-
-void StylesheetParameterGuard::set(const map& parameters) {
- for ( auto&& parameter : parameters ) {
- this->set(parameter.first, parameter.second);
- }
-}
-
-void StylesheetParameterGuard::set(
- const std::string& key,
- const std::string& value
-) {
- this->transformer_.setStylesheetParam(
- key.data(),
- std::string("'" + value + "'").data()
- );
-}
-
-void StylesheetParameterGuard::set(
- const std::string& key,
- const xalan::XObjectPtr& value
-) {
- this->transformer_.setStylesheetParam(
- key.data(),
- value
- );
-}
-
-}
diff --git a/src/support/stylesheet_parameter_guard.h b/src/support/stylesheet_parameter_guard.h
deleted file mode 100644
index 7fa425e..0000000
--- a/src/support/stylesheet_parameter_guard.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef INPUTXSLT_SRC_SUPPORT_STYLESHEET_PARAMETER_GUARD_H_
-#define INPUTXSLT_SRC_SUPPORT_STYLESHEET_PARAMETER_GUARD_H_
-
-#include <xalanc/XalanTransformer/XalanTransformer.hpp>
-#include <xalanc/XPath/XObject.hpp>
-
-#include <string>
-#include <unordered_map>
-
-#include "common.h"
-
-namespace InputXSLT {
-
-class StylesheetParameterGuard {
- public:
- typedef std::unordered_map<std::string, std::string> map;
-
- explicit StylesheetParameterGuard(xalan::XalanTransformer&);
- StylesheetParameterGuard(
- xalan::XalanTransformer&,
- const map&
- );
-
- ~StylesheetParameterGuard();
-
- void set(const map&);
- void set(const std::string&, const std::string&);
- void set(const std::string&, const xalan::XObjectPtr&);
-
- private:
- xalan::XalanTransformer& transformer_;
-
-};
-
-}
-
-#endif // INPUTXSLT_SRC_SUPPORT_STYLESHEET_PARAMETER_GUARD_H_
diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc
deleted file mode 100644
index 4017cd0..0000000
--- a/src/transformation_facade.cc
+++ /dev/null
@@ -1,116 +0,0 @@
-#include "transformation_facade.h"
-
-#include <xalanc/XSLT/XSLTInputSource.hpp>
-#include <xalanc/XalanTransformer/XalanCompiledStylesheet.hpp>
-#include <xalanc/PlatformSupport/XalanOutputStreamPrintWriter.hpp>
-#include <xalanc/PlatformSupport/XalanStdOutputStream.hpp>
-#include <xalanc/XMLSupport/FormatterToXML.hpp>
-
-#include "support/xerces_string_guard.h"
-
-namespace InputXSLT {
-
-TransformationFacade::TransformationFacade(
- xalan::XSLTInputSource transformation,
- IncludeEntityResolver* resolver
-):
- input_{},
- transformation_{},
- transformer_(),
- error_multiplexer_(&transformer_),
- warning_capacitor_(&error_multiplexer_) {
- this->transformer_.setEntityResolver(resolver);
-
- ErrorCapacitor errorCapacitor(&this->error_multiplexer_);
-
- std::stringstream dummyStream("<dummy/>");
-
- this->transformer_.parseSource(
- xalan::XSLTInputSource(dummyStream),
- this->input_
- );
-
- this->transformer_.compileStylesheet(
- transformation,
- this->transformation_
- );
-
- errorCapacitor.discharge();
-}
-
-TransformationFacade::TransformationFacade(
- xalan::XSLTInputSource input,
- xalan::XSLTInputSource transformation,
- IncludeEntityResolver* resolver
-):
- input_{},
- transformation_{},
- transformer_(),
- error_multiplexer_(&transformer_),
- warning_capacitor_(&error_multiplexer_) {
- this->transformer_.setEntityResolver(resolver);
-
- ErrorCapacitor errorCapacitor(&this->error_multiplexer_);
-
- this->transformer_.parseSource(
- input,
- this->input_
- );
-
- this->transformer_.compileStylesheet(
- transformation,
- this->transformation_
- );
-
- errorCapacitor.discharge();
-}
-
-WarningCapacitor::warning_cache_ptr TransformationFacade::getCachedWarnings() {
- return this->warning_capacitor_.discharge();
-}
-
-void TransformationFacade::generate(
- std::basic_ostream<char>& targetStream,
- const xalan::XObjectPtr& parameter
-) {
- StylesheetParameterGuard guard(this->transformer_);
- guard.set("parameters", parameter);
-
- this->generate(targetStream);
-}
-
-void TransformationFacade::generate(std::basic_ostream<char>& targetStream) {
- StylesheetParameterGuard guard(this->transformer_);
-
- xalan::XalanStdOutputStream outputStream(targetStream);
- xalan::XalanOutputStreamPrintWriter outputWriter(outputStream);
-
- xalan::FormatterToXML formatter(outputWriter);
- formatter.setDoIndent(true);
-
- this->generate(formatter);
-}
-
-void TransformationFacade::generate(
- xalan::FormatterListener& formatter,
- const xalan::XObjectPtr& parameter
-) {
- StylesheetParameterGuard guard(this->transformer_);
- guard.set("parameters", parameter);
-
- this->generate(formatter);
-}
-
-void TransformationFacade::generate(xalan::FormatterListener& target) {
- ErrorCapacitor errorCapacitor(&this->error_multiplexer_);
-
- this->transformer_.transform(
- *(this->input_),
- this->transformation_,
- target
- );
-
- errorCapacitor.discharge();
-}
-
-}
diff --git a/src/transformation_facade.h b/src/transformation_facade.h
deleted file mode 100644
index e4cbc10..0000000
--- a/src/transformation_facade.h
+++ /dev/null
@@ -1,80 +0,0 @@
-#ifndef INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_
-#define INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_
-
-#include <xalanc/XalanTransformer/XalanTransformer.hpp>
-
-#include <string>
-#include <memory>
-#include <sstream>
-#include <functional>
-
-#include "common.h"
-#include "support/include_entity_resolver.h"
-#include "support/stylesheet_parameter_guard.h"
-#include "support/error/error_multiplexer.h"
-#include "support/error/error_capacitor.h"
-#include "support/error/warning_capacitor.h"
-
-namespace InputXSLT {
-
-class TransformationFacade {
- public:
- typedef std::unique_ptr<TransformationFacade> ptr;
-
- template <typename... Arguments>
- static ptr try_create(
- const std::function<void(const ErrorCapacitor::error_cache&)>&,
- Arguments&&...
- );
-
- TransformationFacade(
- xalan::XSLTInputSource,
- IncludeEntityResolver*
- );
-
- TransformationFacade(
- xalan::XSLTInputSource,
- xalan::XSLTInputSource,
- IncludeEntityResolver*
- );
-
- void generate(std::basic_ostream<char>&);
- void generate(std::basic_ostream<char>&, const xalan::XObjectPtr&);
-
- void generate(xalan::FormatterListener&);
- void generate(xalan::FormatterListener&, const xalan::XObjectPtr&);
-
- WarningCapacitor::warning_cache_ptr getCachedWarnings();
-
- private:
- const xalan::XalanParsedSource* input_;
- const xalan::XalanCompiledStylesheet* transformation_;
-
- xalan::XalanTransformer transformer_;
- ErrorMultiplexer error_multiplexer_;
- WarningCapacitor warning_capacitor_;
-
-};
-
-template <typename... Arguments>
-auto TransformationFacade::try_create(
- const std::function<void(const ErrorCapacitor::error_cache&)>& handleErrors,
- Arguments&&... arguments
-) -> ptr {
- try {
- return ptr(
- new InputXSLT::TransformationFacade(
- std::forward<Arguments>(arguments)...
- )
- );
- }
- catch (const ErrorCapacitor::exception& exception) {
- handleErrors(*exception);
-
- return ptr();
- }
-}
-
-}
-
-#endif // INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_
diff --git a/src/transformer_facade.cc b/src/transformer_facade.cc
new file mode 100644
index 0000000..10c8c7a
--- /dev/null
+++ b/src/transformer_facade.cc
@@ -0,0 +1,129 @@
+#include "transformer_facade.h"
+
+#include <xalanc/PlatformSupport/XalanOutputStreamPrintWriter.hpp>
+#include <xalanc/PlatformSupport/XalanStdOutputStream.hpp>
+
+#include <xalanc/XMLSupport/FormatterToXML.hpp>
+#include <xalanc/XercesParserLiaison/FormatterToXercesDOM.hpp>
+#include <xalanc/XMLSupport/FormatterTreeWalker.hpp>
+
+#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp>
+#include <xalanc/XercesParserLiaison/XercesDOMSupport.hpp>
+#include <xalanc/XalanTransformer/XercesDOMWrapperParsedSource.hpp>
+
+#include <xercesc/dom/DOMDocument.hpp>
+#include <xercesc/dom/DOMImplementation.hpp>
+
+#include "support/xerces_string_guard.h"
+
+namespace InputXSLT {
+
+TransformerFacade::TransformerFacade(IncludeEntityResolver* resolver):
+ transformer_(),
+ error_multiplexer_(&transformer_),
+ warning_capacitor_(&error_multiplexer_) {
+ this->transformer_.setEntityResolver(resolver);
+}
+
+WarningCapacitor::warning_cache_ptr TransformerFacade::getCachedWarnings() {
+ return this->warning_capacitor_.discharge();
+}
+
+void TransformerFacade::generate(
+ const xalan::XSLTInputSource& source,
+ const xalan::XSLTInputSource& transformation,
+ xalan::FormatterListener& target
+) {
+ if ( source.getNode() == nullptr ) {
+ ErrorCapacitor errorCapacitor(&this->error_multiplexer_);
+
+ this->transformer_.transform(
+ source,
+ transformation,
+ target
+ );
+
+ errorCapacitor.discharge();
+ } else {
+ this->generate(
+ source.getNode(),
+ transformation,
+ target
+ );
+ }
+}
+
+void TransformerFacade::generate(
+ const xalan::XSLTInputSource& transformation,
+ xalan::FormatterListener& target
+) {
+ ErrorCapacitor errorCapacitor(&this->error_multiplexer_);
+
+ xercesc::DOMDocument* const inputDocument(
+ xercesc::DOMImplementation::getImplementation()->createDocument(
+ nullptr,
+ *XercesStringGuard<XMLCh>("dummy"),
+ nullptr
+ )
+ );
+
+ xalan::XercesParserLiaison parserLiaison;
+ xalan::XercesDOMSupport domSupport(parserLiaison);
+
+ xalan::XercesDOMWrapperParsedSource inputParsedSource(
+ inputDocument,
+ parserLiaison,
+ domSupport
+ );
+
+ this->transformer_.transform(
+ inputParsedSource,
+ transformation,
+ target
+ );
+
+ inputDocument->release();
+
+ errorCapacitor.discharge();
+}
+
+void TransformerFacade::generate(
+ xalan::XalanNode* const source,
+ const xalan::XSLTInputSource& transformation,
+ xalan::FormatterListener& target
+) {
+ ErrorCapacitor errorCapacitor(&this->error_multiplexer_);
+
+ xercesc::DOMDocument* const inputDocument(
+ xercesc::DOMImplementation::getImplementation()->createDocument()
+ );
+
+ xalan::FormatterToXercesDOM inputFormatter(
+ inputDocument,
+ inputDocument->getDocumentElement()
+ );
+
+ xalan::FormatterTreeWalker walker(inputFormatter);
+ walker.traverseSubtree(source);
+
+ xalan::XercesParserLiaison parserLiaison;
+ xalan::XercesDOMSupport domSupport(parserLiaison);
+
+ xalan::XercesDOMWrapperParsedSource inputParsedSource(
+ inputFormatter.getDocument(),
+ parserLiaison,
+ domSupport
+ );
+
+ this->transformer_.transform(
+ inputParsedSource,
+ transformation,
+ target
+ );
+
+ inputDocument->release();
+
+ errorCapacitor.discharge();
+}
+
+}
diff --git a/src/transformer_facade.h b/src/transformer_facade.h
new file mode 100644
index 0000000..17db094
--- /dev/null
+++ b/src/transformer_facade.h
@@ -0,0 +1,46 @@
+#ifndef INPUTXSLT_SRC_TRANSFORMER_FACADE_H_
+#define INPUTXSLT_SRC_TRANSFORMER_FACADE_H_
+
+#include <xalanc/XalanTransformer/XalanTransformer.hpp>
+
+#include "common.h"
+#include "support/include_entity_resolver.h"
+#include "support/error/error_multiplexer.h"
+#include "support/error/error_capacitor.h"
+#include "support/error/warning_capacitor.h"
+
+namespace InputXSLT {
+
+class TransformerFacade {
+ public:
+ TransformerFacade(IncludeEntityResolver*);
+
+ void generate(
+ const xalan::XSLTInputSource&,
+ const xalan::XSLTInputSource&,
+ xalan::FormatterListener&
+ );
+
+ void generate(
+ const xalan::XSLTInputSource&,
+ xalan::FormatterListener&
+ );
+
+ WarningCapacitor::warning_cache_ptr getCachedWarnings();
+
+ private:
+ xalan::XalanTransformer transformer_;
+ ErrorMultiplexer error_multiplexer_;
+ WarningCapacitor warning_capacitor_;
+
+ void generate(
+ xalan::XalanNode* const,
+ const xalan::XSLTInputSource&,
+ xalan::FormatterListener&
+ );
+
+};
+
+}
+
+#endif // INPUTXSLT_SRC_TRANSFORMER_FACADE_H_