aboutsummaryrefslogtreecommitdiff
path: root/src/function/read_xml_file.cc
blob: d429f34de8fe09ff8da356d6697060ae4c4f9495 (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
#include "read_xml_file.h"

#include "boost/filesystem/fstream.hpp"

namespace InputXSLT {

FunctionReadXmlFile::FunctionReadXmlFile(const FilesystemContext& context):
	fs_context_(context),
	parser_() { }

FunctionReadXmlFile::FunctionReadXmlFile(const FunctionReadXmlFile& src):
	fs_context_(src.fs_context_),
	parser_() { }

xalan::XObjectPtr FunctionReadXmlFile::execute(
	xalan::XPathExecutionContext& executionContext,
	xalan::XalanNode*,
	const xalan::XObjectPtr argument,
	const xalan::Locator*
) const {
	const boost::filesystem::path filePath(
		this->fs_context_.resolve(argument->str())
	);

	if ( boost::filesystem::is_regular_file(filePath) ) {
		boost::filesystem::ifstream file(filePath);

		return executionContext.getXObjectFactory().createNodeSet(
			this->parser_.parseXMLStream(
				xalan::XSLTInputSource(file)
			)
		);
	} else {
		return executionContext.getXObjectFactory().createString(
			xalan::XalanDOMString("io error")
		);
	}
}

FunctionReadXmlFile* FunctionReadXmlFile::clone(
	xalan::MemoryManager& manager) const {
	return xalan::XalanCopyConstruct(manager, *this);
}

const xalan::XalanDOMString& FunctionReadXmlFile::getError(
	xalan::XalanDOMString& result) const {
	result.assign("The read-xml-file() function expects one argument of type string.");

	return result;
}

}