aboutsummaryrefslogtreecommitdiff
path: root/src/function/read_file.cc
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-05 20:42:36 +0200
committerAdrian Kummerländer2014-05-05 20:42:36 +0200
commit9aad4dffd9c8b0fde534b3abc3c27875547423fa (patch)
treeefe5f9af32f9854c6bc7f2caed3c01a4369ca41e /src/function/read_file.cc
parentbd24e3fe6335bc776400be6bcb44a0701ecc4133 (diff)
downloadInputXSLT-9aad4dffd9c8b0fde534b3abc3c27875547423fa.tar
InputXSLT-9aad4dffd9c8b0fde534b3abc3c27875547423fa.tar.gz
InputXSLT-9aad4dffd9c8b0fde534b3abc3c27875547423fa.tar.bz2
InputXSLT-9aad4dffd9c8b0fde534b3abc3c27875547423fa.tar.lz
InputXSLT-9aad4dffd9c8b0fde534b3abc3c27875547423fa.tar.xz
InputXSLT-9aad4dffd9c8b0fde534b3abc3c27875547423fa.tar.zst
InputXSLT-9aad4dffd9c8b0fde534b3abc3c27875547423fa.zip
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
Diffstat (limited to 'src/function/read_file.cc')
-rw-r--r--src/function/read_file.cc65
1 files changed, 6 insertions, 59 deletions
diff --git a/src/function/read_file.cc b/src/function/read_file.cc
index ba94909..439d905 100644
--- a/src/function/read_file.cc
+++ b/src/function/read_file.cc
@@ -8,12 +8,9 @@
#include "boost/filesystem/fstream.hpp"
#include "support/xerces_string_guard.h"
-#include "support/filesystem_context.h"
namespace {
-using InputXSLT::XercesStringGuard;
-
inline std::string readFile(const boost::filesystem::path& filePath) {
boost::filesystem::ifstream file(filePath);
@@ -23,7 +20,12 @@ inline std::string readFile(const boost::filesystem::path& filePath) {
);
}
-xercesc::DOMDocument* constructDocument(
+}
+
+namespace InputXSLT {
+
+xercesc::DOMDocument* FunctionReadFile::constructDocument(
+ const FilesystemContext&,
const boost::filesystem::path& filePath
) {
xercesc::DOMDocument* const domDocument(
@@ -68,58 +70,3 @@ xercesc::DOMDocument* constructDocument(
}
}
-
-namespace InputXSLT {
-
-FunctionReadFile::FunctionReadFile():
- document_cache_(std::make_shared<DomDocumentCache>()) { }
-
-xalan::XObjectPtr FunctionReadFile::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);
-}
-
-FunctionReadFile* FunctionReadFile::clone(
- xalan::MemoryManager& manager) const {
- return xalan::XalanCopyConstruct(manager, *this);
-}
-
-const xalan::XalanDOMString& FunctionReadFile::getError(
- xalan::XalanDOMString& result) const {
- result.assign("The read-file() function expects one argument of type string.");
-
- return result;
-}
-
-}