diff options
author | Adrian Kummerländer | 2014-04-21 21:47:20 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-04-21 21:47:20 +0200 |
commit | 7142544d43b431df44d34921b0f3012fa1e0137d (patch) | |
tree | 5fb5de3222d25f0e48f24a0dbdd0d18f5d917c89 /src/function | |
parent | cdf4ad3486debe75fe89b2f04bb62541f3ac8405 (diff) | |
download | InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.tar InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.tar.gz InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.tar.bz2 InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.tar.lz InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.tar.xz InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.tar.zst InputXSLT-7142544d43b431df44d34921b0f3012fa1e0137d.zip |
Implemented basic external directory traversal function
* _read-directory_ lists all files in a given directory
** currently text-only output, xml planned
* improved FilesystemContext path resolution (relative path is fully resolved by boost::filesystem)
Diffstat (limited to 'src/function')
-rw-r--r-- | src/function/read_directory.cc | 49 | ||||
-rw-r--r-- | src/function/read_directory.h | 41 |
2 files changed, 90 insertions, 0 deletions
diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc new file mode 100644 index 0000000..7b73526 --- /dev/null +++ b/src/function/read_directory.cc @@ -0,0 +1,49 @@ +#include "read_directory.h" + +#include <iostream> + +namespace InputXSLT { + +FunctionReadDirectory::FunctionReadDirectory(const FilesystemContext& context): + fs_context_(context) { } + +xalan::XObjectPtr FunctionReadDirectory::execute( + xalan::XPathExecutionContext& executionContext, + xalan::XalanNode* context, + const xalan::Function::XObjectArgVectorType& arguments, + const xalan::Locator* locator +) const { + if ( arguments.size() != 1 ) { + xalan::XPathExecutionContext::GetAndReleaseCachedString guard( + executionContext + ); + + this->generalError(executionContext, context, locator); + } + + std::string files; + + this->fs_context_.iterate( + arguments[0]->str(), + [&files](const boost::filesystem::path& p) { + files += p.string() + "\n"; + }); + + return executionContext.getXObjectFactory().createString( + xalan::XalanDOMString(files.data()) + ); +} + +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."); + + return result; +} + +} diff --git a/src/function/read_directory.h b/src/function/read_directory.h new file mode 100644 index 0000000..4a865f2 --- /dev/null +++ b/src/function/read_directory.h @@ -0,0 +1,41 @@ +#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 <string> + +#include "common.h" +#include "support/filesystem_context.h" + +namespace InputXSLT { + +class FunctionReadDirectory : public xalan::Function { + public: + FunctionReadDirectory(const FilesystemContext&); + + virtual xalan::XObjectPtr execute( + xalan::XPathExecutionContext&, + xalan::XalanNode*, + const xalan::Function::XObjectArgVectorType&, + const xalan::Locator* + ) const; + + virtual FunctionReadDirectory* clone(xalan::MemoryManager&) const; + + FunctionReadDirectory& operator=(const FunctionReadDirectory&) = delete; + bool operator==(const FunctionReadDirectory&) const = delete; + + private: + const FilesystemContext& fs_context_; + + const xalan::XalanDOMString& getError(xalan::XalanDOMString&) const; + +}; + +} + +#endif // INPUTXSLT_SRC_FUNCTION_READ_DIRECTORY_H_ |