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 --- src/function/read_directory.cc | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/function') 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( -- cgit v1.2.3