aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-28 21:51:39 +0200
committerAdrian Kummerländer2014-05-28 21:51:39 +0200
commit5859cb6af4a5136a96971c47e41e6195007ef944 (patch)
tree77431a85377b3b3742bcdb6c30526d957f9f61c1
parent802d416040aa31d72defa7a9227cd31b0885bc60 (diff)
downloadInputXSLT-5859cb6af4a5136a96971c47e41e6195007ef944.tar
InputXSLT-5859cb6af4a5136a96971c47e41e6195007ef944.tar.gz
InputXSLT-5859cb6af4a5136a96971c47e41e6195007ef944.tar.bz2
InputXSLT-5859cb6af4a5136a96971c47e41e6195007ef944.tar.lz
InputXSLT-5859cb6af4a5136a96971c47e41e6195007ef944.tar.xz
InputXSLT-5859cb6af4a5136a96971c47e41e6195007ef944.tar.zst
InputXSLT-5859cb6af4a5136a96971c47e41e6195007ef944.zip
Implemented basic ErrorHandler
* InputXSLT::ErrorHandler is derived from xercesc::ErrorHandler and enables contextual printing of transformation errors ** currently this means that the error messages passed to std::cerr contain the full path of the offending transformation * added input trimming to the external transform function ** calls to this function from inside a transformation may contain unnecessary whitespace characters which disrupt further processing
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/function/transform.cc10
-rw-r--r--src/support/error_handler.cc43
-rw-r--r--src/support/error_handler.h26
-rw-r--r--src/transformation_facade.cc4
-rw-r--r--src/transformation_facade.h2
-rw-r--r--test/transform/reference.xml2
-rw-r--r--test/transform/transformation.xsl2
8 files changed, 82 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1943a13..8d83c0a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -33,6 +33,7 @@ set(
src/support/stylesheet_parameter_guard.cc
src/support/xalan_string.cc
src/support/include_entity_resolver.cc
+ src/support/error_handler.cc
src/support/tuple/xobject_value.cc
src/support/dom/document_cache.cc
src/support/dom/document_cache_item.cc
diff --git a/src/function/transform.cc b/src/function/transform.cc
index fd28b34..06e4c19 100644
--- a/src/function/transform.cc
+++ b/src/function/transform.cc
@@ -4,6 +4,8 @@
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMElement.hpp>
+#include <boost/algorithm/string.hpp>
+
#include "transformation_facade.h"
#include "support/xerces_string_guard.h"
#include "support/dom/result_node_facade.h"
@@ -14,13 +16,13 @@ xercesc::DOMDocument* FunctionTransform::constructDocument(
const InputXSLT::FilesystemContext& fsContext,
const FunctionBase::parameter_tuple& parameters
) {
- const std::string transformationPath(
+ const std::string transformationPath(boost::trim_copy(
fsContext.resolve(std::get<0>(parameters)).string()
- );
+ ));
- const std::string targetPath(
+ const std::string targetPath(boost::trim_copy(
fsContext.resolve(std::get<1>(parameters)).string()
- );
+ ));
const xalan::XObjectPtr& parameterObject(
std::get<2>(parameters)
diff --git a/src/support/error_handler.cc b/src/support/error_handler.cc
new file mode 100644
index 0000000..9a898a6
--- /dev/null
+++ b/src/support/error_handler.cc
@@ -0,0 +1,43 @@
+#include "error_handler.h"
+
+#include <xercesc/sax/SAXParseException.hpp>
+
+#include <iostream>
+
+#include "support/xerces_string_guard.h"
+
+namespace InputXSLT {
+
+ErrorHandler::ErrorHandler(const std::string& transformation):
+ transformation_path_(transformation) { }
+
+void ErrorHandler::warning(const xercesc::SAXParseException& e) {
+ std::cerr << "Warning in "
+ << "'"
+ << this->transformation_path_
+ << "': "
+ << *XercesStringGuard<char>(e.getMessage())
+ << std::endl;
+}
+
+void ErrorHandler::error(const xercesc::SAXParseException& e) {
+ std::cerr << "Error in "
+ << "'"
+ << this->transformation_path_
+ << "': "
+ << *XercesStringGuard<char>(e.getMessage())
+ << std::endl;
+}
+
+void ErrorHandler::fatalError(const xercesc::SAXParseException& e) {
+ std::cerr << "Fatal error in "
+ << "'"
+ << this->transformation_path_
+ << "': "
+ << *XercesStringGuard<char>(e.getMessage())
+ << std::endl;
+}
+
+void ErrorHandler::resetErrors() { }
+
+}
diff --git a/src/support/error_handler.h b/src/support/error_handler.h
new file mode 100644
index 0000000..7835292
--- /dev/null
+++ b/src/support/error_handler.h
@@ -0,0 +1,26 @@
+#ifndef INPUTXSLT_SRC_SUPPORT_ERROR_HANDLER_H_
+#define INPUTXSLT_SRC_SUPPORT_ERROR_HANDLER_H_
+
+#include <xercesc/sax/ErrorHandler.hpp>
+
+#include <string>
+
+namespace InputXSLT {
+
+class ErrorHandler : public xercesc::ErrorHandler {
+ public:
+ ErrorHandler(const std::string&);
+
+ virtual void warning(const xercesc::SAXParseException&);
+ virtual void error(const xercesc::SAXParseException&);
+ virtual void fatalError(const xercesc::SAXParseException&);
+ virtual void resetErrors();
+
+ private:
+ const std::string& transformation_path_;
+
+};
+
+}
+
+#endif // INPUTXSLT_SRC_SUPPORT_ERROR_HANDLER_H_
diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc
index 3bf1532..fc7e1de 100644
--- a/src/transformation_facade.cc
+++ b/src/transformation_facade.cc
@@ -15,8 +15,10 @@ TransformationFacade::TransformationFacade(
IncludeEntityResolver* resolver
):
transformation_{},
- transformer_() {
+ transformer_(),
+ error_handler_(transformation) {
this->transformer_.setEntityResolver(resolver);
+ this->transformer_.setErrorHandler(&this->error_handler_);
this->transformer_.compileStylesheet(
xalan::XSLTInputSource(transformation.data()),
diff --git a/src/transformation_facade.h b/src/transformation_facade.h
index 1e09248..ab76cac 100644
--- a/src/transformation_facade.h
+++ b/src/transformation_facade.h
@@ -6,6 +6,7 @@
#include <string>
#include "common.h"
+#include "support/error_handler.h"
#include "support/include_entity_resolver.h"
#include "support/stylesheet_parameter_guard.h"
@@ -29,6 +30,7 @@ class TransformationFacade {
const xalan::XalanCompiledStylesheet* transformation_;
xalan::XalanTransformer transformer_;
+ ErrorHandler error_handler_;
int generate(const std::string&, StylesheetParameterGuard&);
int generate(std::basic_ostream<char>&, StylesheetParameterGuard&);
diff --git a/test/transform/reference.xml b/test/transform/reference.xml
index 5d45081..bef43e4 100644
--- a/test/transform/reference.xml
+++ b/test/transform/reference.xml
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<test_case>
-<transform_test>
<parameter_value>42</parameter_value>
-</transform_test>
</test_case>
diff --git a/test/transform/transformation.xsl b/test/transform/transformation.xsl
index fc41eb3..f2cc787 100644
--- a/test/transform/transformation.xsl
+++ b/test/transform/transformation.xsl
@@ -36,7 +36,7 @@
</xsl:call-template>
<xsl:copy-of select="
- InputXSLT:read-xml-file('test_actual.xml')/test_case/transform_test
+ InputXSLT:read-xml-file('test_actual.xml')/test_case/transform_test/*
"/>
</xsl:template>