aboutsummaryrefslogtreecommitdiff
path: root/src/transformer_facade.cc
blob: 01314cdfd4c862d8946f02f86c1eadae9e445ca2 (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
#include "transformer_facade.h"

#include <xalanc/XSLT/XSLTInputSource.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <xalanc/XercesParserLiaison/XercesDOMSupport.hpp>
#include <xalanc/XalanTransformer/XercesDOMWrapperParsedSource.hpp>

#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMImplementation.hpp>

#include <iostream>

#include "function/read_file.h"
#include "function/read_xml_file.h"
#include "function/read_directory.h"


namespace InputXSLT {

TransformerFacade::TransformerFacade(const std::string& path):
	fs_context_(path),
	parser_(),
	transformer_() {
	const xalan::XalanDOMString customNamespace(
		"http://ExternalFunction.xalan-c++.xml.apache.org"
	);

	this->transformer_.installExternalFunction(
		customNamespace,
		xalan::XalanDOMString("read-file"),
		InputXSLT::FunctionReadFile(this->fs_context_)
	);

	this->transformer_.installExternalFunction(
		customNamespace,
		xalan::XalanDOMString("read-xml-file"),
		InputXSLT::FunctionReadXmlFile(this->fs_context_)
	);

	this->transformer_.installExternalFunction(
		customNamespace,
		xalan::XalanDOMString("read-directory"),
		InputXSLT::FunctionReadDirectory(this->fs_context_)
	);
}

int TransformerFacade::execute(
	const std::string& transformation,
	const std::string& target
) {
	xercesc::DOMDocument* inputDom(
		xercesc::DOMImplementation::getImplementation()->createDocument()
	);
	xalan::XercesDOMSupport domSupport(this->parser_);

	xalan::XercesDOMWrapperParsedSource parsedInput(
		inputDom,
		this->parser_,
		domSupport
	);

	xalan::XSLTInputSource transform(transformation.data());
	xalan::XSLTResultTarget output(target.data());

	return this->transformer_.transform(
		parsedInput,
		transform,
		output
	);
}

}