aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-06-09 14:24:26 +0200
committerAdrian Kummerländer2014-06-09 14:24:26 +0200
commit516ff636f760458c33676458fc88892faab9d376 (patch)
tree8c0bc2790fa8025fed9173d9e0abba22408ac303
parentf13e1fa9a41006d80e6923489414cfdc2fcadd08 (diff)
downloadInputXSLT-516ff636f760458c33676458fc88892faab9d376.tar
InputXSLT-516ff636f760458c33676458fc88892faab9d376.tar.gz
InputXSLT-516ff636f760458c33676458fc88892faab9d376.tar.bz2
InputXSLT-516ff636f760458c33676458fc88892faab9d376.tar.lz
InputXSLT-516ff636f760458c33676458fc88892faab9d376.tar.xz
InputXSLT-516ff636f760458c33676458fc88892faab9d376.tar.zst
InputXSLT-516ff636f760458c33676458fc88892faab9d376.zip
Added include path resolution to FilesystemContext constructor
* extracted system id handling into separate "resolve" method overload of "IncludeEntityResolver" class * paths to be resolved against the include path vector are enclosed by square brackets ** FilesystemContext for external functions was instantiated using the unmodified systemId provided by xalan::Locator ** this commit adds include path resolution to that step *** exceptions were thrown as the program tried to instantiate a FilesystemContext instance without resolving the square bracket syntax * changed FunctionTransform "target" attribute content to the target path filename instead of the full path
-rw-r--r--src/function/base.h6
-rw-r--r--src/function/transform.cc16
-rw-r--r--src/support/filesystem_context.cc6
-rw-r--r--src/support/filesystem_context.h2
-rw-r--r--src/support/include_entity_resolver.cc34
-rw-r--r--src/support/include_entity_resolver.h2
6 files changed, 42 insertions, 24 deletions
diff --git a/src/function/base.h b/src/function/base.h
index 3ca1d61..f2b3d5c 100644
--- a/src/function/base.h
+++ b/src/function/base.h
@@ -100,7 +100,11 @@ class FunctionBase : public xalan::Function {
static_cast<Implementation*>(
const_cast<FunctionBase*>(this)
)->constructDocument(
- FilesystemContext(locator),
+ FilesystemContext(
+ this->include_resolver_->resolve(
+ locator->getSystemId()
+ )
+ ),
XObjectValue::get<typename std::tuple_element<
Index,
std::tuple<Types...>
diff --git a/src/function/transform.cc b/src/function/transform.cc
index 7e6207c..059260d 100644
--- a/src/function/transform.cc
+++ b/src/function/transform.cc
@@ -34,9 +34,6 @@ xercesc::DOMDocument* FunctionTransform::constructDocument(
std::string targetPath,
xalan::XObjectPtr parameterObject
) {
- transformationPath = fsContext.resolve(transformationPath).string();
- targetPath = fsContext.resolve(targetPath).string();
-
xercesc::DOMDocument* const domDocument(
xercesc::DOMImplementation::getImplementation()->createDocument(
nullptr,
@@ -50,15 +47,22 @@ xercesc::DOMDocument* FunctionTransform::constructDocument(
);
ResultNodeFacade result(domDocument, rootNode, "transformation");
- result.setAttribute("target", targetPath);
+
+ result.setAttribute(
+ "target",
+ boost::filesystem::path(targetPath).filename().string()
+ );
if ( auto transformation = TransformationFacade::try_create(
- transformationPath,
+ fsContext.resolve(transformationPath).string(),
this->include_resolver_,
handleErrors(result)
) ) {
try {
- transformation->generate(targetPath, parameterObject);
+ transformation->generate(
+ fsContext.resolve(targetPath).string(),
+ parameterObject
+ );
result.setAttribute("result", "success");
}
diff --git a/src/support/filesystem_context.cc b/src/support/filesystem_context.cc
index eba7e45..a18ec43 100644
--- a/src/support/filesystem_context.cc
+++ b/src/support/filesystem_context.cc
@@ -8,11 +8,9 @@
namespace InputXSLT {
-FilesystemContext::FilesystemContext(const xalan::Locator* locator):
+FilesystemContext::FilesystemContext(const boost::filesystem::path& path):
path_(boost::filesystem::canonical(
- boost::filesystem::path(
- *XercesStringGuard<char>(locator->getSystemId()) + 7
- ).parent_path().string()
+ path.parent_path()
)) { }
FilesystemContext::FilesystemContext(const std::string& path):
diff --git a/src/support/filesystem_context.h b/src/support/filesystem_context.h
index 1f574de..9741039 100644
--- a/src/support/filesystem_context.h
+++ b/src/support/filesystem_context.h
@@ -15,7 +15,7 @@ namespace InputXSLT {
class FilesystemContext {
public:
- explicit FilesystemContext(const xalan::Locator*);
+ explicit FilesystemContext(const boost::filesystem::path&);
explicit FilesystemContext(const std::string&);
boost::filesystem::path resolve(const std::string&) const;
diff --git a/src/support/include_entity_resolver.cc b/src/support/include_entity_resolver.cc
index e63a3c4..5e106f2 100644
--- a/src/support/include_entity_resolver.cc
+++ b/src/support/include_entity_resolver.cc
@@ -10,6 +10,13 @@ namespace {
using InputXSLT::XercesStringGuard;
+inline boost::filesystem::path getPathFromSystemId(
+ const XMLCh* const systemId) {
+ return boost::filesystem::path(
+ *XercesStringGuard<char>(systemId) + 7
+ );
+}
+
boost::optional<std::string> extractFilePath(const XMLCh* const rawPath) {
const std::string filePath = *XercesStringGuard<char>(rawPath);
const std::size_t leadingDelimiter = filePath.find_first_of('[');
@@ -42,21 +49,24 @@ xercesc::InputSource* IncludeEntityResolver::resolveEntity(
const XMLCh* const systemId
) {
if ( systemId != nullptr ) {
- if ( auto filePath = extractFilePath(systemId) ) {
- if ( auto resolvedPath = this->resolve(*filePath) ) {
- return new xercesc::LocalFileInputSource(
- *XercesStringGuard<XMLCh>((*resolvedPath).string())
- );
- } else {
- return new xercesc::LocalFileInputSource(
- *XercesStringGuard<XMLCh>(*filePath)
- );
- }
+ return new xercesc::LocalFileInputSource(
+ *XercesStringGuard<XMLCh>(this->resolve(systemId).string())
+ );
+ } else {
+ return nullptr;
+ }
+}
+
+boost::filesystem::path IncludeEntityResolver::resolve(
+ const XMLCh* const rawPath) const {
+ if ( auto filePath = extractFilePath(rawPath) ) {
+ if ( auto resolvedPath = this->resolve(*filePath) ) {
+ return *resolvedPath;
} else {
- return nullptr;
+ return getPathFromSystemId(rawPath);
}
} else {
- return nullptr;
+ return getPathFromSystemId(rawPath);
}
}
diff --git a/src/support/include_entity_resolver.h b/src/support/include_entity_resolver.h
index 28992d6..c8f2867 100644
--- a/src/support/include_entity_resolver.h
+++ b/src/support/include_entity_resolver.h
@@ -22,6 +22,8 @@ class IncludeEntityResolver : public xercesc::EntityResolver {
const XMLCh* const
);
+ boost::filesystem::path resolve(
+ const XMLCh* const) const;
boost::optional<boost::filesystem::path> resolve(
const std::string&) const;