diff options
-rw-r--r-- | src/function/base.h | 9 | ||||
-rw-r--r-- | src/function/read_file.cc | 13 | ||||
-rw-r--r-- | src/function/read_xml_file.cc | 13 | ||||
-rw-r--r-- | src/function/transform.cc | 4 | ||||
-rw-r--r-- | src/function/transform.h | 7 | ||||
-rw-r--r-- | src/plattform_guard.cc | 6 |
6 files changed, 35 insertions, 17 deletions
diff --git a/src/function/base.h b/src/function/base.h index cc207c3..3609201 100644 --- a/src/function/base.h +++ b/src/function/base.h @@ -10,9 +10,10 @@ #include "common.h" #include "support/xalan_string.h" +#include "support/filesystem_context.h" +#include "support/include_entity_resolver.h" #include "support/tuple/mapper.h" #include "support/dom/document_cache.h" -#include "support/filesystem_context.h" namespace InputXSLT { @@ -24,7 +25,8 @@ class FunctionBase : public xalan::Function { public: typedef std::tuple<Types...> parameter_tuple; - FunctionBase(): + FunctionBase(IncludeEntityResolver* resolver): + include_resolver_(resolver), document_cache_(std::make_shared<DomDocumentCache>()) { } virtual xalan::XObjectPtr execute( @@ -73,6 +75,9 @@ class FunctionBase : public xalan::Function { FunctionBase& operator=(const FunctionBase&) = delete; bool operator==(const FunctionBase&) const = delete; + protected: + IncludeEntityResolver* const include_resolver_; + private: std::shared_ptr<DomDocumentCache> document_cache_; diff --git a/src/function/read_file.cc b/src/function/read_file.cc index 5ded1ac..85f834d 100644 --- a/src/function/read_file.cc +++ b/src/function/read_file.cc @@ -28,10 +28,21 @@ xercesc::DOMDocument* FunctionReadFile::constructDocument( const FilesystemContext& fsContext, const FunctionBase::parameter_tuple& parameters ) { - const boost::filesystem::path filePath( + boost::filesystem::path filePath( fsContext.resolve(std::get<0>(parameters)) ); + if ( !(boost::filesystem::exists(filePath) && + boost::filesystem::is_regular_file(filePath)) ) { + auto resolvedPath = this->include_resolver_->resolve( + std::get<0>(parameters) + ); + + if ( resolvedPath.first ) { + filePath = resolvedPath.second; + } + } + xercesc::DOMDocument* const domDocument( xercesc::DOMImplementation::getImplementation()->createDocument( nullptr, diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc index 5f1d47d..b9246e6 100644 --- a/src/function/read_xml_file.cc +++ b/src/function/read_xml_file.cc @@ -38,10 +38,21 @@ xercesc::DOMDocument* FunctionReadXmlFile::constructDocument( const FilesystemContext& fsContext, const FunctionBase::parameter_tuple& parameters ) { - const boost::filesystem::path filePath( + boost::filesystem::path filePath( fsContext.resolve(std::get<0>(parameters)) ); + if ( !(boost::filesystem::exists(filePath) && + boost::filesystem::is_regular_file(filePath)) ) { + auto resolvedPath = this->include_resolver_->resolve( + std::get<0>(parameters) + ); + + if ( resolvedPath.first ) { + filePath = resolvedPath.second; + } + } + xercesc::DOMDocument* const domDocument( xercesc::DOMImplementation::getImplementation()->createDocument( nullptr, diff --git a/src/function/transform.cc b/src/function/transform.cc index 8823745..cf6ff09 100644 --- a/src/function/transform.cc +++ b/src/function/transform.cc @@ -9,10 +9,6 @@ namespace InputXSLT { -FunctionTransform::FunctionTransform(IncludeEntityResolver* resolver): - FunctionBase::FunctionBase(), - include_resolver_(resolver) { } - xercesc::DOMDocument* FunctionTransform::constructDocument( const InputXSLT::FilesystemContext& fsContext, const FunctionBase::parameter_tuple& parameters diff --git a/src/function/transform.h b/src/function/transform.h index 94fae53..810738e 100644 --- a/src/function/transform.h +++ b/src/function/transform.h @@ -3,8 +3,6 @@ #include "base.h" -#include "support/include_entity_resolver.h" - namespace InputXSLT { class FunctionTransform : public FunctionBase< @@ -14,7 +12,7 @@ class FunctionTransform : public FunctionBase< xalan::XObjectPtr > { public: - FunctionTransform(IncludeEntityResolver*); + using FunctionBase::FunctionBase; protected: friend FunctionBase; @@ -24,9 +22,6 @@ class FunctionTransform : public FunctionBase< const FunctionBase::parameter_tuple& ); - private: - IncludeEntityResolver* const include_resolver_; - }; } diff --git a/src/plattform_guard.cc b/src/plattform_guard.cc index 8ffbbb9..d66c8b5 100644 --- a/src/plattform_guard.cc +++ b/src/plattform_guard.cc @@ -25,19 +25,19 @@ PlattformGuard::PlattformGuard(const std::vector<std::string>& path): xalan::XalanTransformer::installExternalFunctionGlobal( customNamespace, xalan::XalanDOMString("read-file"), - InputXSLT::FunctionReadFile() + InputXSLT::FunctionReadFile(&this->include_resolver_) ); xalan::XalanTransformer::installExternalFunctionGlobal( customNamespace, xalan::XalanDOMString("read-xml-file"), - InputXSLT::FunctionReadXmlFile() + InputXSLT::FunctionReadXmlFile(&this->include_resolver_) ); xalan::XalanTransformer::installExternalFunctionGlobal( customNamespace, xalan::XalanDOMString("read-directory"), - InputXSLT::FunctionReadDirectory() + InputXSLT::FunctionReadDirectory(&this->include_resolver_) ); xalan::XalanTransformer::installExternalFunctionGlobal( |