aboutsummaryrefslogtreecommitdiff
path: root/src/support
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-20 21:17:10 +0200
committerAdrian Kummerländer2014-05-20 21:17:10 +0200
commit35334241ce4b76b1b1a66219ce938f27fdf39031 (patch)
tree1bad6d46b957e47eac2127f16198876cf7fe8450 /src/support
parent426265b91d4533b7aa16d53124ad9b5d0a6862d6 (diff)
downloadInputXSLT-35334241ce4b76b1b1a66219ce938f27fdf39031.tar
InputXSLT-35334241ce4b76b1b1a66219ce938f27fdf39031.tar.gz
InputXSLT-35334241ce4b76b1b1a66219ce938f27fdf39031.tar.bz2
InputXSLT-35334241ce4b76b1b1a66219ce938f27fdf39031.tar.lz
InputXSLT-35334241ce4b76b1b1a66219ce938f27fdf39031.tar.xz
InputXSLT-35334241ce4b76b1b1a66219ce938f27fdf39031.tar.zst
InputXSLT-35334241ce4b76b1b1a66219ce938f27fdf39031.zip
Replaced FunctionResolveInclude with IncludeEntityResolver
* xalan / xerces offers the possibility of implementing custom entity resolvers which are called upon by "<xsl:include..." ** such a custom resolver was implemented to resolve include path entities * this is a much better way to support include paths than offering a custom external "resolve-include" function * as entity paths are expanded before they are passed to the entity resolver, a special "[path]" syntax simmilar to "#include <path>" had to be implemented
Diffstat (limited to 'src/support')
-rw-r--r--src/support/include_entity_resolver.cc70
-rw-r--r--src/support/include_entity_resolver.h30
2 files changed, 100 insertions, 0 deletions
diff --git a/src/support/include_entity_resolver.cc b/src/support/include_entity_resolver.cc
new file mode 100644
index 0000000..79631a5
--- /dev/null
+++ b/src/support/include_entity_resolver.cc
@@ -0,0 +1,70 @@
+#include "include_entity_resolver.h"
+
+#include <xercesc/framework/LocalFileInputSource.hpp>
+
+#include "boost/filesystem.hpp"
+
+#include "support/xerces_string_guard.h"
+
+namespace InputXSLT {
+
+IncludeEntityResolver::IncludeEntityResolver(
+ const std::vector<std::string>& path):
+ path_() {
+ this->path_.reserve(path.size());
+
+ std::transform(
+ path.begin(),
+ path.end(),
+ std::back_inserter(this->path_),
+ [](const std::string& path) -> FilesystemContext {
+ return FilesystemContext(path);
+ }
+ );
+}
+
+xercesc::InputSource* IncludeEntityResolver::resolveEntity(
+ const XMLCh* const,
+ const XMLCh* const systemId
+) {
+ if ( systemId != nullptr ) {
+ const std::string rawPath(
+ *XercesStringGuard<char>(systemId)
+ );
+
+ const std::size_t leadingDelimiter = rawPath.find_first_of('[');
+ const std::size_t closingDelimiter = rawPath.find_last_of(']');
+
+ if ( leadingDelimiter != std::string::npos &&
+ closingDelimiter != std::string::npos &&
+ leadingDelimiter < closingDelimiter ) {
+ const std::string filePath(
+ rawPath.substr(
+ leadingDelimiter + 1,
+ closingDelimiter - leadingDelimiter - 1
+ )
+ );
+
+ for ( auto&& context : this->path_ ) {
+ const boost::filesystem::path resolvedPath(
+ context.resolve(filePath)
+ );
+
+ if ( boost::filesystem::exists(resolvedPath) &&
+ boost::filesystem::is_regular_file(resolvedPath) ) {
+ return new xercesc::LocalFileInputSource(
+ *XercesStringGuard<XMLCh>(resolvedPath.string())
+ );
+ }
+ }
+
+ return nullptr;
+ } else {
+ return nullptr;
+ }
+ } else {
+ return nullptr;
+ }
+}
+
+}
diff --git a/src/support/include_entity_resolver.h b/src/support/include_entity_resolver.h
new file mode 100644
index 0000000..390cfe1
--- /dev/null
+++ b/src/support/include_entity_resolver.h
@@ -0,0 +1,30 @@
+#ifndef INPUTXSLT_SRC_SUPPORT_INCLUDE_ENTITY_RESOLVER_H_
+#define INPUTXSLT_SRC_SUPPORT_INCLUDE_ENTITY_RESOLVER_H_
+
+#include <xercesc/sax/EntityResolver.hpp>
+#include <xercesc/sax/InputSource.hpp>
+
+#include <string>
+#include <vector>
+
+#include "filesystem_context.h"
+
+namespace InputXSLT {
+
+class IncludeEntityResolver : public xercesc::EntityResolver {
+ public:
+ IncludeEntityResolver(const std::vector<std::string>&);
+
+ xercesc::InputSource* resolveEntity(
+ const XMLCh* const,
+ const XMLCh* const
+ );
+
+ private:
+ std::vector<FilesystemContext> path_;
+
+};
+
+}
+
+#endif // INPUTXSLT_SRC_SUPPORT_INCLUDE_ENTITY_RESOLVER_H_