From 5fde046561caa11a58abd13cf1f469fdce5c53f1 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Sat, 26 Apr 2014 22:07:13 +0200 Subject: Added status information to external read-directory function * updated test transformation accordingly --- dummy/transform.xsl | 34 +++++++++----- src/function/read_directory.cc | 100 ++++++++++++++++++++++++++++------------- 2 files changed, 91 insertions(+), 43 deletions(-) diff --git a/dummy/transform.xsl b/dummy/transform.xsl index 323ecdb..fc6c15b 100644 --- a/dummy/transform.xsl +++ b/dummy/transform.xsl @@ -24,25 +24,37 @@ - Failed to read test.txt + Could not read file. + - - + +
+ + + +
    + +
  • +
    +
+
    + +
  • +
    +
+
+ + Could not read directory. + +
+
diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc index 3f503b3..1e7e7d7 100644 --- a/src/function/read_directory.cc +++ b/src/function/read_directory.cc @@ -34,44 +34,80 @@ xalan::XObjectPtr FunctionReadDirectory::execute( domDocument->getDocumentElement() ); - this->fs_context_.iterate( - argument->str(), - [&domDocument, &rootNode](const boost::filesystem::path& p) { - xercesc::DOMElement* const itemNode( - domDocument->createElement(*XercesStringGuard("item")) + if (boost::filesystem::is_directory( + this->fs_context_.resolve(argument->str()) + )) { + xercesc::DOMElement* const contentNode( + domDocument->createElement(*XercesStringGuard("content")) ); - switch ( boost::filesystem::status(p).type() ) { - case boost::filesystem::regular_file: { - itemNode->setAttribute( - *XercesStringGuard("type"), - *XercesStringGuard("file") - ); - - break; - }; - case boost::filesystem::directory_file: { - itemNode->setAttribute( - *XercesStringGuard("type"), - *XercesStringGuard("directory") - ); - - break; - }; - default: { - break; - }; - } - - xercesc::DOMText* const textNode( + this->fs_context_.iterate( + argument->str(), + [&domDocument, &contentNode](const boost::filesystem::path& p) { + xercesc::DOMElement* const itemNode( + domDocument->createElement(*XercesStringGuard("item")) + ); + + switch ( boost::filesystem::status(p).type() ) { + case boost::filesystem::regular_file: { + itemNode->setAttribute( + *XercesStringGuard("type"), + *XercesStringGuard("file") + ); + + break; + }; + case boost::filesystem::directory_file: { + itemNode->setAttribute( + *XercesStringGuard("type"), + *XercesStringGuard("directory") + ); + + break; + }; + default: { + break; + }; + } + + xercesc::DOMText* const textNode( + domDocument->createTextNode( + *XercesStringGuard(p.filename().string()) + ) + ); + + itemNode->appendChild(textNode); + contentNode->appendChild(itemNode); + }); + + xercesc::DOMElement* const resultNode( + domDocument->createElement(*XercesStringGuard("status")) + ); + + xercesc::DOMText* const resultTextNode( + domDocument->createTextNode( + *XercesStringGuard("successful") + ) + ); + + resultNode->appendChild(resultTextNode); + + rootNode->appendChild(contentNode); + rootNode->appendChild(resultNode); + } else { + xercesc::DOMElement* const resultNode( + domDocument->createElement(*XercesStringGuard("status")) + ); + + xercesc::DOMText* const resultTextNode( domDocument->createTextNode( - *XercesStringGuard(p.filename().string()) + *XercesStringGuard("error") ) ); - itemNode->appendChild(textNode); - rootNode->appendChild(itemNode); - }); + resultNode->appendChild(resultTextNode); + rootNode->appendChild(resultNode); + } } xalan::XPathExecutionContext::BorrowReturnMutableNodeRefList nodeList( -- cgit v1.2.3