diff options
author | Adrian Kummerländer | 2014-04-26 22:07:13 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-04-26 22:07:13 +0200 |
commit | 5fde046561caa11a58abd13cf1f469fdce5c53f1 (patch) | |
tree | 859b095235b093b448ac5c33aaa5e456d62c984a /src | |
parent | eba5513f82f0e1458543e8646db0317d7211cf96 (diff) | |
download | InputXSLT-5fde046561caa11a58abd13cf1f469fdce5c53f1.tar InputXSLT-5fde046561caa11a58abd13cf1f469fdce5c53f1.tar.gz InputXSLT-5fde046561caa11a58abd13cf1f469fdce5c53f1.tar.bz2 InputXSLT-5fde046561caa11a58abd13cf1f469fdce5c53f1.tar.lz InputXSLT-5fde046561caa11a58abd13cf1f469fdce5c53f1.tar.xz InputXSLT-5fde046561caa11a58abd13cf1f469fdce5c53f1.tar.zst InputXSLT-5fde046561caa11a58abd13cf1f469fdce5c53f1.zip |
Added status information to external read-directory function
* updated test transformation accordingly
Diffstat (limited to 'src')
-rw-r--r-- | src/function/read_directory.cc | 100 |
1 files changed, 68 insertions, 32 deletions
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( |