aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/support/include_entity_resolver.cc76
-rw-r--r--src/support/include_entity_resolver.h2
2 files changed, 50 insertions, 28 deletions
diff --git a/src/support/include_entity_resolver.cc b/src/support/include_entity_resolver.cc
index 79631a5..a00d9e6 100644
--- a/src/support/include_entity_resolver.cc
+++ b/src/support/include_entity_resolver.cc
@@ -6,6 +6,29 @@
#include "support/xerces_string_guard.h"
+namespace {
+
+std::pair<bool, std::string> extractFilePath(const std::string& rawPath) {
+ 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 ) {
+ return std::make_pair(
+ true,
+ rawPath.substr(
+ leadingDelimiter + 1,
+ closingDelimiter - leadingDelimiter - 1
+ )
+ );
+ } else {
+ return std::make_pair(false, std::string());
+ }
+}
+
+}
+
namespace InputXSLT {
IncludeEntityResolver::IncludeEntityResolver(
@@ -28,37 +51,18 @@ xercesc::InputSource* IncludeEntityResolver::resolveEntity(
const XMLCh* const systemId
) {
if ( systemId != nullptr ) {
- const std::string rawPath(
- *XercesStringGuard<char>(systemId)
- );
+ auto filePath = extractFilePath(*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 ( filePath.first ) {
+ auto resolvedPath = this->resolve(filePath.second);
- if ( boost::filesystem::exists(resolvedPath) &&
- boost::filesystem::is_regular_file(resolvedPath) ) {
- return new xercesc::LocalFileInputSource(
- *XercesStringGuard<XMLCh>(resolvedPath.string())
- );
- }
+ if ( resolvedPath.first ) {
+ return new xercesc::LocalFileInputSource(
+ *XercesStringGuard<XMLCh>(resolvedPath.second.string())
+ );
+ } else {
+ return nullptr;
}
-
- return nullptr;
} else {
return nullptr;
}
@@ -67,4 +71,20 @@ xercesc::InputSource* IncludeEntityResolver::resolveEntity(
}
}
+std::pair<bool, boost::filesystem::path> IncludeEntityResolver::resolve(
+ const std::string& filePath) {
+ 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 std::make_pair(true, resolvedPath);
+ }
+ }
+
+ return std::make_pair(false, boost::filesystem::path());
+}
+
}
diff --git a/src/support/include_entity_resolver.h b/src/support/include_entity_resolver.h
index 390cfe1..b87e10f 100644
--- a/src/support/include_entity_resolver.h
+++ b/src/support/include_entity_resolver.h
@@ -20,6 +20,8 @@ class IncludeEntityResolver : public xercesc::EntityResolver {
const XMLCh* const
);
+ std::pair<bool, boost::filesystem::path> resolve(const std::string&);
+
private:
std::vector<FilesystemContext> path_;