aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dummy/transform.xsl34
-rw-r--r--src/function/read_directory.cc100
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(