From 9aad4dffd9c8b0fde534b3abc3c27875547423fa Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Mon, 5 May 2014 20:42:36 +0200 Subject: Encapsulated common parts of external function inplementations * common parts were moved into CRTP template base class _FunctionBase_ * all external functions are derived from that class ** only have to implement _constructDocument_ member method ** currently only supports a single string input parameter which is enough for now * this change condenses external funtion implementations to the essential and should increase readability as well as maintainability --- src/function/read_xml_file.cc | 63 +++++-------------------------------------- 1 file changed, 6 insertions(+), 57 deletions(-) (limited to 'src/function/read_xml_file.cc') diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc index a4e3e3c..71ba819 100644 --- a/src/function/read_xml_file.cc +++ b/src/function/read_xml_file.cc @@ -9,7 +9,6 @@ #include "boost/filesystem/fstream.hpp" #include "support/xerces_string_guard.h" -#include "support/filesystem_context.h" namespace { @@ -29,7 +28,12 @@ inline xercesc::DOMNode* importDocumentElement( ); } -xercesc::DOMDocument* constructDocument( +} + +namespace InputXSLT { + +xercesc::DOMDocument* FunctionReadXmlFile::constructDocument( + const FilesystemContext&, const boost::filesystem::path& filePath ) { xercesc::DOMDocument* const domDocument( @@ -72,58 +76,3 @@ xercesc::DOMDocument* constructDocument( } } - -namespace InputXSLT { - -FunctionReadXmlFile::FunctionReadXmlFile(): - document_cache_(std::make_shared()) { } - -xalan::XObjectPtr FunctionReadXmlFile::execute( - xalan::XPathExecutionContext& executionContext, - xalan::XalanNode*, - const xalan::XObjectPtr argument, - const xalan::Locator* locator -) const { - const FilesystemContext fsContext(locator); - - const boost::filesystem::path filePath( - fsContext.resolve(argument->str()) - ); - - DomDocumentCache::optional_item optionalCachedDocument( - this->document_cache_->get(filePath.string()) - ); - - if ( !optionalCachedDocument.first ) { - optionalCachedDocument = this->document_cache_->create( - filePath.string(), - constructDocument(filePath) - ); - } - - xalan::XPathExecutionContext::BorrowReturnMutableNodeRefList nodeList( - executionContext - ); - - nodeList->addNodes( - *optionalCachedDocument.second->getXalanDocument() - ->getDocumentElement() - ->getChildNodes() - ); - - return executionContext.getXObjectFactory().createNodeSet(nodeList); -} - -FunctionReadXmlFile* FunctionReadXmlFile::clone( - xalan::MemoryManager& manager) const { - return xalan::XalanCopyConstruct(manager, *this); -} - -const xalan::XalanDOMString& FunctionReadXmlFile::getError( - xalan::XalanDOMString& result) const { - result.assign("The read-xml-file() function expects one argument of type string."); - - return result; -} - -} -- cgit v1.2.3