diff options
author | Adrian Kummerländer | 2014-04-24 21:59:46 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-04-24 21:59:46 +0200 |
commit | ff92d0af44fa454d066f6ee3fe2becd97206b64e (patch) | |
tree | b9998826d95e85bf3f09104234f0ef8fa7bba2de | |
parent | a31fc1169edb33126242eb035dc038cbdea407e8 (diff) | |
download | InputXSLT-ff92d0af44fa454d066f6ee3fe2becd97206b64e.tar InputXSLT-ff92d0af44fa454d066f6ee3fe2becd97206b64e.tar.gz InputXSLT-ff92d0af44fa454d066f6ee3fe2becd97206b64e.tar.bz2 InputXSLT-ff92d0af44fa454d066f6ee3fe2becd97206b64e.tar.lz InputXSLT-ff92d0af44fa454d066f6ee3fe2becd97206b64e.tar.xz InputXSLT-ff92d0af44fa454d066f6ee3fe2becd97206b64e.tar.zst InputXSLT-ff92d0af44fa454d066f6ee3fe2becd97206b64e.zip |
Expanded FunctionReadDirectory class to return files and directories
* they are marked appropriately by a _type_ attribute
-rw-r--r-- | dummy/transform.xsl | 2 | ||||
-rw-r--r-- | src/function/read_directory.cc | 26 | ||||
-rw-r--r-- | src/support/filesystem_context.cc | 3 | ||||
-rw-r--r-- | src/transformation_facade.cc | 1 | ||||
-rw-r--r-- | 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 @@ </xsl:for-each> </ul> <ul id="filelist"> - <xsl:for-each select="external:read-directory('.')/content/file"> + <xsl:for-each select="external:read-directory('.')/content/item[@type='file']"> <li><xsl:value-of select="."/></li> </xsl:for-each> </ul> 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 <string> - #include <xalanc/XalanTransformer/XalanTransformer.hpp> -#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp> + +#include <string> #include "common.h" #include "support/filesystem_context.h" |