aboutsummaryrefslogtreecommitdiff
path: root/src/function/read_file.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/function/read_file.cc')
-rw-r--r--src/function/read_file.cc44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/function/read_file.cc b/src/function/read_file.cc
index 9e32f04..ac6225a 100644
--- a/src/function/read_file.cc
+++ b/src/function/read_file.cc
@@ -10,31 +10,31 @@ FunctionReadFile::FunctionReadFile(const FilesystemContext& context):
fs_context_(context) { }
xalan::XObjectPtr FunctionReadFile::execute(
- xalan::XPathExecutionContext& executionContext,
- xalan::XalanNode* context,
- const xalan::Function::XObjectArgVectorType& arguments,
- const xalan::Locator* locator
+ xalan::XPathExecutionContext& executionContext,
+ xalan::XalanNode*,
+ const xalan::XObjectPtr argument,
+ const xalan::Locator*
) const {
- if ( arguments.size() != 1 ) {
- xalan::XPathExecutionContext::GetAndReleaseCachedString guard(
- executionContext
- );
-
- this->generalError(executionContext, context, locator);
- }
-
- boost::filesystem::ifstream file(
- this->fs_context_.resolve(arguments[0]->str())
+ const boost::filesystem::path filePath(
+ this->fs_context_.resolve(argument->str())
);
- const std::string fileContent(
- (std::istreambuf_iterator<char>(file)),
- (std::istreambuf_iterator<char>())
- );
+ if ( boost::filesystem::is_regular_file(filePath) ) {
+ boost::filesystem::ifstream file(filePath);
- return executionContext.getXObjectFactory().createString(
- xalan::XalanDOMString(fileContent.data())
- );
+ const std::string fileContent(
+ (std::istreambuf_iterator<char>(file)),
+ (std::istreambuf_iterator<char>())
+ );
+
+ return executionContext.getXObjectFactory().createString(
+ xalan::XalanDOMString(fileContent.data())
+ );
+ } else {
+ return executionContext.getXObjectFactory().createString(
+ xalan::XalanDOMString("io error")
+ );
+ }
}
FunctionReadFile* FunctionReadFile::clone(
@@ -44,7 +44,7 @@ FunctionReadFile* FunctionReadFile::clone(
const xalan::XalanDOMString& FunctionReadFile::getError(
xalan::XalanDOMString& result) const {
- result.assign("The read-file() function expects one argument.");
+ result.assign("The read-file() function expects one argument of type string.");
return result;
}