summaryrefslogtreecommitdiff
path: root/chart2/source/inc/dumpxmltostring.hxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-12-10 12:34:50 +0100
committerStephan Bergmann <sbergman@redhat.com>2022-12-14 12:56:52 +0000
commit56e17186ffcda7e93530bef3a06120584bb7d579 (patch)
tree71f3de002cb1e822da6d7fc5d5241dd94f45d8f8 /chart2/source/inc/dumpxmltostring.hxx
parent8bdb85f8c7f31e51328afa51a584c3cfdea1c06f (diff)
[API CHANGE] Merge sfx2::XmlDump into css::qa::XDumper
Both sfx2::XmlDump and css::qa::XDumper were (only) used to dump various data from ChartModel and ChartView instances in debugging (e.g., F12 and Shift-F12 in an SW_DEBUG=1 Writer) and testing scenarios. The problem with XmlDump was that it was used as the target of a dynamic_cast from a UNO type, which is dangerous (see the upcoming commit introducing loplugin:unocast for details). One fix would have been to replace that dynamic_cast with a use of XUnoTunnel, and make ChartModel and ChartView implement that. But those classes already implement XDumper, so it looks more natural to use XDumper for that purpose too. However, the information that was obtained via XDumper was rather different from the information that was obtained via XmlDump. So make an incompatible change to the (unpublished) XDumper, adding a kind parameter distinguishing the original behavior of XDumper (kind == "shapes") from the original behavior of XmlDump (kind == ""). Change-Id: Ia7379bedfc45ab62a298fdc2f030cebaf21c4885 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144145 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'chart2/source/inc/dumpxmltostring.hxx')
-rw-r--r--chart2/source/inc/dumpxmltostring.hxx41
1 files changed, 41 insertions, 0 deletions
diff --git a/chart2/source/inc/dumpxmltostring.hxx b/chart2/source/inc/dumpxmltostring.hxx
new file mode 100644
index 000000000000..d03f1cab9d45
--- /dev/null
+++ b/chart2/source/inc/dumpxmltostring.hxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <sal/config.h>
+
+#include <libxml/tree.h>
+#include <libxml/xmlwriter.h>
+
+#include <new>
+
+namespace chart
+{
+template <typename F> OUString dumpXmlToString(F f)
+{
+ auto const buf = xmlBufferCreate();
+ if (buf == nullptr)
+ {
+ throw std::bad_alloc();
+ }
+ auto const writer = xmlNewTextWriterMemory(buf, 0);
+ if (writer == nullptr)
+ {
+ throw std::bad_alloc();
+ }
+ f(writer);
+ xmlFreeTextWriter(writer);
+ OString s(reinterpret_cast<char const*>(xmlBufferContent(buf)), xmlBufferLength(buf));
+ xmlBufferFree(buf);
+ return OStringToOUString(s, RTL_TEXTENCODING_ISO_8859_1); //TODO
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */