aboutsummaryrefslogtreecommitdiff
path: root/src/function
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-06-06 22:00:39 +0200
committerAdrian Kummerländer2014-06-06 22:00:39 +0200
commit272b34c1a4639cd0f909bfb52d30339c93b0c42b (patch)
treed3bed13ddf28e86f8de319222daf535305082431 /src/function
parent78bb3387b15d15d766fb5d17a99612f0480f2bee (diff)
downloadInputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.tar
InputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.tar.gz
InputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.tar.bz2
InputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.tar.lz
InputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.tar.xz
InputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.tar.zst
InputXSLT-272b34c1a4639cd0f909bfb52d30339c93b0c42b.zip
Implemented WarningCapacitor as a counterpart to ErrorCapacitor
* in difference to ErrorCapacitor this class doesn't throw an exception on "discharge" but returns the gathered warnings * adapted FunctionTransform and frontend error handling to include warnings * added static "try_create" method to TransformationFacade ** wraps construction error handling ** custom logic may be embedded using the std::function argument *** this was implemented to prevent unneccessary code duplication for handling both construction and generation errors * adapted FunctionTransform to return warning as "warning" nodes in the result tree ** added functional lambda expression factory method "handleErrors" *** returns a error handling lambda expression for a given ResultNodeFacade * implemented WarningGuard class in frontend executable ** guarantees warnings to be printed to std::cerr independent of any exceptions
Diffstat (limited to 'src/function')
-rw-r--r--src/function/transform.cc46
1 files changed, 34 insertions, 12 deletions
diff --git a/src/function/transform.cc b/src/function/transform.cc
index 86bc91c..844dee9 100644
--- a/src/function/transform.cc
+++ b/src/function/transform.cc
@@ -9,6 +9,23 @@
#include "support/dom/result_node_facade.h"
#include "support/error/error_capacitor.h"
+namespace {
+
+using InputXSLT::ErrorCapacitor;
+
+inline std::function<void(const ErrorCapacitor::error_cache&)> handleErrors(
+ InputXSLT::ResultNodeFacade& result) {
+ return [&result](const ErrorCapacitor::error_cache& errors) {
+ result.setAttribute("result", "error");
+
+ for ( auto&& error : errors ) {
+ result.setValueNode("error", error);
+ }
+ };
+}
+
+}
+
namespace InputXSLT {
xercesc::DOMDocument* FunctionTransform::constructDocument(
@@ -42,21 +59,26 @@ xercesc::DOMDocument* FunctionTransform::constructDocument(
ResultNodeFacade result(domDocument, rootNode, "transformation");
result.setAttribute("target", targetPath);
- try {
- InputXSLT::TransformationFacade transformation(
- transformationPath,
- this->include_resolver_
- );
+ if ( auto transformation = TransformationFacade::try_create(
+ transformationPath,
+ this->include_resolver_,
+ handleErrors(result)
+ ) ) {
+ try {
+ transformation->generate(targetPath, parameterObject);
- transformation.generate(targetPath, parameterObject);
+ result.setAttribute("result", "success");
+ }
+ catch (const ErrorCapacitor::exception& exception) {
+ handleErrors(result)(*exception);
+ }
- result.setAttribute("result", "success");
- }
- catch (const ErrorCapacitor::exception& exception) {
- result.setAttribute("result", "error");
+ WarningCapacitor::warning_cache_ptr warnings(
+ transformation->getCachedWarnings()
+ );
- for ( auto&& error : *(exception.getCachedErrors()) ) {
- result.setValueNode("error", error);
+ for ( auto&& warning : *warnings ) {
+ result.setValueNode("warning", warning);
}
}