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 | |
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
-rw-r--r-- | dummy/transform.xsl | 34 | ||||
-rw-r--r-- | 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 @@ <xsl:value-of select="$testFile/self::content"/> </xsl:when> <xsl:otherwise> - Failed to read test.txt + Could not read file. </xsl:otherwise> </xsl:choose> </div> + <ul id="xml"> <xsl:for-each select="external:read-xml-file('test.txt')/tester/eintrag"> <li><xsl:value-of select="."/></li> </xsl:for-each> </ul> - <ul id="filelist1"> - <xsl:for-each select="external:read-directory('../')[@type='file']"> - <li><xsl:value-of select="."/></li> - </xsl:for-each> - </ul> - <ul id="filelist2"> - <xsl:for-each select="external:read-directory('../')[@type='directory']"> - <li><xsl:value-of select="."/></li> - </xsl:for-each> - </ul> + + <div id="filelists"> + <xsl:variable name="fileList" select="external:read-directory('../')"/> + <xsl:choose> + <xsl:when test="$fileList/self::status = 'successful'"> + <ul id="filelist1"> + <xsl:for-each select="$fileList/self::content/item[@type='file']"> + <li><xsl:value-of select="."/></li> + </xsl:for-each> + </ul> + <ul id="filelist2"> + <xsl:for-each select="$fileList/self::content/item[@type='directory']"> + <li><xsl:value-of select="."/></li> + </xsl:for-each> + </ul> + </xsl:when> + <xsl:otherwise> + Could not read directory. + </xsl:otherwise> + </xsl:choose> + </div> </body> </html> </xsl:template> 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( |