From 34b2f97ac57489d7c9555a3cb0c92c808a4948ea Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Tue, 22 Apr 2014 22:49:56 +0200 Subject: Implemented basic XML output of external read-directory function * output is generated from XML hand-generated in a std::stringstream ** while this works reasonably well it is not how it should by done, i.e. this will have to be reimplemented using xerces / xalan constructs ** => this is intended to try out how a read-directory could work in a XSLT context --- src/function/read_directory.cc | 24 +++++++++++++++++------- src/function/read_directory.h | 4 ++++ 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'src/function') diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc index 7b73526..213ef68 100644 --- a/src/function/read_directory.cc +++ b/src/function/read_directory.cc @@ -1,11 +1,16 @@ #include "read_directory.h" -#include +#include namespace InputXSLT { FunctionReadDirectory::FunctionReadDirectory(const FilesystemContext& context): - fs_context_(context) { } + fs_context_(context), + parser_() { } + +FunctionReadDirectory::FunctionReadDirectory(const FunctionReadDirectory& src): + fs_context_(src.fs_context_), + parser_() { } xalan::XObjectPtr FunctionReadDirectory::execute( xalan::XPathExecutionContext& executionContext, @@ -21,16 +26,21 @@ xalan::XObjectPtr FunctionReadDirectory::execute( this->generalError(executionContext, context, locator); } - std::string files; + std::stringstream stream; + stream << ""; this->fs_context_.iterate( arguments[0]->str(), - [&files](const boost::filesystem::path& p) { - files += p.string() + "\n"; + [&stream](const boost::filesystem::path& p) { + stream << "" << p.filename().string() << ""; }); - return executionContext.getXObjectFactory().createString( - xalan::XalanDOMString(files.data()) + stream << ""; + + return executionContext.getXObjectFactory().createNodeSet( + this->parser_.parseXMLStream( + xalan::XSLTInputSource(stream) + ) ); } diff --git a/src/function/read_directory.h b/src/function/read_directory.h index 4a865f2..e7ee0c4 100644 --- a/src/function/read_directory.h +++ b/src/function/read_directory.h @@ -6,6 +6,8 @@ #include #include +#include + #include #include "common.h" @@ -16,6 +18,7 @@ namespace InputXSLT { class FunctionReadDirectory : public xalan::Function { public: FunctionReadDirectory(const FilesystemContext&); + FunctionReadDirectory(const FunctionReadDirectory&); virtual xalan::XObjectPtr execute( xalan::XPathExecutionContext&, @@ -31,6 +34,7 @@ class FunctionReadDirectory : public xalan::Function { private: const FilesystemContext& fs_context_; + mutable xalan::XercesParserLiaison parser_; const xalan::XalanDOMString& getError(xalan::XalanDOMString&) const; -- cgit v1.2.3