aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/function/external_text_formatter.cc (renamed from src/function/execute.cc)56
-rw-r--r--src/function/external_text_formatter.h (renamed from src/function/execute.h)10
-rw-r--r--src/plattform_guard.cc6
4 files changed, 50 insertions, 24 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 442c215..1943a13 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,7 +28,7 @@ set(
src/function/read_xml_file.cc
src/function/read_directory.cc
src/function/transform.cc
- src/function/execute.cc
+ src/function/external_text_formatter.cc
src/support/filesystem_context.cc
src/support/stylesheet_parameter_guard.cc
src/support/xalan_string.cc
diff --git a/src/function/execute.cc b/src/function/external_text_formatter.cc
index f19ba75..d1b9e92 100644
--- a/src/function/execute.cc
+++ b/src/function/external_text_formatter.cc
@@ -1,21 +1,52 @@
-#include "execute.h"
+#include "external_text_formatter.h"
+
+#include <xalanc/XSLT/XSLTInputSource.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMElement.hpp>
+#include <xercesc/parsers/XercesDOMParser.hpp>
#include <boost/process.hpp>
+#include <sstream>
+
#include "support/xerces_string_guard.h"
#include "support/dom/result_node_facade.h"
+namespace {
+
+using InputXSLT::XercesStringGuard;
+
+inline xercesc::DOMNode* importDocumentElement(
+ boost::process::pistream& outputStream,
+ xercesc::DOMDocument* const domDocument
+) {
+ std::stringstream xmlStream(
+ "<output>" + std::string(
+ (std::istreambuf_iterator<char>(outputStream)),
+ (std::istreambuf_iterator<char>())
+ ) + "</output>"
+ );
+
+ xercesc::XercesDOMParser parser;
+ parser.parse(xalan::XSLTInputSource(xmlStream));
+
+ return domDocument->importNode(
+ parser.getDocument()->getDocumentElement(),
+ true
+ );
+}
+
+}
+
namespace InputXSLT {
-xercesc::DOMDocument* FunctionExecute::constructDocument(
+xercesc::DOMDocument* FunctionExternalTextFormatter::constructDocument(
const InputXSLT::FilesystemContext&,
const FunctionBase::parameter_tuple& parameters
) {
- const std::string& executablePath(
+ const std::string& formatterPath(
std::get<0>(parameters)
);
@@ -39,32 +70,27 @@ xercesc::DOMDocument* FunctionExecute::constructDocument(
context.stdout_behavior = boost::process::capture_stream();
context.stdin_behavior = boost::process::capture_stream();
- boost::process::child process(
+ boost::process::child formatterProcess(
boost::process::launch(
- executablePath,
+ formatterPath,
std::vector<std::string>{""},
context
)
);
- boost::process::postream& inputStream = process.get_stdin();
- boost::process::pistream& outputStream = process.get_stdout();
+ boost::process::postream& inputStream = formatterProcess.get_stdin();
+ boost::process::pistream& outputStream = formatterProcess.get_stdout();
inputStream << stdinText;
inputStream.close();
- const std::string resultText(
- (std::istreambuf_iterator<char>(outputStream)),
- (std::istreambuf_iterator<char>())
- );
-
- boost::process::status status = process.wait();
+ boost::process::status status = formatterProcess.wait();
if ( status.exited() ) {
ResultNodeFacade result(domDocument, rootNode, "result");
- result.setValueNode("code", std::to_string(status.exit_status()));
- result.setValueNode("output", resultText);
+ result.setValueNode("code", std::to_string(status.exit_status()));
+ result.setContent(importDocumentElement(outputStream, domDocument));
} else {
ResultNodeFacade result(domDocument, rootNode, "error");
diff --git a/src/function/execute.h b/src/function/external_text_formatter.h
index 12167da..877bac5 100644
--- a/src/function/execute.h
+++ b/src/function/external_text_formatter.h
@@ -1,12 +1,12 @@
-#ifndef INPUTXSLT_SRC_FUNCTION_EXECUTE_H_
-#define INPUTXSLT_SRC_FUNCTION_EXECUTE_H_
+#ifndef INPUTXSLT_SRC_FUNCTION_EXTERNAL_TEXT_FORMATTER_H_
+#define INPUTXSLT_SRC_FUNCTION_EXTERNAL_TEXT_FORMATTER_H_
#include "base.h"
namespace InputXSLT {
-class FunctionExecute : public FunctionBase<
- FunctionExecute,
+class FunctionExternalTextFormatter : public FunctionBase<
+ FunctionExternalTextFormatter,
std::string,
std::string
> {
@@ -25,4 +25,4 @@ class FunctionExecute : public FunctionBase<
}
-#endif // INPUTXSLT_SRC_FUNCTION_EXECUTE_H_
+#endif // INPUTXSLT_SRC_FUNCTION_EXTERNAL_TEXT_FORMATTER_H_
diff --git a/src/plattform_guard.cc b/src/plattform_guard.cc
index ff4de08..d787adf 100644
--- a/src/plattform_guard.cc
+++ b/src/plattform_guard.cc
@@ -10,7 +10,7 @@
#include "function/read_xml_file.h"
#include "function/read_directory.h"
#include "function/transform.h"
-#include "function/execute.h"
+#include "function/external_text_formatter.h"
namespace InputXSLT {
@@ -49,8 +49,8 @@ PlattformGuard::PlattformGuard(const std::vector<std::string>& path):
xalan::XalanTransformer::installExternalFunctionGlobal(
customNamespace,
- xalan::XalanDOMString("execute"),
- InputXSLT::FunctionExecute(&this->include_resolver_)
+ xalan::XalanDOMString("external-text-formatter"),
+ InputXSLT::FunctionExternalTextFormatter(&this->include_resolver_)
);
}