summaryrefslogtreecommitdiff
path: root/unoxml/source/dom
diff options
context:
space:
mode:
authorFyodor Yemelyanenko <fyodor_e@hotmail.com>2017-08-21 16:11:14 +1000
committerMichael Stahl <mstahl@redhat.com>2017-08-25 12:44:33 +0200
commitd181d8acbf49e2fe87c8cf53a9431e503ccced55 (patch)
tree5a9049f86deed322dadb912f00113fc26f2a77e7 /unoxml/source/dom
parent3aab0593dd0b64849488f2186221135df9851258 (diff)
tdf#84237 use XErrorHandler in CDocumentBuilder
In documentbuilder.cxx added code to call XErrorHandler::warning and XErrorHandler::error functions (from DOM::warning_func and DOM::error_func) In domtest.cxx added try {} catch () block to BasicTest::validInputTest, BasicTest::warningInputTest and BasicTest::errorInputTest and to SerializerTest::serializerTest. Also uncommented lines CPPUNIT_TEST(warningInputTest); and CPPUNIT_TEST(errorInputTest); Unit tests are now working (FatalError test removed, as lib2xml doesn't distinguish between error and fatal error and counts everything as error). Change-Id: I27c5036df6a1cc5bef5dbb8171c201d81bae2ccd Reviewed-on: https://gerrit.libreoffice.org/41376 Reviewed-by: Michael Stahl <mstahl@redhat.com> Tested-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'unoxml/source/dom')
-rw-r--r--unoxml/source/dom/documentbuilder.cxx68
-rw-r--r--unoxml/source/dom/documentbuilder.hxx11
2 files changed, 70 insertions, 9 deletions
diff --git a/unoxml/source/dom/documentbuilder.cxx b/unoxml/source/dom/documentbuilder.cxx
index 5f3530395bfe..e8eb6097c23d 100644
--- a/unoxml/source/dom/documentbuilder.cxx
+++ b/unoxml/source/dom/documentbuilder.cxx
@@ -269,21 +269,71 @@ namespace DOM
// default warning handler does not trigger assertion
static void warning_func(void * ctx, const char * /*msg*/, ...)
{
- SAL_INFO(
- "unoxml",
- "libxml2 warning: "
- << make_error_message(static_cast<xmlParserCtxtPtr>(ctx)));
+ try
+ {
+ xmlParserCtxtPtr const pctx = static_cast<xmlParserCtxtPtr>(ctx);
+
+ SAL_INFO(
+ "unoxml",
+ "libxml2 warning: "
+ << make_error_message(pctx));
+
+ CDocumentBuilder * const pDocBuilder = static_cast<CDocumentBuilder*>(pctx->_private);
+
+ if (pDocBuilder->getErrorHandler().is()) // if custom error handler is set (using setErrorHandler ())
+ {
+ // Prepare SAXParseException to be passed to custom XErrorHandler::warning function
+ css::xml::sax::SAXParseException saxex;
+ saxex.Message = make_error_message(pctx);
+ saxex.LineNumber = static_cast<sal_Int32>(pctx->lastError.line);
+ saxex.ColumnNumber = static_cast<sal_Int32>(pctx->lastError.int2);
+
+ // Call custom warning function
+ pDocBuilder->getErrorHandler()->warning(::css::uno::Any(saxex));
+ }
+ }
+ catch (const css::uno::RuntimeException &e)
+ {
+ // Protect lib2xml from UNO Exception
+ SAL_WARN("unoxml",
+ "DOM::warning_func: caught RuntimeException"
+ << e.Message);
+ }
}
// default error handler triggers assertion
static void error_func(void * ctx, const char * /*msg*/, ...)
{
- SAL_WARN(
- "unoxml",
- "libxml2 error: "
- << make_error_message(static_cast<xmlParserCtxtPtr>(ctx)));
+ try
+ {
+ xmlParserCtxtPtr const pctx = static_cast<xmlParserCtxtPtr>(ctx);
+ SAL_WARN(
+ "unoxml",
+ "libxml2 error: "
+ << make_error_message(pctx));
+
+ CDocumentBuilder * const pDocBuilder = static_cast<CDocumentBuilder*>(pctx->_private);
+
+ if (pDocBuilder->getErrorHandler().is()) // if custom error handler is set (using setErrorHandler ())
+ {
+ // Prepare SAXParseException to be passed to custom XErrorHandler::error function
+ css::xml::sax::SAXParseException saxex;
+ saxex.Message = make_error_message(pctx);
+ saxex.LineNumber = static_cast<sal_Int32>(pctx->lastError.line);
+ saxex.ColumnNumber = static_cast<sal_Int32>(pctx->lastError.int2);
+
+ // Call custom warning function
+ pDocBuilder->getErrorHandler()->error(::css::uno::Any(saxex));
+ }
+ }
+ catch (const css::uno::RuntimeException &e)
+ {
+ // Protect lib2xml from UNO Exception
+ SAL_WARN("unoxml",
+ "DOM::error_func: caught RuntimeException"
+ << e.Message);
+ }
}
-
} // extern "C"
void throwEx(xmlParserCtxtPtr ctxt)
diff --git a/unoxml/source/dom/documentbuilder.hxx b/unoxml/source/dom/documentbuilder.hxx
index cdda893010d5..9f6253bdff8a 100644
--- a/unoxml/source/dom/documentbuilder.hxx
+++ b/unoxml/source/dom/documentbuilder.hxx
@@ -123,6 +123,17 @@ namespace DOM
the XML document to be parsed.
*/
virtual void SAL_CALL setErrorHandler(const css::uno::Reference< css::xml::sax::XErrorHandler >& eh) override;
+
+ /*
+ Get the ErrorHandler to be used to report errors present in
+ the XML document to be parsed.
+ */
+
+ const css::uno::Reference< css::xml::sax::XErrorHandler >& getErrorHandler()
+ {
+ return m_xErrorHandler;
+ }
+
};
}