diff options
author | Adrian Kummerlaender | 2014-08-20 22:28:15 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2014-08-20 22:28:15 +0200 |
commit | 2c89112141530617b51af8c41211c2507ec8c738 (patch) | |
tree | c467e07340c55cf81090315e79e85af05b542647 /src | |
parent | b31f9170c2bc2330442070968d3cb334cadb5faa (diff) | |
download | InputXSLT-2c89112141530617b51af8c41211c2507ec8c738.tar InputXSLT-2c89112141530617b51af8c41211c2507ec8c738.tar.gz InputXSLT-2c89112141530617b51af8c41211c2507ec8c738.tar.bz2 InputXSLT-2c89112141530617b51af8c41211c2507ec8c738.tar.lz InputXSLT-2c89112141530617b51af8c41211c2507ec8c738.tar.xz InputXSLT-2c89112141530617b51af8c41211c2507ec8c738.tar.zst InputXSLT-2c89112141530617b51af8c41211c2507ec8c738.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/function/base.h | 8 | ||||
-rw-r--r-- | src/function/external_command.cc | 4 | ||||
-rw-r--r-- | src/function/external_command.h | 1 | ||||
-rw-r--r-- | src/function/generate.cc | 7 | ||||
-rw-r--r-- | src/function/generate.h | 1 | ||||
-rw-r--r-- | src/function/read_directory.cc | 4 | ||||
-rw-r--r-- | src/function/read_directory.h | 4 | ||||
-rw-r--r-- | src/function/read_file.cc | 4 | ||||
-rw-r--r-- | src/function/read_file.h | 4 | ||||
-rw-r--r-- | src/function/transform.cc | 5 | ||||
-rw-r--r-- | src/function/transform.h | 1 | ||||
-rw-r--r-- | src/function/write_file.cc | 5 | ||||
-rw-r--r-- | src/function/write_file.h | 1 | ||||
-rw-r--r-- | src/support/type/xobject_value.cc | 10 | ||||
-rw-r--r-- | 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<Index...> ) 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<const Implementation*>(this)->constructDocument( + context, valueGetter.get<typename std::tuple_element< Index, std::tuple<Types...> 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<std::string> 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<std::string> ) 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<std::string> 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<boost::filesystem::path>( 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<xalan::XSLTInputSource>( source.setSystemId( *XercesStringGuard<XMLCh>( - 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_; }; |