From 2c89112141530617b51af8c41211c2507ec8c738 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 20 Aug 2014 22:28:15 +0200 Subject: Setting the correct work directory in FunctionExternalCommand * changed the XObjectValue constructor to accept a pointer to FilesystemContext instead of instantiating the context by itself * the FilesystemContext is now instantiated in the "callConstructDocument" member method of "FunctionBase" ** a const reference to FilesystemContext is passed to all "constructDocument" member method implementations * the FilesystemContext is currently only used by FunctionExternal command to set the correct work directory in "boost::process::context" ** this is required so calling external commands from inside a stylesheet works as expected *** i.e. from inside the directory the stylesheet is located in * modified all remaining external function implementations accordingly --- src/function/base.h | 8 +++++--- src/function/external_command.cc | 4 ++++ src/function/external_command.h | 1 + src/function/generate.cc | 7 ++++--- src/function/generate.h | 1 + src/function/read_directory.cc | 4 +++- src/function/read_directory.h | 4 +++- src/function/read_file.cc | 4 +++- src/function/read_file.h | 4 +++- src/function/transform.cc | 5 +++-- src/function/transform.h | 1 + src/function/write_file.cc | 5 +++-- src/function/write_file.h | 1 + src/support/type/xobject_value.cc | 10 +++++----- src/support/type/xobject_value.h | 4 ++-- 15 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/function/base.h b/src/function/base.h index 3726aa8..d53ae8a 100644 --- a/src/function/base.h +++ b/src/function/base.h @@ -120,15 +120,17 @@ class FunctionBase : public xalan::Function { const xalan::Locator* locator, Sequence ) const { - XObjectValue valueGetter( + const FilesystemContext context( IncludeEntityResolver::getPathFromSystemId( locator->getSystemId() - ), - this->include_resolver_ + ) ); + XObjectValue valueGetter(&context, this->include_resolver_); + return this->document_cache_->create( static_cast(this)->constructDocument( + context, valueGetter.get diff --git a/src/function/external_command.cc b/src/function/external_command.cc index 7d91a9a..3819a43 100644 --- a/src/function/external_command.cc +++ b/src/function/external_command.cc @@ -40,6 +40,7 @@ inline xercesc::DOMNode* importDocumentElement( namespace InputXSLT { DomDocumentCache::document_ptr FunctionExternalCommand::constructDocument( + const FilesystemContext& fsContext, std::string command, boost::optional input ) const { @@ -51,6 +52,9 @@ DomDocumentCache::document_ptr FunctionExternalCommand::constructDocument( context.environment = boost::process::self::get_environment(); context.stdout_behavior = boost::process::capture_stream(); context.stdin_behavior = boost::process::capture_stream(); + context.work_directory = boost::filesystem::canonical( + fsContext.getBase().parent_path() + ).string(); boost::process::child commandProcess( boost::process::launch_shell(command, context) diff --git a/src/function/external_command.h b/src/function/external_command.h index 8af5079..3c4579d 100644 --- a/src/function/external_command.h +++ b/src/function/external_command.h @@ -20,6 +20,7 @@ class FunctionExternalCommand : public FunctionBase< friend FunctionBase; DomDocumentCache::document_ptr constructDocument( + const FilesystemContext&, std::string, boost::optional ) const; diff --git a/src/function/generate.cc b/src/function/generate.cc index df5e65b..f9cd449 100644 --- a/src/function/generate.cc +++ b/src/function/generate.cc @@ -15,9 +15,10 @@ namespace InputXSLT { DomDocumentCache::document_ptr FunctionGenerate::constructDocument( - xalan::XSLTInputSource inputSource, - xalan::XSLTInputSource transformationSource, - boost::filesystem::path targetPath + const FilesystemContext&, + xalan::XSLTInputSource inputSource, + xalan::XSLTInputSource transformationSource, + boost::filesystem::path targetPath ) const { DomDocumentCache::document_ptr domDocument( DomDocumentCache::createDocument("content") diff --git a/src/function/generate.h b/src/function/generate.h index 43f5da1..333ed37 100644 --- a/src/function/generate.h +++ b/src/function/generate.h @@ -20,6 +20,7 @@ class FunctionGenerate : public FunctionBase< friend FunctionBase; DomDocumentCache::document_ptr constructDocument( + const FilesystemContext&, xalan::XSLTInputSource, xalan::XSLTInputSource, boost::filesystem::path diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc index 8436459..d630e5d 100644 --- a/src/function/read_directory.cc +++ b/src/function/read_directory.cc @@ -6,7 +6,9 @@ namespace InputXSLT { DomDocumentCache::document_ptr FunctionReadDirectory::constructDocument( - boost::filesystem::path directoryPath) const { + const FilesystemContext&, + boost::filesystem::path directoryPath +) const { DomDocumentCache::document_ptr domDocument( DomDocumentCache::createDocument("content") ); diff --git a/src/function/read_directory.h b/src/function/read_directory.h index 914f9b3..814d2ae 100644 --- a/src/function/read_directory.h +++ b/src/function/read_directory.h @@ -18,7 +18,9 @@ class FunctionReadDirectory : public FunctionBase< friend FunctionBase; DomDocumentCache::document_ptr constructDocument( - boost::filesystem::path) const; + const FilesystemContext&, + boost::filesystem::path + ) const; }; diff --git a/src/function/read_file.cc b/src/function/read_file.cc index 42cb4a4..3718f04 100644 --- a/src/function/read_file.cc +++ b/src/function/read_file.cc @@ -60,7 +60,9 @@ boost::optional readPlainFile( namespace InputXSLT { DomDocumentCache::document_ptr FunctionReadFile::constructDocument( - boost::filesystem::path filePath) const { + const FilesystemContext&, + boost::filesystem::path filePath +) const { DomDocumentCache::document_ptr domDocument( DomDocumentCache::createDocument("content") ); diff --git a/src/function/read_file.h b/src/function/read_file.h index b26bc6a..e5233e7 100644 --- a/src/function/read_file.h +++ b/src/function/read_file.h @@ -18,7 +18,9 @@ class FunctionReadFile : public FunctionBase< friend FunctionBase; DomDocumentCache::document_ptr constructDocument( - boost::filesystem::path) const; + const FilesystemContext&, + boost::filesystem::path + ) const; }; diff --git a/src/function/transform.cc b/src/function/transform.cc index 7eab3fd..9bd2dae 100644 --- a/src/function/transform.cc +++ b/src/function/transform.cc @@ -10,8 +10,9 @@ namespace InputXSLT { DomDocumentCache::document_ptr FunctionTransform::constructDocument( - xalan::XSLTInputSource inputSource, - xalan::XSLTInputSource transformationSource + const FilesystemContext&, + xalan::XSLTInputSource inputSource, + xalan::XSLTInputSource transformationSource ) const { DomDocumentCache::document_ptr domDocument( DomDocumentCache::createDocument("content") diff --git a/src/function/transform.h b/src/function/transform.h index 48f5c89..6c8c05d 100644 --- a/src/function/transform.h +++ b/src/function/transform.h @@ -19,6 +19,7 @@ class FunctionTransform : public FunctionBase< friend FunctionBase; DomDocumentCache::document_ptr constructDocument( + const FilesystemContext&, xalan::XSLTInputSource, xalan::XSLTInputSource ) const; diff --git a/src/function/write_file.cc b/src/function/write_file.cc index 70412d7..db9eea5 100644 --- a/src/function/write_file.cc +++ b/src/function/write_file.cc @@ -59,8 +59,9 @@ bool serializeNodeToFile( namespace InputXSLT { DomDocumentCache::document_ptr FunctionWriteFile::constructDocument( - boost::filesystem::path filePath, - xalan::XalanNode* const contentNode + const FilesystemContext&, + boost::filesystem::path filePath, + xalan::XalanNode* const contentNode ) const { DomDocumentCache::document_ptr domDocument( DomDocumentCache::createDocument("content") diff --git a/src/function/write_file.h b/src/function/write_file.h index 723865e..df05f95 100644 --- a/src/function/write_file.h +++ b/src/function/write_file.h @@ -17,6 +17,7 @@ class FunctionWriteFile : public FunctionBase< friend FunctionBase; DomDocumentCache::document_ptr constructDocument( + const FilesystemContext&, boost::filesystem::path, xalan::XalanNode* const ) const; diff --git a/src/support/type/xobject_value.cc b/src/support/type/xobject_value.cc index e457a69..2fe4f9f 100644 --- a/src/support/type/xobject_value.cc +++ b/src/support/type/xobject_value.cc @@ -15,10 +15,10 @@ namespace InputXSLT { XObjectValue::XObjectValue( - const boost::filesystem::path& path, - const IncludeEntityResolver* resolver + const FilesystemContext* context, + const IncludeEntityResolver* resolver ): - filesystem_context_(path), + filesystem_context_(context), include_resolver_(resolver) { } template <> @@ -47,7 +47,7 @@ boost::filesystem::path XObjectValue::get( if ( auto resolvedPath = this->include_resolver_->resolve(rawPath) ) { return *resolvedPath; } else { - return this->filesystem_context_.resolve(rawPath); + return this->filesystem_context_->resolve(rawPath); } } @@ -89,7 +89,7 @@ xalan::XSLTInputSource XObjectValue::get( source.setSystemId( *XercesStringGuard( - this->filesystem_context_.getBase().string() + this->filesystem_context_->getBase().string() ) ); diff --git a/src/support/type/xobject_value.h b/src/support/type/xobject_value.h index cfc259d..53ceacc 100644 --- a/src/support/type/xobject_value.h +++ b/src/support/type/xobject_value.h @@ -12,7 +12,7 @@ namespace InputXSLT { class XObjectValue { public: XObjectValue( - const boost::filesystem::path&, + const FilesystemContext*, const IncludeEntityResolver* ); @@ -20,7 +20,7 @@ class XObjectValue { Type get(const xalan::XObjectPtr&) const; private: - const FilesystemContext filesystem_context_; + const FilesystemContext* const filesystem_context_; const IncludeEntityResolver* const include_resolver_; }; -- cgit v1.2.3