aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/function/external_text_formatter.cc17
-rw-r--r--src/function/read_directory.cc13
-rw-r--r--src/function/read_file.cc8
-rw-r--r--src/function/read_xml_file.cc9
-rw-r--r--src/function/transform.cc8
-rw-r--r--src/support/dom/result_node_facade.cc11
-rw-r--r--src/support/dom/result_node_facade.h4
-rw-r--r--test/external_text_formatter/transformation.xsl19
-rw-r--r--test/read_directory/transformation.xsl30
-rw-r--r--test/read_file/transformation.xsl16
-rw-r--r--test/read_xml_file/transformation.xsl20
-rw-r--r--test/transform/transformation.xsl8
12 files changed, 121 insertions, 42 deletions
diff --git a/src/function/external_text_formatter.cc b/src/function/external_text_formatter.cc
index d1b9e92..22f53c5 100644
--- a/src/function/external_text_formatter.cc
+++ b/src/function/external_text_formatter.cc
@@ -86,17 +86,20 @@ xercesc::DOMDocument* FunctionExternalTextFormatter::constructDocument(
boost::process::status status = formatterProcess.wait();
- if ( status.exited() ) {
- ResultNodeFacade result(domDocument, rootNode, "result");
+ ResultNodeFacade result(domDocument, rootNode, "output");
+ result.setAttribute("formatter", formatterPath);
+ result.setAttribute("code", std::to_string(status.exit_status()));
- result.setValueNode("code", std::to_string(status.exit_status()));
- result.setContent(importDocumentElement(outputStream, domDocument));
+ if ( status.exited() ) {
+ result.setAttribute("result", "success");
+ result.setContent(
+ importDocumentElement(outputStream, domDocument)->getChildNodes()
+ );
} else {
- ResultNodeFacade result(domDocument, rootNode, "error");
-
- result.setValueNode("code", std::to_string(status.exit_status()));
+ result.setAttribute("result", "error");
}
+
return domDocument;
}
diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc
index f4baff6..e54e146 100644
--- a/src/function/read_directory.cc
+++ b/src/function/read_directory.cc
@@ -29,11 +29,18 @@ xercesc::DOMDocument* FunctionReadDirectory::constructDocument(
domDocument->getDocumentElement()
);
+ ResultNodeFacade result(domDocument, rootNode, "directory");
+ result.setAttribute("path", directoryPath.string());
+
if ( boost::filesystem::is_directory(directoryPath) ) {
+ result.setAttribute("result", "success");
+
+ xercesc::DOMNode* const resultNode = result.getNode();
+
fsContext.iterate(
directoryPath,
- [&domDocument, &rootNode](const boost::filesystem::path& p) {
- ResultNodeFacade result(domDocument, rootNode, "result");
+ [&domDocument, &resultNode](const boost::filesystem::path& p) {
+ ResultNodeFacade result(domDocument, resultNode, "entry");
switch ( boost::filesystem::status(p).type() ) {
case boost::filesystem::regular_file: {
@@ -60,7 +67,7 @@ xercesc::DOMDocument* FunctionReadDirectory::constructDocument(
result.setValueNode("full", boost::filesystem::canonical(p).string());
});
} else {
- ResultNodeFacade result(domDocument, rootNode, "error");
+ result.setAttribute("result", "error");
}
return domDocument;
diff --git a/src/function/read_file.cc b/src/function/read_file.cc
index 87423ab..79e321d 100644
--- a/src/function/read_file.cc
+++ b/src/function/read_file.cc
@@ -50,13 +50,15 @@ xercesc::DOMDocument* FunctionReadFile::constructDocument(
domDocument->getDocumentElement()
);
+ ResultNodeFacade result(domDocument, rootNode, "file");
+ result.setAttribute("path", filePath.string());
+
if ( boost::filesystem::is_regular_file(filePath) ) {
- ResultNodeFacade result(domDocument, rootNode, "result");
+ result.setAttribute("result", "success");
- result.setAttribute("name", filePath.filename().string());
result.setContent(readFile(filePath));
} else {
- ResultNodeFacade result(domDocument, rootNode, "error");
+ result.setAttribute("result", "success");
}
return domDocument;
diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc
index 6d0fd04..2fa4f13 100644
--- a/src/function/read_xml_file.cc
+++ b/src/function/read_xml_file.cc
@@ -60,16 +60,17 @@ xercesc::DOMDocument* FunctionReadXmlFile::constructDocument(
domDocument->getDocumentElement()
);
- if ( boost::filesystem::is_regular_file(filePath) ) {
- ResultNodeFacade result(domDocument, rootNode, "result");
+ ResultNodeFacade result(domDocument, rootNode, "file");
+ result.setAttribute("path", filePath.string());
- result.setAttribute("name", filePath.filename().string());
+ if ( boost::filesystem::is_regular_file(filePath) ) {
+ result.setAttribute("result", "success");
result.setContent(
importDocumentElement(filePath, domDocument)
);
} else {
- ResultNodeFacade result(domDocument, rootNode, "error");
+ result.setAttribute("result", "error");
}
return domDocument;
diff --git a/src/function/transform.cc b/src/function/transform.cc
index e952018..ab8c51c 100644
--- a/src/function/transform.cc
+++ b/src/function/transform.cc
@@ -38,8 +38,8 @@ xercesc::DOMDocument* FunctionTransform::constructDocument(
domDocument->getDocumentElement()
);
- ResultNodeFacade result(domDocument, rootNode, "result");
- result.setAttribute("name", targetPath);
+ ResultNodeFacade result(domDocument, rootNode, "transformation");
+ result.setAttribute("target", targetPath);
try {
InputXSLT::TransformationFacade transformation(
@@ -48,8 +48,12 @@ xercesc::DOMDocument* FunctionTransform::constructDocument(
);
transformation.generate(targetPath, parameterObject);
+
+ result.setAttribute("result", "success");
}
catch (const ErrorCapacitor::exception& exception) {
+ result.setAttribute("result", "error");
+
for ( auto&& error : *(exception.getCachedErrors()) ) {
result.setValueNode("error", error);
}
diff --git a/src/support/dom/result_node_facade.cc b/src/support/dom/result_node_facade.cc
index 597448b..eeb2cc6 100644
--- a/src/support/dom/result_node_facade.cc
+++ b/src/support/dom/result_node_facade.cc
@@ -1,6 +1,7 @@
#include "result_node_facade.h"
#include <xercesc/dom/DOMText.hpp>
+#include <xercesc/dom/DOMNodeList.hpp>
#include "support/xerces_string_guard.h"
@@ -21,6 +22,10 @@ ResultNodeFacade::~ResultNodeFacade() {
this->root_node_->appendChild(this->result_node_);
}
+xercesc::DOMNode* ResultNodeFacade::getNode() {
+ return this->result_node_;
+}
+
void ResultNodeFacade::setAttribute(
const std::string& name,
const std::string& value
@@ -58,4 +63,10 @@ void ResultNodeFacade::setContent(xercesc::DOMNode* node) {
this->result_node_->appendChild(node);
}
+void ResultNodeFacade::setContent(xercesc::DOMNodeList* nodes) {
+ for ( std::size_t index = 0; index != nodes->getLength(); ++index ) {
+ this->setContent(nodes->item(index));
+ }
+}
+
}
diff --git a/src/support/dom/result_node_facade.h b/src/support/dom/result_node_facade.h
index ccdd850..bf73582 100644
--- a/src/support/dom/result_node_facade.h
+++ b/src/support/dom/result_node_facade.h
@@ -18,10 +18,14 @@ class ResultNodeFacade {
);
~ResultNodeFacade();
+ xercesc::DOMNode* getNode();
+
void setAttribute(const std::string&, const std::string&);
void setValueNode(const std::string&, const std::string&);
+
void setContent(const std::string&);
void setContent(xercesc::DOMNode*);
+ void setContent(xercesc::DOMNodeList*);
private:
xercesc::DOMDocument* const dom_document_;
diff --git a/test/external_text_formatter/transformation.xsl b/test/external_text_formatter/transformation.xsl
index 00fe3b3..a94f211 100644
--- a/test/external_text_formatter/transformation.xsl
+++ b/test/external_text_formatter/transformation.xsl
@@ -20,13 +20,24 @@
)
</xsl:variable>
- <xsl:copy-of select="dyn:evaluate($command)/output/*"/>
+ <xsl:copy-of select="dyn:evaluate($command)"/>
</xsl:template>
<xsl:template name="implementation">
- <xsl:call-template name="formatter">
- <xsl:with-param name="source" select="InputXSLT:read-file('test.md')"/>
- </xsl:call-template>
+ <xsl:variable name="result">
+ <xsl:call-template name="formatter">
+ <xsl:with-param name="source" select="InputXSLT:read-file('test.md')"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:choose>
+ <xsl:when test="xalan:nodeset($result)/output/@result = 'success'">
+ <xsl:copy-of select="xalan:nodeset($result)/output/*"/>
+ </xsl:when>
+ <xsl:otherwise>
+ Failure during external text formatting
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
</xsl:stylesheet>
diff --git a/test/read_directory/transformation.xsl b/test/read_directory/transformation.xsl
index 9a9a057..f1446a2 100644
--- a/test/read_directory/transformation.xsl
+++ b/test/read_directory/transformation.xsl
@@ -2,22 +2,34 @@
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xalan="http://xml.apache.org/xalan"
xmlns:InputXSLT="function.inputxslt.application"
- exclude-result-prefixes="InputXSLT"
+ exclude-result-prefixes="InputXSLT xalan"
>
<xsl:include href="[testcase.xsl]"/>
<xsl:template name="implementation">
- <xsl:for-each select="InputXSLT:read-directory('../')">
- <item type="{@type}">
- <name><xsl:value-of select="./name"/></name>
+ <xsl:variable name="result">
+ <xsl:copy-of select="InputXSLT:read-directory('../')"/>
+ </xsl:variable>
- <xsl:if test="@type='file' and ./name='check'">
- <extension><xsl:value-of select="./extension"/></extension>
- </xsl:if>
- </item>
- </xsl:for-each>
+ <xsl:choose>
+ <xsl:when test="xalan:nodeset($result)/directory/@result = 'success'">
+ <xsl:for-each select="xalan:nodeset($result)/directory/entry">
+ <item type="{@type}">
+ <name><xsl:value-of select="./name"/></name>
+
+ <xsl:if test="@type='file' and ./name='check'">
+ <extension><xsl:value-of select="./extension"/></extension>
+ </xsl:if>
+ </item>
+ </xsl:for-each>
+ </xsl:when>
+ <xsl:otherwise>
+ Error during directory io
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
</xsl:stylesheet>
diff --git a/test/read_file/transformation.xsl b/test/read_file/transformation.xsl
index f773e0e..9610046 100644
--- a/test/read_file/transformation.xsl
+++ b/test/read_file/transformation.xsl
@@ -2,14 +2,26 @@
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xalan="http://xml.apache.org/xalan"
xmlns:InputXSLT="function.inputxslt.application"
- exclude-result-prefixes="InputXSLT"
+ exclude-result-prefixes="InputXSLT xalan"
>
<xsl:include href="[testcase.xsl]"/>
<xsl:template name="implementation">
- <xsl:value-of select="InputXSLT:read-file('test.txt')"/>
+ <xsl:variable name="result">
+ <xsl:copy-of select="InputXSLT:read-file('test.txt')"/>
+ </xsl:variable>
+
+ <xsl:choose>
+ <xsl:when test="xalan:nodeset($result)/file/@result = 'success'">
+ <xsl:value-of select="xalan:nodeset($result)/file"/>
+ </xsl:when>
+ <xsl:otherwise>
+ Error during file io
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
</xsl:stylesheet>
diff --git a/test/read_xml_file/transformation.xsl b/test/read_xml_file/transformation.xsl
index 2a6c5e5..f23273e 100644
--- a/test/read_xml_file/transformation.xsl
+++ b/test/read_xml_file/transformation.xsl
@@ -2,16 +2,28 @@
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xalan="http://xml.apache.org/xalan"
xmlns:InputXSLT="function.inputxslt.application"
- exclude-result-prefixes="InputXSLT"
+ exclude-result-prefixes="InputXSLT xalan"
>
<xsl:include href="[testcase.xsl]"/>
<xsl:template name="implementation">
- <xsl:for-each select="InputXSLT:read-xml-file('test.txt')/tester/eintrag">
- <item><xsl:value-of select="."/></item>
- </xsl:for-each>
+ <xsl:variable name="result">
+ <xsl:copy-of select="InputXSLT:read-xml-file('test.txt')"/>
+ </xsl:variable>
+
+ <xsl:choose>
+ <xsl:when test="xalan:nodeset($result)/file/@result = 'success'">
+ <xsl:for-each select="xalan:nodeset($result)/file/tester/eintrag">
+ <item><xsl:value-of select="."/></item>
+ </xsl:for-each>
+ </xsl:when>
+ <xsl:otherwise>
+ Error during file io
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:template>
</xsl:stylesheet>
diff --git a/test/transform/transformation.xsl b/test/transform/transformation.xsl
index 19c42ae..412036b 100644
--- a/test/transform/transformation.xsl
+++ b/test/transform/transformation.xsl
@@ -38,13 +38,13 @@
</xsl:variable>
<xsl:choose>
- <xsl:when test="xalan:nodeset($result)/result/error">
- <xsl:copy-of select="xalan:nodeset($result)/result/error"/>
- </xsl:when>
- <xsl:otherwise>
+ <xsl:when test="xalan:nodeset($result)/transformation/@result = 'success'">
<xsl:copy-of select="
InputXSLT:read-xml-file('test_actual.xml')/test_case/transform_test/*
"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy-of select="xalan:nodeset($result)/transformation/*"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>