aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-22 19:58:15 +0200
committerAdrian Kummerländer2014-05-22 19:58:15 +0200
commit4d0569669e01434b3bb9f689cd176f590344bea8 (patch)
tree131ea5f48f34bafd01ffa133971739f68e551556
parentbbe16940e7a6f97128e99ad7642b964e48ecde2e (diff)
downloadInputXSLT-4d0569669e01434b3bb9f689cd176f590344bea8.tar
InputXSLT-4d0569669e01434b3bb9f689cd176f590344bea8.tar.gz
InputXSLT-4d0569669e01434b3bb9f689cd176f590344bea8.tar.bz2
InputXSLT-4d0569669e01434b3bb9f689cd176f590344bea8.tar.lz
InputXSLT-4d0569669e01434b3bb9f689cd176f590344bea8.tar.xz
InputXSLT-4d0569669e01434b3bb9f689cd176f590344bea8.tar.zst
InputXSLT-4d0569669e01434b3bb9f689cd176f590344bea8.zip
Added include path resolution to external file access functions
* if a given file can not be located relative to the transformation's location both "read-file" and "read-xml-file" will now try to resolve the path using the IncludeEntityResolver * all external functions based on the FunctionBase template are now provided with a pointer to a IncludeEntityResolver instance * it is determined by the external function implementation whether include path resolution will be used
-rw-r--r--src/function/base.h9
-rw-r--r--src/function/read_file.cc13
-rw-r--r--src/function/read_xml_file.cc13
-rw-r--r--src/function/transform.cc4
-rw-r--r--src/function/transform.h7
-rw-r--r--src/plattform_guard.cc6
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(