aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/function/read_file.cc16
-rw-r--r--src/function/read_file.h7
-rw-r--r--src/function/read_xml_file.cc18
-rw-r--r--src/function/read_xml_file.h7
-rw-r--r--src/support/filesystem_context.cc24
-rw-r--r--src/support/filesystem_context.h28
-rw-r--r--src/transformer_facade.cc6
-rw-r--r--src/transformer_facade.h2
8 files changed, 74 insertions, 34 deletions
diff --git a/src/function/read_file.cc b/src/function/read_file.cc
index 19ecfc8..9e32f04 100644
--- a/src/function/read_file.cc
+++ b/src/function/read_file.cc
@@ -6,8 +6,8 @@
namespace InputXSLT {
-FunctionReadFile::FunctionReadFile(const std::string& path):
- path_(path) { }
+FunctionReadFile::FunctionReadFile(const FilesystemContext& context):
+ fs_context_(context) { }
xalan::XObjectPtr FunctionReadFile::execute(
xalan::XPathExecutionContext& executionContext,
@@ -20,19 +20,13 @@ xalan::XObjectPtr FunctionReadFile::execute(
executionContext
);
- generalError(executionContext, context, locator);
+ this->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->fs_context_.resolve(arguments[0]->str())
);
- boost::filesystem::ifstream file(this->path_ / fileName);
-
const std::string fileContent(
(std::istreambuf_iterator<char>(file)),
(std::istreambuf_iterator<char>())
diff --git a/src/function/read_file.h b/src/function/read_file.h
index f5bdb9d..b88336a 100644
--- a/src/function/read_file.h
+++ b/src/function/read_file.h
@@ -6,17 +6,16 @@
#include <xalanc/XPath/Function.hpp>
#include <xalanc/XPath/XObject.hpp>
-#include "boost/filesystem.hpp"
-
#include <string>
#include "common.h"
+#include "support/filesystem_context.h"
namespace InputXSLT {
class FunctionReadFile : public xalan::Function {
public:
- FunctionReadFile(const std::string&);
+ FunctionReadFile(const FilesystemContext&);
virtual xalan::XObjectPtr execute(
xalan::XPathExecutionContext&,
@@ -31,7 +30,7 @@ class FunctionReadFile : public xalan::Function {
bool operator==(const FunctionReadFile&) const = delete;
private:
- const boost::filesystem::path path_;
+ const FilesystemContext& fs_context_;
const xalan::XalanDOMString& getError(xalan::XalanDOMString&) const;
diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc
index 78f81c4..ac42288 100644
--- a/src/function/read_xml_file.cc
+++ b/src/function/read_xml_file.cc
@@ -4,12 +4,12 @@
namespace InputXSLT {
-FunctionReadXmlFile::FunctionReadXmlFile(const std::string& path):
- path_(path),
+FunctionReadXmlFile::FunctionReadXmlFile(const FilesystemContext& context):
+ fs_context_(context),
parser_() { }
FunctionReadXmlFile::FunctionReadXmlFile(const FunctionReadXmlFile& src):
- path_(src.path_),
+ fs_context_(src.fs_context_),
parser_() { }
xalan::XObjectPtr FunctionReadXmlFile::execute(
@@ -23,19 +23,13 @@ xalan::XObjectPtr FunctionReadXmlFile::execute(
executionContext
);
- generalError(executionContext, context, locator);
+ this->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->fs_context_.resolve(arguments[0]->str())
);
- boost::filesystem::ifstream file(this->path_ / fileName);
-
return executionContext.getXObjectFactory().createNodeSet(
this->parser_.parseXMLStream(
xalan::XSLTInputSource(file)
diff --git a/src/function/read_xml_file.h b/src/function/read_xml_file.h
index 6877feb..aa8590a 100644
--- a/src/function/read_xml_file.h
+++ b/src/function/read_xml_file.h
@@ -7,17 +7,16 @@
#include <xalanc/XPath/XObject.hpp>
#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp>
-#include "boost/filesystem.hpp"
-
#include <string>
#include "common.h"
+#include "support/filesystem_context.h"
namespace InputXSLT {
class FunctionReadXmlFile : public xalan::Function {
public:
- FunctionReadXmlFile(const std::string&);
+ FunctionReadXmlFile(const FilesystemContext&);
FunctionReadXmlFile(const FunctionReadXmlFile&);
virtual xalan::XObjectPtr execute(
@@ -33,7 +32,7 @@ class FunctionReadXmlFile : public xalan::Function {
bool operator==(const FunctionReadXmlFile&) const = delete;
private:
- const boost::filesystem::path path_;
+ const FilesystemContext& fs_context_;
mutable xalan::XercesParserLiaison parser_;
const xalan::XalanDOMString& getError(xalan::XalanDOMString& result) const;
diff --git a/src/support/filesystem_context.cc b/src/support/filesystem_context.cc
new file mode 100644
index 0000000..d3f9614
--- /dev/null
+++ b/src/support/filesystem_context.cc
@@ -0,0 +1,24 @@
+#include "filesystem_context.h"
+
+namespace InputXSLT {
+
+FilesystemContext::FilesystemContext(const std::string& path):
+ path_(path) { }
+
+boost::filesystem::path FilesystemContext::resolve(
+ const std::string& path) const {
+ return boost::filesystem::path(this->path_ / path);
+}
+
+boost::filesystem::path FilesystemContext::resolve(
+ const xalan::XalanDOMString& path) const {
+ xalan::CharVectorType castHelper;
+ path.transcode(castHelper);
+
+ return this->resolve(std::string(
+ castHelper.begin(),
+ castHelper.end()
+ ));
+}
+
+}
diff --git a/src/support/filesystem_context.h b/src/support/filesystem_context.h
new file mode 100644
index 0000000..d5836f1
--- /dev/null
+++ b/src/support/filesystem_context.h
@@ -0,0 +1,28 @@
+#ifndef INPUTXSLT_SRC_SUPPORT_FILESYSTEM_CONTEXT_H_
+#define INPUTXSLT_SRC_SUPPORT_FILESYSTEM_CONTEXT_H_
+
+#include <xalanc/XalanDOM/XalanDOMString.hpp>
+
+#include "boost/filesystem.hpp"
+
+#include <string>
+
+#include "common.h"
+
+namespace InputXSLT {
+
+class FilesystemContext {
+ public:
+ explicit FilesystemContext(const std::string&);
+
+ boost::filesystem::path resolve(const std::string&) const;
+ boost::filesystem::path resolve(const xalan::XalanDOMString&) const;
+
+ private:
+ const boost::filesystem::path path_;
+
+};
+
+}
+
+#endif // INPUTXSLT_SRC_SUPPORT_FILESYSTEM_CONTEXT_H_
diff --git a/src/transformer_facade.cc b/src/transformer_facade.cc
index be2a6a2..dfd51ef 100644
--- a/src/transformer_facade.cc
+++ b/src/transformer_facade.cc
@@ -17,6 +17,7 @@
namespace InputXSLT {
TransformerFacade::TransformerFacade(const std::string& path):
+ fs_context_(path),
parser_(),
transformer_() {
const xalan::XalanDOMString customNamespace(
@@ -26,15 +27,14 @@ TransformerFacade::TransformerFacade(const std::string& path):
this->transformer_.installExternalFunction(
customNamespace,
xalan::XalanDOMString("read-file"),
- InputXSLT::FunctionReadFile(path)
+ InputXSLT::FunctionReadFile(this->fs_context_)
);
this->transformer_.installExternalFunction(
customNamespace,
xalan::XalanDOMString("read-xml-file"),
- InputXSLT::FunctionReadXmlFile(path)
+ InputXSLT::FunctionReadXmlFile(this->fs_context_)
);
-
}
int TransformerFacade::execute(
diff --git a/src/transformer_facade.h b/src/transformer_facade.h
index c11fa78..ed25edc 100644
--- a/src/transformer_facade.h
+++ b/src/transformer_facade.h
@@ -7,6 +7,7 @@
#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp>
#include "common.h"
+#include "support/filesystem_context.h"
namespace InputXSLT {
@@ -17,6 +18,7 @@ class TransformerFacade {
int execute(const std::string&, const std::string&);
private:
+ const FilesystemContext fs_context_;
mutable xalan::XercesParserLiaison parser_;
xalan::XalanTransformer transformer_;