From 22cbef9c75aeb58d6c88c9b736526cb9d52a52a2 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Mon, 28 Apr 2014 20:03:06 +0200 Subject: Adapted read-directory tree construction to match the other functions * throwing std::out_of_range exception from DomDocumentCache::get instead of returning nullptr in case of a problem * moved xalanToString method back into FilesystemContext compilation unit as is only needed there --- src/function/read_directory.cc | 11 ++++++----- src/support/dom/document_cache.cc | 4 +++- src/support/filesystem_context.cc | 14 +++++++++++++- src/support/utility.h | 18 ------------------ 4 files changed, 22 insertions(+), 25 deletions(-) delete mode 100644 src/support/utility.h (limited to 'src') diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc index 6fcb447..b0ae13f 100644 --- a/src/function/read_directory.cc +++ b/src/function/read_directory.cc @@ -5,7 +5,6 @@ #include #include -#include "support/utility.h" #include "support/xerces_string_guard.h" namespace InputXSLT { @@ -20,8 +19,12 @@ xalan::XObjectPtr FunctionReadDirectory::execute( const xalan::XObjectPtr argument, const xalan::Locator* ) const { + const boost::filesystem::path directoryPath( + this->fs_context_.resolve(argument->str()) + ); + DomDocumentCache::item* const cachedDocument( - this->document_cache_->get(xalanToString(argument->str())) + this->document_cache_->get(directoryPath.string()) ); if ( !cachedDocument->isFinalized() ) { @@ -33,9 +36,7 @@ xalan::XObjectPtr FunctionReadDirectory::execute( domDocument->getDocumentElement() ); - if (boost::filesystem::is_directory( - this->fs_context_.resolve(argument->str()) - )) { + if ( boost::filesystem::is_directory(directoryPath) ) { xercesc::DOMElement* const contentNode( domDocument->createElement(*XercesStringGuard("content")) ); diff --git a/src/support/dom/document_cache.cc b/src/support/dom/document_cache.cc index f814559..1573af8 100644 --- a/src/support/dom/document_cache.cc +++ b/src/support/dom/document_cache.cc @@ -1,5 +1,7 @@ #include "document_cache.h" +#include + namespace InputXSLT { DomDocumentCache::DomDocumentCache(): @@ -16,7 +18,7 @@ DomDocumentCache::item* DomDocumentCache::get(const std::string& key) { if ( result.second ) { return (*(result.first)).second.get(); } else { - return nullptr; + throw std::out_of_range("failed to instantiate DomDocumentCache"); } } else { return (*itemIter).second.get(); diff --git a/src/support/filesystem_context.cc b/src/support/filesystem_context.cc index 34b8950..6ad682f 100644 --- a/src/support/filesystem_context.cc +++ b/src/support/filesystem_context.cc @@ -1,6 +1,18 @@ #include "filesystem_context.h" -#include "support/utility.h" +namespace { + +inline std::string xalanToString(const xalan::XalanDOMString& text) { + xalan::CharVectorType castHelper; + text.transcode(castHelper); + + return std::string( + castHelper.begin(), + castHelper.end() - 1 + ); +} + +} namespace InputXSLT { diff --git a/src/support/utility.h b/src/support/utility.h deleted file mode 100644 index 4c63c72..0000000 --- a/src/support/utility.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef INPUTXSLT_SRC_SUPPORT_UTILITY_H_ -#define INPUTXSLT_SRC_SUPPORT_UTILITY_H_ - -namespace { - -inline std::string xalanToString(const xalan::XalanDOMString& text) { - xalan::CharVectorType castHelper; - text.transcode(castHelper); - - return std::string( - castHelper.begin(), - castHelper.end() - 1 - ); -} - -} - -#endif // INPUTXSLT_SRC_SUPPORT_UTILITY_H_ -- cgit v1.2.3