From cdf4ad3486debe75fe89b2f04bb62541f3ac8405 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Mon, 21 Apr 2014 13:30:23 +0200 Subject: Extracted filesystem path resolution into InputXSLT::FilesystemContext * this class provides methods for resolving paths relative to the contained base path * other filesystem interaction methods will also be implemented in this class ** for instance directory traversal --- src/support/filesystem_context.cc | 24 ++++++++++++++++++++++++ src/support/filesystem_context.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/support/filesystem_context.cc create mode 100644 src/support/filesystem_context.h (limited to 'src/support') 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 + +#include "boost/filesystem.hpp" + +#include + +#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_ -- cgit v1.2.3