From ff92d0af44fa454d066f6ee3fe2becd97206b64e Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Thu, 24 Apr 2014 21:59:46 +0200 Subject: Expanded FunctionReadDirectory class to return files and directories * they are marked appropriately by a _type_ attribute --- dummy/transform.xsl | 2 +- src/function/read_directory.cc | 26 ++++++++++++++++++++++---- src/support/filesystem_context.cc | 3 ++- src/transformation_facade.cc | 1 - src/transformation_facade.h | 5 ++--- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/dummy/transform.xsl b/dummy/transform.xsl index 6dc45dc..95467ca 100644 --- a/dummy/transform.xsl +++ b/dummy/transform.xsl @@ -24,7 +24,7 @@ diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc index 0ed33bc..22653b6 100644 --- a/src/function/read_directory.cc +++ b/src/function/read_directory.cc @@ -34,16 +34,34 @@ xalan::XObjectPtr FunctionReadDirectory::execute( this->fs_context_.iterate( arguments[0]->str(), [&domDocument, &rootNode](const boost::filesystem::path& p) { - XMLCh* buffer = xercesc::XMLString::transcode("file"); - xercesc::DOMNode* const fileNode = domDocument->createElement(buffer); + XMLCh* buffer = xercesc::XMLString::transcode("item"); + xercesc::DOMElement* const itemNode = domDocument->createElement(buffer); + xercesc::XMLString::release(&buffer); + + buffer = xercesc::XMLString::transcode("type"); + + if ( boost::filesystem::is_regular_file(p) ) { + XMLCh* valueBuffer = xercesc::XMLString::transcode("file"); + + itemNode->setAttribute(buffer, valueBuffer); + + xercesc::XMLString::release(&valueBuffer); + } else if ( boost::filesystem::is_directory(p) ) { + XMLCh* valueBuffer = xercesc::XMLString::transcode("directory"); + + itemNode->setAttribute(buffer, valueBuffer); + + xercesc::XMLString::release(&valueBuffer); + } + xercesc::XMLString::release(&buffer); buffer = xercesc::XMLString::transcode(p.filename().string().data()); xercesc::DOMText* const textNode = domDocument->createTextNode(buffer); xercesc::XMLString::release(&buffer); - fileNode->appendChild(textNode); - rootNode->appendChild(fileNode); + itemNode->appendChild(textNode); + rootNode->appendChild(itemNode); }); return executionContext.getXObjectFactory().createNodeSet( diff --git a/src/support/filesystem_context.cc b/src/support/filesystem_context.cc index d0813c2..baeccf3 100644 --- a/src/support/filesystem_context.cc +++ b/src/support/filesystem_context.cc @@ -40,7 +40,8 @@ void FilesystemContext::iterate( for ( boost::filesystem::directory_iterator iter(directory); iter != boost::filesystem::directory_iterator(); ++iter ) { - if ( boost::filesystem::is_regular_file(iter->status()) ) { + if ( boost::filesystem::is_regular_file(iter->status()) || + boost::filesystem::is_directory(iter->status()) ) { func(*iter); } } diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc index 58bdb52..19f7772 100644 --- a/src/transformation_facade.cc +++ b/src/transformation_facade.cc @@ -9,7 +9,6 @@ #include "function/read_xml_file.h" #include "function/read_directory.h" - namespace InputXSLT { TransformationFacade::TransformationFacade(const std::string& transformation): diff --git a/src/transformation_facade.h b/src/transformation_facade.h index 715d72e..765a376 100644 --- a/src/transformation_facade.h +++ b/src/transformation_facade.h @@ -1,10 +1,9 @@ #ifndef INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_ #define INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_ -#include - #include -#include + +#include #include "common.h" #include "support/filesystem_context.h" -- cgit v1.2.3