aboutsummaryrefslogtreecommitdiff
path: root/src/support
diff options
context:
space:
mode:
authorAdrian Kummerlaender2014-06-17 21:28:04 +0200
committerAdrian Kummerlaender2014-06-17 21:28:04 +0200
commit0d670478b51c55e44f57995fe3ca8a4585723a6c (patch)
tree8014505de42d1743599d8076c503e9f3c6e22e8f /src/support
parent741a70f5fecc38033832728f4ecc62a6abe328b2 (diff)
downloadInputXSLT-0d670478b51c55e44f57995fe3ca8a4585723a6c.tar
InputXSLT-0d670478b51c55e44f57995fe3ca8a4585723a6c.tar.gz
InputXSLT-0d670478b51c55e44f57995fe3ca8a4585723a6c.tar.bz2
InputXSLT-0d670478b51c55e44f57995fe3ca8a4585723a6c.tar.lz
InputXSLT-0d670478b51c55e44f57995fe3ca8a4585723a6c.tar.xz
InputXSLT-0d670478b51c55e44f57995fe3ca8a4585723a6c.tar.zst
InputXSLT-0d670478b51c55e44f57995fe3ca8a4585723a6c.zip
Added context awareness to XObjectValue casting logic
* added support for defining boost::filesystem::path as a external function parameter ** boost::filesystem::path parameters are resolved against the appropriate FilesystemContext and IncludeEntityResolver instances * xalan::XSLTInputSource parameter source paths are also resolved * removed need for passing a reference FilesystemContext to "constructDocument" methods ** they now only accept the parameters of the external function implemented by them ** all path resolution logic is wrapped by the newly created XObjectValue class * converted XObjectValue namespace into class ** the "get" template method is now a template member method ** this was needed to enable value casting logic to access the appropriate FilesystemContext and IncludeEntityResolver instances * this commit marks the next step towards the goals defined in 741a70f
Diffstat (limited to 'src/support')
-rw-r--r--src/support/filesystem_context.cc63
-rw-r--r--src/support/filesystem_context.h22
-rw-r--r--src/support/include_entity_resolver.cc2
-rw-r--r--src/support/include_entity_resolver.h2
-rw-r--r--src/support/type/xobject_value.cc55
-rw-r--r--src/support/type/xobject_value.h21
6 files changed, 93 insertions, 72 deletions
diff --git a/src/support/filesystem_context.cc b/src/support/filesystem_context.cc
index a18ec43..21548a5 100644
--- a/src/support/filesystem_context.cc
+++ b/src/support/filesystem_context.cc
@@ -4,52 +4,13 @@
#include <iterator>
#include "support/xalan_string.h"
-#include "support/xerces_string_guard.h"
namespace InputXSLT {
-FilesystemContext::FilesystemContext(const boost::filesystem::path& path):
- path_(boost::filesystem::canonical(
- path.parent_path()
- )) { }
-
-FilesystemContext::FilesystemContext(const std::string& path):
- path_(boost::filesystem::canonical(path)) { }
-
-boost::filesystem::path FilesystemContext::resolve(
- const std::string& path) const {
- const boost::filesystem::path targetPath(path);
-
- if ( targetPath.is_absolute() ) {
- return targetPath;
- } else {
- return absolute(this->path_ / targetPath);
- }
-}
-
-boost::filesystem::path FilesystemContext::resolve(
- const xalan::XalanDOMString& path) const {
- return this->resolve(toString(path));
-}
-
-void FilesystemContext::iterate(
- const std::string& path,
- const std::function<void(const boost::filesystem::path&)>& func
-) const {
- this->iterate(this->resolve(path), func);
-}
-
-void FilesystemContext::iterate(
- const xalan::XalanDOMString& path,
- const std::function<void(const boost::filesystem::path&)>& func
-) const {
- this->iterate(toString(path), func);
-}
-
void FilesystemContext::iterate(
const boost::filesystem::path& directory,
const std::function<void(const boost::filesystem::path&)>& func
-) const {
+) {
std::vector<boost::filesystem::path> directoryItems;
std::copy_if(
@@ -74,4 +35,26 @@ void FilesystemContext::iterate(
);
}
+FilesystemContext::FilesystemContext(const boost::filesystem::path& path):
+ path_(boost::filesystem::canonical(
+ path.parent_path()
+ )) { }
+
+FilesystemContext::FilesystemContext(const std::string& path):
+ path_(boost::filesystem::canonical(path)) { }
+
+boost::filesystem::path FilesystemContext::resolve(
+ const xalan::XalanDOMString& path) const {
+ return this->resolve(toString(path));
+}
+
+boost::filesystem::path FilesystemContext::resolve(
+ const boost::filesystem::path& path) const {
+ if ( path.is_absolute() ) {
+ return path;
+ } else {
+ return absolute(this->path_ / path);
+ }
+}
+
}
diff --git a/src/support/filesystem_context.h b/src/support/filesystem_context.h
index 9741039..2088c6b 100644
--- a/src/support/filesystem_context.h
+++ b/src/support/filesystem_context.h
@@ -15,26 +15,16 @@ namespace InputXSLT {
class FilesystemContext {
public:
+ static void iterate(
+ const boost::filesystem::path&,
+ const std::function<void(const boost::filesystem::path&)>&
+ );
+
explicit FilesystemContext(const boost::filesystem::path&);
explicit FilesystemContext(const std::string&);
- boost::filesystem::path resolve(const std::string&) const;
boost::filesystem::path resolve(const xalan::XalanDOMString&) const;
-
- void iterate(
- const std::string&,
- const std::function<void(const boost::filesystem::path&)>&
- ) const;
-
- void iterate(
- const xalan::XalanDOMString&,
- const std::function<void(const boost::filesystem::path&)>&
- ) const;
-
- void iterate(
- const boost::filesystem::path&,
- const std::function<void(const boost::filesystem::path&)>&
- ) const;
+ boost::filesystem::path resolve(const boost::filesystem::path&) const;
private:
const boost::filesystem::path path_;
diff --git a/src/support/include_entity_resolver.cc b/src/support/include_entity_resolver.cc
index 86535c8..e1c9f96 100644
--- a/src/support/include_entity_resolver.cc
+++ b/src/support/include_entity_resolver.cc
@@ -71,7 +71,7 @@ boost::filesystem::path IncludeEntityResolver::resolve(
}
boost::optional<boost::filesystem::path> IncludeEntityResolver::resolve(
- const std::string& filePath) const {
+ const boost::filesystem::path& filePath) const {
for ( auto&& context : this->path_ ) {
const boost::filesystem::path resolvedPath(
context.resolve(filePath)
diff --git a/src/support/include_entity_resolver.h b/src/support/include_entity_resolver.h
index c8f2867..32d9001 100644
--- a/src/support/include_entity_resolver.h
+++ b/src/support/include_entity_resolver.h
@@ -25,7 +25,7 @@ class IncludeEntityResolver : public xercesc::EntityResolver {
boost::filesystem::path resolve(
const XMLCh* const) const;
boost::optional<boost::filesystem::path> resolve(
- const std::string&) const;
+ const boost::filesystem::path&) const;
private:
const std::vector<FilesystemContext> path_;
diff --git a/src/support/type/xobject_value.cc b/src/support/type/xobject_value.cc
index 812be52..0236597 100644
--- a/src/support/type/xobject_value.cc
+++ b/src/support/type/xobject_value.cc
@@ -4,6 +4,7 @@
#include <xalanc/XalanDOM/XalanDocumentFragment.hpp>
#include <boost/algorithm/string.hpp>
+#include "boost/filesystem.hpp"
#include <string>
@@ -11,34 +12,68 @@
namespace InputXSLT {
-namespace XObjectValue {
+XObjectValue::XObjectValue(
+ const boost::filesystem::path& path,
+ const IncludeEntityResolver* resolver
+):
+ filesystem_context_(path),
+ include_resolver_(resolver) { }
template <>
-std::string get<std::string>(const xalan::XObjectPtr& ptr) {
+std::string XObjectValue::get<std::string>(
+ const xalan::XObjectPtr& ptr) const {
return boost::trim_copy(toString(ptr->str()));
}
template <>
-xalan::XObjectPtr get<xalan::XObjectPtr>(const xalan::XObjectPtr& ptr) {
+boost::filesystem::path XObjectValue::get<boost::filesystem::path>(
+ const xalan::XObjectPtr& ptr) const {
+ const boost::filesystem::path rawPath(
+ toString(ptr->str())
+ );
+
+ const boost::filesystem::path filePath(
+ this->filesystem_context_.resolve(rawPath)
+ );
+
+ if ( !(boost::filesystem::exists(filePath) &&
+ boost::filesystem::is_regular_file(filePath)) ) {
+ if ( auto resolvedPath = this->include_resolver_->resolve(rawPath) ) {
+ return *resolvedPath;
+ } else {
+ return filePath;
+ }
+ } else {
+ return filePath;
+ }
+}
+
+template <>
+xalan::XObjectPtr XObjectValue::get<xalan::XObjectPtr>(
+ const xalan::XObjectPtr& ptr) const {
return ptr;
}
template <>
-xalan::XSLTInputSource get<xalan::XSLTInputSource>(
- const xalan::XObjectPtr& ptr) {
+xalan::XSLTInputSource XObjectValue::get<xalan::XSLTInputSource>(
+ const xalan::XObjectPtr& ptr) const {
switch ( ptr->getType() ) {
case xalan::XObject::eObjectType::eTypeNodeSet: {
- return xalan::XSLTInputSource(ptr->nodeset().item(0));
+ return xalan::XSLTInputSource(
+ ptr->nodeset().item(0)
+ );
}
case xalan::XObject::eObjectType::eTypeResultTreeFrag: {
- return xalan::XSLTInputSource(ptr->rtree().getFirstChild());
+ return xalan::XSLTInputSource(
+ ptr->rtree().getFirstChild()
+ );
}
default: {
- return xalan::XSLTInputSource(ptr->str());
+ return xalan::XSLTInputSource(
+ this->get<boost::filesystem::path>(ptr).string().data()
+ );
}
}
}
}
-
-}
diff --git a/src/support/type/xobject_value.h b/src/support/type/xobject_value.h
index bb602a4..cfc259d 100644
--- a/src/support/type/xobject_value.h
+++ b/src/support/type/xobject_value.h
@@ -4,13 +4,26 @@
#include <xalanc/XPath/XObject.hpp>
#include "common.h"
+#include "support/filesystem_context.h"
+#include "support/include_entity_resolver.h"
namespace InputXSLT {
-namespace XObjectValue {
- template <typename Type>
- Type get(const xalan::XObjectPtr&);
-}
+class XObjectValue {
+ public:
+ XObjectValue(
+ const boost::filesystem::path&,
+ const IncludeEntityResolver*
+ );
+
+ template <typename Type>
+ Type get(const xalan::XObjectPtr&) const;
+
+ private:
+ const FilesystemContext filesystem_context_;
+ const IncludeEntityResolver* const include_resolver_;
+
+};
}