blob: 19ecfc8d6ec848c232e9c244c03e200d904aee85 (
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
|
#include "read_file.h"
#include "boost/filesystem/fstream.hpp"
#include <fstream>
namespace InputXSLT {
FunctionReadFile::FunctionReadFile(const std::string& path):
path_(path) { }
xalan::XObjectPtr FunctionReadFile::execute(
xalan::XPathExecutionContext& executionContext,
xalan::XalanNode* context,
const xalan::Function::XObjectArgVectorType& arguments,
const xalan::Locator* locator
) const {
if ( arguments.size() != 1 ) {
xalan::XPathExecutionContext::GetAndReleaseCachedString guard(
executionContext
);
generalError(executionContext, context, locator);
}
xalan::CharVectorType castHelper;
arguments[0]->str().transcode(castHelper);
const std::string fileName(
castHelper.begin(),
castHelper.end()
);
boost::filesystem::ifstream file(this->path_ / fileName);
const std::string fileContent(
(std::istreambuf_iterator<char>(file)),
(std::istreambuf_iterator<char>())
);
return executionContext.getXObjectFactory().createString(
xalan::XalanDOMString(fileContent.data())
);
}
FunctionReadFile* FunctionReadFile::clone(
xalan::MemoryManager& manager) const {
return xalan::XalanCopyConstruct(manager, *this);
}
const xalan::XalanDOMString& FunctionReadFile::getError(
xalan::XalanDOMString& result) const {
result.assign("The read-file() function expects one argument.");
return result;
}
}
|