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

#include <xalanc/XSLT/XSLTInputSource.hpp>
#include <xalanc/XalanTransformer/XalanCompiledStylesheet.hpp>

#include "boost/filesystem.hpp"

#include <sstream>

namespace InputXSLT {

TransformationFacade::TransformationFacade(
	const std::string& transformation,
	IncludeEntityResolver* resolver
):
	transformation_{},
	transformer_(),
	error_handler_() {
	this->transformer_.setEntityResolver(resolver);
	this->transformer_.setErrorHandler(&this->error_handler_);
	this->transformer_.setProblemListener(&this->error_handler_);

	this->transformer_.compileStylesheet(
		xalan::XSLTInputSource(transformation.data()),
		this->transformation_
	);
}

TransformationFacade::~TransformationFacade() {
	this->transformer_.destroyStylesheet(
		this->transformation_
	);
}

auto TransformationFacade::generate(
	const std::string& targetPath,
	StylesheetParameterGuard& parameters
) -> return_type {
	const boost::filesystem::path targetPathHelper(
		boost::filesystem::absolute(targetPath)
	);

	parameters.set(
		"target-file",      targetPathHelper.filename().string()
	);
	parameters.set(
		"parent-directory", targetPathHelper.parent_path().filename().string()
	);

	return this->generate(
		xalan::XSLTResultTarget(targetPath.data()),
		parameters
	);
}

auto TransformationFacade::generate(
	std::basic_ostream<char>& targetStream,
	StylesheetParameterGuard& parameters
) -> return_type {
	return this->generate(
		xalan::XSLTResultTarget(targetStream),
		parameters
	);
}

auto TransformationFacade::generate(
	xalan::XSLTResultTarget&& outputTarget,
	StylesheetParameterGuard&
) -> return_type {
	if ( this->transformation_ != nullptr ) {
		std::stringstream      emptyStream("<dummy/>");
		xalan::XSLTInputSource inputSource(emptyStream);

		this->transformer_.transform(
			inputSource,
			this->transformation_,
			outputTarget
		);
	}

	return this->error_handler_.getCachedErrors();
}

}