aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/function/base.h89
-rw-r--r--src/function/read_directory.cc62
-rw-r--r--src/function/read_directory.h35
-rw-r--r--src/function/read_file.cc65
-rw-r--r--src/function/read_file.h35
-rw-r--r--src/function/read_xml_file.cc63
-rw-r--r--src/function/read_xml_file.h36
7 files changed, 130 insertions, 255 deletions
diff --git a/src/function/base.h b/src/function/base.h
new file mode 100644
index 0000000..231800d
--- /dev/null
+++ b/src/function/base.h
@@ -0,0 +1,89 @@
+#ifndef INPUTXSLT_SRC_FUNCTION_BASE_H_
+#define INPUTXSLT_SRC_FUNCTION_BASE_H_
+
+#include <xalanc/XalanTransformer/XalanTransformer.hpp>
+#include <xalanc/XPath/XObjectFactory.hpp>
+#include <xalanc/XPath/Function.hpp>
+#include <xalanc/XPath/XObject.hpp>
+
+#include <memory>
+
+#include "common.h"
+#include "support/dom/document_cache.h"
+#include "support/filesystem_context.h"
+
+namespace InputXSLT {
+
+template <class Implementation>
+class FunctionBase : public xalan::Function {
+ public:
+ FunctionBase():
+ document_cache_(std::make_shared<DomDocumentCache>()) { }
+
+ virtual xalan::XObjectPtr execute(
+ xalan::XPathExecutionContext& executionContext,
+ xalan::XalanNode*,
+ const xalan::XObjectPtr argument,
+ const xalan::Locator* locator
+ ) const {
+ const FilesystemContext fsContext(locator);
+
+ const boost::filesystem::path argumentPath(
+ fsContext.resolve(argument->str())
+ );
+
+ DomDocumentCache::optional_item optionalCachedDocument(
+ this->document_cache_->get(argumentPath.string())
+ );
+
+ if ( !optionalCachedDocument.first ) {
+ optionalCachedDocument = this->document_cache_->create(
+ argumentPath.string(),
+ static_cast<Implementation*>(
+ const_cast<FunctionBase*>(this)
+ )->constructDocument(
+ fsContext,
+ argumentPath
+ )
+ );
+ }
+
+ xalan::XPathExecutionContext::BorrowReturnMutableNodeRefList nodeList(
+ executionContext
+ );
+
+ nodeList->addNodes(
+ *optionalCachedDocument.second->getXalanDocument()
+ ->getDocumentElement()
+ ->getChildNodes()
+ );
+
+ return executionContext.getXObjectFactory().createNodeSet(nodeList);
+ }
+
+ virtual FunctionBase* clone(
+ xalan::MemoryManager& manager) const {
+ return xalan::XalanCopyConstruct(
+ manager,
+ static_cast<const Implementation&>(*this)
+ );
+ }
+
+ FunctionBase& operator=(const FunctionBase&) = delete;
+ bool operator==(const FunctionBase&) const = delete;
+
+ protected:
+ std::shared_ptr<DomDocumentCache> document_cache_;
+
+ const xalan::XalanDOMString& getError(
+ xalan::XalanDOMString& result) const {
+ result.assign("The function expects one argument of type string.");
+
+ return result;
+ }
+
+};
+
+}
+
+#endif // INPUTXSLT_SRC_FUNCTION_BASE_H_
diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc
index 48ffa51..8b41dae 100644
--- a/src/function/read_directory.cc
+++ b/src/function/read_directory.cc
@@ -6,13 +6,10 @@
#include <xercesc/dom/DOMText.hpp>
#include "support/xerces_string_guard.h"
-#include "support/filesystem_context.h"
-namespace {
-
-using InputXSLT::XercesStringGuard;
+namespace InputXSLT {
-xercesc::DOMDocument* constructDocument(
+xercesc::DOMDocument* FunctionReadDirectory::constructDocument(
const InputXSLT::FilesystemContext& fsContext,
const boost::filesystem::path& directoryPath
) {
@@ -84,58 +81,3 @@ xercesc::DOMDocument* constructDocument(
}
}
-
-namespace InputXSLT {
-
-FunctionReadDirectory::FunctionReadDirectory():
- document_cache_(std::make_shared<DomDocumentCache>()) { }
-
-xalan::XObjectPtr FunctionReadDirectory::execute(
- xalan::XPathExecutionContext& executionContext,
- xalan::XalanNode*,
- const xalan::XObjectPtr argument,
- const xalan::Locator* locator
-) const {
- const FilesystemContext fsContext(locator);
-
- const boost::filesystem::path directoryPath(
- fsContext.resolve(argument->str())
- );
-
- DomDocumentCache::optional_item optionalCachedDocument(
- this->document_cache_->get(directoryPath.string())
- );
-
- if ( !optionalCachedDocument.first ) {
- optionalCachedDocument = this->document_cache_->create(
- directoryPath.string(),
- constructDocument(fsContext, directoryPath)
- );
- }
-
- xalan::XPathExecutionContext::BorrowReturnMutableNodeRefList nodeList(
- executionContext
- );
-
- nodeList->addNodes(
- *optionalCachedDocument.second->getXalanDocument()
- ->getDocumentElement()
- ->getChildNodes()
- );
-
- return executionContext.getXObjectFactory().createNodeSet(nodeList);
-}
-
-FunctionReadDirectory* FunctionReadDirectory::clone(
- xalan::MemoryManager& manager) const {
- return xalan::XalanCopyConstruct(manager, *this);
-}
-
-const xalan::XalanDOMString& FunctionReadDirectory::getError(
- xalan::XalanDOMString& result) const {
- result.assign("The read-directory() function expects one argument of type string.");
-
- return result;
-}
-
-}
diff --git a/src/function/read_directory.h b/src/function/read_directory.h
index 02a0305..2c28642 100644
--- a/src/function/read_directory.h
+++ b/src/function/read_directory.h
@@ -1,38 +1,21 @@
#ifndef INPUTXSLT_SRC_FUNCTION_READ_DIRECTORY_H_
#define INPUTXSLT_SRC_FUNCTION_READ_DIRECTORY_H_
-#include <xalanc/XalanTransformer/XalanTransformer.hpp>
-#include <xalanc/XPath/XObjectFactory.hpp>
-#include <xalanc/XPath/Function.hpp>
-#include <xalanc/XPath/XObject.hpp>
-
-#include <memory>
-
-#include "common.h"
-#include "support/dom/document_cache.h"
+#include "base.h"
namespace InputXSLT {
-class FunctionReadDirectory : public xalan::Function {
+class FunctionReadDirectory : public FunctionBase<FunctionReadDirectory> {
public:
- FunctionReadDirectory();
-
- virtual xalan::XObjectPtr execute(
- xalan::XPathExecutionContext&,
- xalan::XalanNode*,
- const xalan::XObjectPtr,
- const xalan::Locator*
- ) const;
-
- virtual FunctionReadDirectory* clone(xalan::MemoryManager&) const;
-
- FunctionReadDirectory& operator=(const FunctionReadDirectory&) = delete;
- bool operator==(const FunctionReadDirectory&) const = delete;
+ using FunctionBase<FunctionReadDirectory>::FunctionBase;
- private:
- std::shared_ptr<DomDocumentCache> document_cache_;
+ protected:
+ friend FunctionBase<FunctionReadDirectory>;
- const xalan::XalanDOMString& getError(xalan::XalanDOMString&) const;
+ xercesc::DOMDocument* constructDocument(
+ const FilesystemContext&,
+ const boost::filesystem::path&
+ );
};
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;
-}
-
-}
diff --git a/src/function/read_file.h b/src/function/read_file.h
index 65746a5..fd36847 100644
--- a/src/function/read_file.h
+++ b/src/function/read_file.h
@@ -1,38 +1,21 @@
#ifndef INPUTXSLT_SRC_FUNCTION_READ_FILE_H_
#define INPUTXSLT_SRC_FUNCTION_READ_FILE_H_
-#include <xalanc/XalanTransformer/XalanTransformer.hpp>
-#include <xalanc/XPath/XObjectFactory.hpp>
-#include <xalanc/XPath/Function.hpp>
-#include <xalanc/XPath/XObject.hpp>
-
-#include <string>
-
-#include "common.h"
-#include "support/dom/document_cache.h"
+#include "base.h"
namespace InputXSLT {
-class FunctionReadFile : public xalan::Function {
+class FunctionReadFile : public FunctionBase<FunctionReadFile> {
public:
- FunctionReadFile();
-
- virtual xalan::XObjectPtr execute(
- xalan::XPathExecutionContext&,
- xalan::XalanNode*,
- const xalan::XObjectPtr,
- const xalan::Locator*
- ) const;
-
- virtual FunctionReadFile* clone(xalan::MemoryManager&) const;
-
- FunctionReadFile& operator=(const FunctionReadFile&) = delete;
- bool operator==(const FunctionReadFile&) const = delete;
+ using FunctionBase<FunctionReadFile>::FunctionBase;
- private:
- std::shared_ptr<DomDocumentCache> document_cache_;
+ protected:
+ friend FunctionBase<FunctionReadFile>;
- const xalan::XalanDOMString& getError(xalan::XalanDOMString&) const;
+ xercesc::DOMDocument* constructDocument(
+ const FilesystemContext&,
+ const boost::filesystem::path&
+ );
};
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<DomDocumentCache>()) { }
-
-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;
-}
-
-}
diff --git a/src/function/read_xml_file.h b/src/function/read_xml_file.h
index d7ef440..5314b4a 100644
--- a/src/function/read_xml_file.h
+++ b/src/function/read_xml_file.h
@@ -1,39 +1,21 @@
#ifndef INPUTXSLT_SRC_FUNCTION_READ_XML_FILE_H_
#define INPUTXSLT_SRC_FUNCTION_READ_XML_FILE_H_
-#include <xalanc/XalanTransformer/XalanTransformer.hpp>
-#include <xalanc/XPath/XObjectFactory.hpp>
-#include <xalanc/XPath/Function.hpp>
-#include <xalanc/XPath/XObject.hpp>
-
-#include <string>
-#include <memory>
-
-#include "common.h"
-#include "support/dom/document_cache.h"
+#include "base.h"
namespace InputXSLT {
-class FunctionReadXmlFile : public xalan::Function {
+class FunctionReadXmlFile : public FunctionBase<FunctionReadXmlFile> {
public:
- FunctionReadXmlFile();
-
- virtual xalan::XObjectPtr execute(
- xalan::XPathExecutionContext&,
- xalan::XalanNode*,
- const xalan::XObjectPtr,
- const xalan::Locator*
- ) const;
-
- virtual FunctionReadXmlFile* clone(xalan::MemoryManager&) const;
-
- FunctionReadXmlFile& operator=(const FunctionReadXmlFile&) = delete;
- bool operator==(const FunctionReadXmlFile&) const = delete;
+ using FunctionBase<FunctionReadXmlFile>::FunctionBase;
- private:
- std::shared_ptr<DomDocumentCache> document_cache_;
+ protected:
+ friend FunctionBase<FunctionReadXmlFile>;
- const xalan::XalanDOMString& getError(xalan::XalanDOMString& result) const;
+ xercesc::DOMDocument* constructDocument(
+ const FilesystemContext&,
+ const boost::filesystem::path&
+ );
};