aboutsummaryrefslogtreecommitdiff
path: root/src/support/type
diff options
context:
space:
mode:
Diffstat (limited to 'src/support/type')
-rw-r--r--src/support/type/xobject_value.cc55
-rw-r--r--src/support/type/xobject_value.h21
2 files changed, 62 insertions, 14 deletions
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_;
+
+};
}