aboutsummaryrefslogtreecommitdiff
path: root/src/transformation_facade.cc
blob: 9d248b8373d35f8d1ad80783c98c99d003aa0d3b (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
#include "transformation_facade.h"

#include <xalanc/XSLT/XSLTInputSource.hpp>
#include <xalanc/XalanTransformer/XalanCompiledStylesheet.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) {
	StylesheetParameterGuard guard(this->transformer_);

	this->generate(targetStream, guard);
}

void TransformationFacade::generate(
	std::basic_ostream<char>&            targetStream,
	const StylesheetParameterGuard::map& parameters
) {
	StylesheetParameterGuard guard(this->transformer_, parameters);

	this->generate(targetStream, guard);
}

void TransformationFacade::generate(
	std::basic_ostream<char>& targetStream,
	const xalan::XObjectPtr&  parameter
) {
	StylesheetParameterGuard guard(this->transformer_);
	guard.set("parameters", parameter);

	this->generate(targetStream, guard);
}


void TransformationFacade::generate(
	std::basic_ostream<char>& targetStream,
	StylesheetParameterGuard&
) {
	ErrorCapacitor errorCapacitor(&this->error_multiplexer_);

	this->transformer_.transform(
		*(this->input_),
		this->transformation_,
		targetStream
	);

	errorCapacitor.discharge();
}

}