aboutsummaryrefslogtreecommitdiff
path: root/src/transformation_facade.h
blob: eb134cdaf7c7bcd8c1baf0b153c507738ca6c2d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_
#define INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_

#include <xalanc/XalanTransformer/XalanTransformer.hpp>

#include <string>
#include <memory>
#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&&...
		);

		template<typename... Arguments>
		TransformationFacade(Arguments&&..., IncludeEntityResolver*);

		TransformationFacade(
			xalan::XSLTInputSource,
			IncludeEntityResolver*
		);

		TransformationFacade(
			xalan::XSLTInputSource,
			xalan::XSLTInputSource,
			IncludeEntityResolver*
		);

		template <typename Target>
		void generate(Target&);

		template <typename Target>
		void generate(Target&, const StylesheetParameterGuard::map&);

		template <typename Target>
		void generate(Target&, 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_;

		void generate(const std::string&, StylesheetParameterGuard&);
		void generate(std::basic_ostream<char>&, StylesheetParameterGuard&);
		void generate(xalan::XSLTResultTarget&&, StylesheetParameterGuard&);

};

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();
	}
}

template <typename... Arguments>
TransformationFacade::TransformationFacade(
	Arguments&&... arguments,
	IncludeEntityResolver* resolver
):
	TransformationFacade(
		xalan::XSLTInputSource(std::forward<Arguments>(arguments))...,
		resolver
	) { }

template <typename Target>
void TransformationFacade::generate(Target& target) {
	StylesheetParameterGuard guard(this->transformer_);

	this->generate(target, guard);
}

template <typename Target>
void TransformationFacade::generate(
	Target& target,
	const StylesheetParameterGuard::map& parameters
) {
	StylesheetParameterGuard guard(this->transformer_, parameters);

	this->generate(target, guard);
}

template <typename Target>
void TransformationFacade::generate(
	Target& target,
	const xalan::XObjectPtr& parameter
) {
	StylesheetParameterGuard guard(this->transformer_);
	guard.set("parameters", parameter);

	this->generate(target, guard);
}

}

#endif  // INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_